Commit ce61bde5 authored by Eric Eastwood's avatar Eric Eastwood

Allow project admins to change Service Desk

Fix https://gitlab.com/gitlab-org/gitlab-ee/issues/2137
parent a9e009a2
...@@ -18,11 +18,6 @@ export default { ...@@ -18,11 +18,6 @@ export default {
required: false, required: false,
default: null, default: null,
}, },
isInstanceAdmin: {
type: Boolean,
required: false,
default: false,
},
}, },
methods: { methods: {
...@@ -40,7 +35,6 @@ export default { ...@@ -40,7 +35,6 @@ export default {
ref="enabled-checkbox" ref="enabled-checkbox"
type="checkbox" type="checkbox"
id="service-desk-enabled-checkbox" id="service-desk-enabled-checkbox"
:disabled="!isInstanceAdmin"
:checked="isEnabled" :checked="isEnabled"
@change="onCheckboxToggle($event)"> @change="onCheckboxToggle($event)">
<span class="descr"> <span class="descr">
...@@ -48,12 +42,6 @@ export default { ...@@ -48,12 +42,6 @@ export default {
</span> </span>
</label> </label>
</div> </div>
<p
ref="only-instance-admin-activate-message"
v-if="!isInstanceAdmin"
class="settings-message">
Only instance admins can activate/deactivate Service Desk
</p>
<template v-if="isEnabled"> <template v-if="isEnabled">
<div <div
class="panel-slim panel-default"> class="panel-slim panel-default">
......
...@@ -12,13 +12,10 @@ class ServiceDeskRoot { ...@@ -12,13 +12,10 @@ class ServiceDeskRoot {
this.wrapperElement.dataset.enabled !== 'false'; this.wrapperElement.dataset.enabled !== 'false';
const incomingEmail = this.wrapperElement.dataset.incomingEmail; const incomingEmail = this.wrapperElement.dataset.incomingEmail;
const endpoint = this.wrapperElement.dataset.endpoint; const endpoint = this.wrapperElement.dataset.endpoint;
const isInstanceAdmin = typeof this.wrapperElement.dataset.isInstanceAdmin !== 'undefined' &&
this.wrapperElement.dataset.isInstanceAdmin !== 'false';
this.store = new ServiceDeskStore({ this.store = new ServiceDeskStore({
isEnabled, isEnabled,
incomingEmail, incomingEmail,
isInstanceAdmin,
}); });
this.service = new ServiceDeskService(endpoint); this.service = new ServiceDeskService(endpoint);
} }
...@@ -51,8 +48,7 @@ class ServiceDeskRoot { ...@@ -51,8 +48,7 @@ class ServiceDeskRoot {
<service-desk-setting <service-desk-setting
:isEnabled="isEnabled" :isEnabled="isEnabled"
:incomingEmail="incomingEmail" :incomingEmail="incomingEmail"
:fetchError="fetchError" :fetchError="fetchError" />
:isInstanceAdmin="isInstanceAdmin" />
`, `,
components: { components: {
'service-desk-setting': ServiceDeskSetting, 'service-desk-setting': ServiceDeskSetting,
......
...@@ -4,7 +4,6 @@ class ServiceDeskStore { ...@@ -4,7 +4,6 @@ class ServiceDeskStore {
isEnabled: false, isEnabled: false,
incomingEmail: '', incomingEmail: '',
fetchError: null, fetchError: null,
isInstanceAdmin: false,
}, initialState); }, initialState);
} }
...@@ -19,10 +18,6 @@ class ServiceDeskStore { ...@@ -19,10 +18,6 @@ class ServiceDeskStore {
setFetchError(value) { setFetchError(value) {
this.state.fetchError = value; this.state.fetchError = value;
} }
setIsInstanceAdmin(value) {
this.state.isInstanceAdmin = value;
}
} }
export default ServiceDeskStore; export default ServiceDeskStore;
...@@ -134,8 +134,7 @@ ...@@ -134,8 +134,7 @@
= link_to icon('question-circle'), help_page_path('user/project/service_desk') = link_to icon('question-circle'), help_page_path('user/project/service_desk')
.js-service-desk-setting-root{ data: { endpoint: namespace_project_service_desk_path(@project.namespace, @project), .js-service-desk-setting-root{ data: { endpoint: namespace_project_service_desk_path(@project.namespace, @project),
enabled: @project.service_desk_enabled, enabled: @project.service_desk_enabled,
incoming_email: (@project.service_desk_address if @project.service_desk_enabled), incoming_email: (@project.service_desk_address if @project.service_desk_enabled) } }
is_instance_admin: current_user.admin? } }
%hr %hr
%fieldset.features.append-bottom-default %fieldset.features.append-bottom-default
......
...@@ -3,63 +3,25 @@ require 'spec_helper' ...@@ -3,63 +3,25 @@ require 'spec_helper'
describe 'Service Desk Setting', js: true, feature: true do describe 'Service Desk Setting', js: true, feature: true do
include WaitForAjax include WaitForAjax
describe 'as project master/admin' do let(:project) { create(:project_empty_repo, :private) }
let(:project) { create(:project_empty_repo, :private) } let(:user) { create(:user) }
let(:user) { create(:user) }
before do before do
project.add_master(user) project.add_master(user)
login_as(user) login_as(user)
allow_any_instance_of(License).to receive(:add_on?).and_call_original allow_any_instance_of(License).to receive(:add_on?).and_call_original
allow_any_instance_of(License).to receive(:add_on?).with('GitLab_ServiceDesk') { true } allow_any_instance_of(License).to receive(:add_on?).with('GitLab_ServiceDesk') { true }
end
describe 'when disabled' do visit edit_namespace_project_path(project.namespace, project)
before do
visit edit_namespace_project_path(project.namespace, project)
end
it 'shows disabled activation checkbox' do
expect(page).to have_selector("#service-desk-enabled-checkbox[disabled]")
end
end
describe 'when enabled' do
before do
project.update(service_desk_enabled: true)
visit edit_namespace_project_path(project.namespace, project)
end
it 'shows disabled activation checkbox' do
expect(page).to have_selector("#service-desk-enabled-checkbox[disabled]")
end
it 'shows service_desk_address when enabled' do
expect(find('.js-service-desk-setting-wrapper .panel-body')).to have_content(project.service_desk_address)
end
end
end end
describe 'as instance admin' do it 'shows activation checkbox' do
let(:project) { create(:project_empty_repo, :private) } expect(page).to have_selector("#service-desk-enabled-checkbox")
let(:user) { create(:user, :admin) } end
before do
login_as(user)
allow_any_instance_of(License).to receive(:add_on?).and_call_original
allow_any_instance_of(License).to receive(:add_on?).with('GitLab_ServiceDesk') { true }
visit edit_namespace_project_path(project.namespace, project)
end
it 'shows activation checkbox' do
expect(page).to have_selector("#service-desk-enabled-checkbox")
end
it 'shows incoming email after activating' do it 'shows incoming email after activating' do
find("#service-desk-enabled-checkbox").click find("#service-desk-enabled-checkbox").click
wait_for_ajax wait_for_ajax
expect(find('.js-service-desk-setting-wrapper .panel-body')).to have_content(project.service_desk_address) expect(find('.js-service-desk-setting-wrapper .panel-body')).to have_content(project.service_desk_address)
end
end end
end end
...@@ -31,12 +31,8 @@ describe('ServiceDeskSetting', () => { ...@@ -31,12 +31,8 @@ describe('ServiceDeskSetting', () => {
el = vm.$el; el = vm.$el;
}); });
it('should see disabled activation checkbox', () => { it('should see activation checkbox (not disabled)', () => {
expect(vm.$refs['enabled-checkbox'].getAttribute('disabled')).toEqual('disabled'); expect(vm.$refs['enabled-checkbox'].getAttribute('disabled')).toEqual(null);
});
it('should see only instance admin can activate/deactivate message', () => {
expect(vm.$refs['only-instance-admin-activate-message']).toBeDefined();
}); });
it('should see main panel with the email info', () => { it('should see main panel with the email info', () => {
...@@ -53,20 +49,6 @@ describe('ServiceDeskSetting', () => { ...@@ -53,20 +49,6 @@ describe('ServiceDeskSetting', () => {
expect(vm.$refs['recommend-protect-email-from-spam-message']).toBeDefined(); expect(vm.$refs['recommend-protect-email-from-spam-message']).toBeDefined();
}); });
}); });
describe('as instance admin', () => {
beforeEach(() => {
vm = createComponent({
isEnabled: true,
isInstanceAdmin: true,
});
el = vm.$el;
});
it('should see activation checkbox (not disabled)', () => {
expect(vm.$refs['enabled-checkbox'].getAttribute('disabled')).toEqual(null);
});
});
}); });
describe('with incomingEmail', () => { describe('with incomingEmail', () => {
......
...@@ -50,22 +50,4 @@ describe('ServiceDeskStore', () => { ...@@ -50,22 +50,4 @@ describe('ServiceDeskStore', () => {
expect(store.state.fetchError).toEqual(err); expect(store.state.fetchError).toEqual(err);
}); });
}); });
describe('setIsInstanceAdmin', () => {
it('defaults to false', () => {
expect(store.state.isInstanceAdmin).toEqual(false);
});
it('set true', () => {
store.setIsInstanceAdmin(true);
expect(store.state.isInstanceAdmin).toEqual(true);
});
it('set false', () => {
store.setIsInstanceAdmin(false);
expect(store.state.isInstanceAdmin).toEqual(false);
});
});
}); });
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