Commit b11b97a8 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'slack_app1' into 'master'

Project alias for Slack application can be edited

See merge request !2374
parents 63f9259d 4069fcb2
......@@ -3,6 +3,10 @@ module Projects
class SlacksController < Projects::ApplicationController
before_action :handle_oauth_error, only: :slack_auth
before_action :authorize_admin_project!
before_action :slack_integration, only: [:edit, :update]
before_action :service, only: [:destroy, :edit, :update]
layout 'project_settings'
def slack_auth
result = Projects::SlackApplicationInstallService.new(project, current_user, params).execute
......@@ -15,10 +19,22 @@ module Projects
end
def destroy
service = project.gitlab_slack_application_service
service.slack_integration.destroy
slack_integration.destroy
redirect_to_service_page
end
def edit
end
def update
if slack_integration.update(slack_integration_params)
flash[:notice] = 'The project alias was updated successfully'
redirect_to_service_page
else
render :edit
end
end
private
......@@ -36,6 +52,18 @@ module Projects
redirect_to_service_page
end
end
def slack_integration
@slack_integration ||= project.gitlab_slack_application_service.slack_integration
end
def service
@service = project.gitlab_slack_application_service
end
def slack_integration_params
params.require(:slack_integration).permit(:alias)
end
end
end
end
......@@ -4,7 +4,8 @@ class SlackIntegration < ActiveRecord::Base
validates :team_id, presence: true
validates :team_name, presence: true
validates :alias, presence: true,
uniqueness: { scope: :team_id, message: 'This alias has already been taken' }
uniqueness: { scope: :team_id, message: 'This alias has already been taken' },
length: 2..80
validates :user_id, presence: true
validates :service, presence: true
......
......@@ -5,8 +5,8 @@
%colgroup
%col
%col
%col.hidden-xs
%col{ width: "120" }
%col
%col
%thead
%tr
%th Team name
......@@ -18,9 +18,11 @@
= slack_integration.team_name
%td
= slack_integration.alias
%td.light
%td
= time_ago_in_words slack_integration.created_at
ago
%td.light
%td
.controls
- project = @service.project
= link_to 'Remove', namespace_project_settings_slack_path(project.namespace, project), method: :delete, class: 'btn btn-danger', data: { confirm: 'Are you sure?' }
= link_to 'Edit', edit_project_settings_slack_path(project), class: 'btn btn-sm'
= link_to 'Remove', project_settings_slack_path(project), method: :delete, class: 'btn btn-danger btn-sm', data: { confirm: 'Are you sure?' }
- page_title 'Edit Slack integration'
= render "projects/settings/head"
.row.prepend-top-default.append-bottom-default
.col-lg-3
%h4.prepend-top-0
Edit project alias
%p You can use this alias in your Slack commands
.col-lg-9
= form_errors(@slack_integration)
= form_for(@slack_integration, url: project_settings_slack_path(@project), method: :put, html: { class: 'gl-show-field-errors form-horizontal js-integration-settings-form'}) do |form|
.form-group
= form.label :alias, 'Enter your alias', class: 'control-label'
.col-sm-10
= form.text_field :alias, class: 'form-control', placeholder: @slack_integration.alias, required: true
.footer-block.row-content-block
%button.btn.btn-save{ type: 'submit' }
= icon('spinner spin', class: 'hidden js-btn-spinner')
%span.js-btn-label
Save changes
&nbsp;
= link_to 'Cancel', edit_project_service_path(@project, @service), class: 'btn btn-cancel'
......@@ -438,7 +438,7 @@ constraints(ProjectUrlConstrainer.new) do
resource :ci_cd, only: [:show], controller: 'ci_cd'
resource :integrations, only: [:show]
resource :slack, only: [:destroy] do
resource :slack, only: [:destroy, :edit, :update] do
get :slack_auth
end
......
require 'spec_helper'
feature 'Slack application', feature: true do
let(:project) { create(:empty_project) }
let(:user) { create(:user) }
let(:role) { :developer }
let(:service) { create(:gitlab_slack_application_service, project: project) }
let(:slack_application_form_path) { edit_project_service_path(project, service) }
background do
gitlab_sign_in(user)
project.team << [user, :master]
create(:slack_integration, service: service)
allow(Service).to receive(:show_gitlab_slack_application?).and_return(true)
end
scenario 'I can edit slack integration' do
visit slack_application_form_path
within '.js-integration-settings-form' do
click_link 'Edit'
end
fill_in 'slack_integration_alias', with: 'alias-edited'
click_button 'Save changes'
expect(page).to have_content('The project alias was updated successfully')
within '.js-integration-settings-form' do
expect(page).to have_content('alias-edited')
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment