diff options
Diffstat (limited to 'app/controllers/projects/mattermosts_controller.rb')
-rw-r--r-- | app/controllers/projects/mattermosts_controller.rb | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/app/controllers/projects/mattermosts_controller.rb b/app/controllers/projects/mattermosts_controller.rb new file mode 100644 index 00000000000..d87dff2a80e --- /dev/null +++ b/app/controllers/projects/mattermosts_controller.rb @@ -0,0 +1,43 @@ +class Projects::MattermostsController < Projects::ApplicationController + include TriggersHelper + include ActionView::Helpers::AssetUrlHelper + + layout 'project_settings' + + before_action :authorize_admin_project! + before_action :service + before_action :teams, only: [:new] + + def new + end + + def create + result, message = @service.configure(current_user, configure_params) + + if result + flash[:notice] = 'This service is now configured' + redirect_to edit_namespace_project_service_path( + @project.namespace, @project, service) + else + flash[:alert] = message || 'Failed to configure service' + redirect_to new_namespace_project_mattermost_path( + @project.namespace, @project) + end + end + + private + + def configure_params + params.require(:mattermost).permit(:trigger, :team_id).merge( + url: service_trigger_url(@service), + icon_url: asset_url('gitlab_logo.png')) + end + + def teams + @teams ||= @service.list_teams(current_user) + end + + def service + @service ||= @project.find_or_initialize_service('mattermost_slash_commands') + end +end |