From d8c35195c723ae0fefefc292fc9a26ca389db7a2 Mon Sep 17 00:00:00 2001 From: Peter Le Date: Tue, 12 Nov 2024 12:21:19 -0500 Subject: [PATCH 1/3] RDISCROWD-7660-2 show authorized servcies to non-admins --- static/src/components/setting/index.vue | 15 +++++++++++++-- templates/projects/external_config.html | 5 +++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/static/src/components/setting/index.vue b/static/src/components/setting/index.vue index 39405ad8c..b774a161f 100644 --- a/static/src/components/setting/index.vue +++ b/static/src/components/setting/index.vue @@ -5,6 +5,14 @@ class="col-md-12" :style="waiting && 'opacity: 0.5'" > +
+
+

Authorized Services

+
+
+ {{ authorizedServices.join(", ") }} +
+
0) { this.dataAccessConfigured = true; } diff --git a/templates/projects/external_config.html b/templates/projects/external_config.html index 24a3b9517..bda413d8c 100644 --- a/templates/projects/external_config.html +++ b/templates/projects/external_config.html @@ -23,6 +23,11 @@

{{_('No external services have been configured')}}

For more information on these settings, please consult the External Configurations documentation.

{% endif %} +{% if not is_admin %} +

Authorized Services

+ {{ authorized_services|join(', ') }} +{% endif %} + {% for (form_name, display, form) in forms %}

{{display}}

{{render_form(form, form_id=form_name, action_url=url_for('project.ext_config', short_name=project.short_name), action_text='Submit', class_='', btn_name=form_name, btn_class='btn btn-default', btn_value=None)}} From 917f8183adf752e1569f359647316b5a52f1ed9b Mon Sep 17 00:00:00 2001 From: Peter Le Date: Thu, 14 Nov 2024 15:00:28 -0500 Subject: [PATCH 2/3] fix tests --- static/src/components/setting/index.vue | 2 +- .../src/test/components/setting/index.spec.js | 93 ++++++++++++------- 2 files changed, 58 insertions(+), 37 deletions(-) diff --git a/static/src/components/setting/index.vue b/static/src/components/setting/index.vue index b774a161f..77f485475 100644 --- a/static/src/components/setting/index.vue +++ b/static/src/components/setting/index.vue @@ -121,7 +121,7 @@ :value="u.id" @click="remove($event, u.id)" > -

{{ u.fullname }}

+

{{ u.fullname }}

diff --git a/static/src/test/components/setting/index.spec.js b/static/src/test/components/setting/index.spec.js index ac287344b..a80244898 100644 --- a/static/src/test/components/setting/index.spec.js +++ b/static/src/test/components/setting/index.spec.js @@ -1,4 +1,4 @@ -import { mount, shallowMount, createLocalVue } from '@vue/test-utils'; +import { createLocalVue, mount, shallowMount } from '@vue/test-utils'; import projectConfig from '../../../components/setting/index.vue'; const localVue = createLocalVue(); @@ -14,7 +14,7 @@ describe('projectConfig', () => { }); let VALID_ACCESS_LEVELS = [ [ 'L1', 'L1' ], [ 'L2', 'L2' ], [ 'L3', 'L3' ], [ 'L4', 'L4' ] ]; - let EXT_CONF = { target_bucket: 'bucket' }; + let EXT_CONF = { target_bucket: 'bucket', authorized_services: [] }; it('fetch external config and access data', async () => { let response = { @@ -66,51 +66,72 @@ describe('projectConfig', () => { expect(wrapper.vm._data.assignee).toEqual(['1']); }); -it('load empty data', () => { - propsData = { - csrfTRoken: null, - externalConfig: {}, - externalConfigForm: [] - }; - const wrapper = shallowMount(projectConfig, { propsData }); - expect(wrapper.vm._data.dataAccessConfigured).toEqual(false); - expect(wrapper.vm._data.users).toEqual({}); -}); + it('load empty data', () => { + propsData = { + csrfTRoken: null, + externalConfig: {}, + externalConfigForm: [] + }; + const wrapper = shallowMount(projectConfig, { propsData }); + expect(wrapper.vm._data.dataAccessConfigured).toEqual(false); + expect(wrapper.vm._data.users).toEqual({}); + }); it('show external config', () => { - const wrapper = shallowMount(projectConfig, { propsData }); - wrapper.vm._data.externalConfigDict = { target_bucket: 'bucket', cluster: 'c1' }; - wrapper.vm._data.inputFields = { - gigwork_poller: { display: 'test1', fields: [{ type: 'TextField', name: 'target_bucket' }] }, - hdfs: { display: 'test2', fields: [{ type: 'SelectField', name: 'cluster', choices: [('c1', 'option1')] }] } - }; - expect(wrapper.findAll('p')).toHaveLength(4); + const wrapper = shallowMount(projectConfig, + { + data() { + return { + externalConfigDict: { target_bucket: 'bucket', cluster: 'c1' }, + inputFields: { + gigwork_poller: { display: 'test1', fields: [{ type: 'TextField', name: 'target_bucket' }] }, + hdfs: { display: 'test2', fields: [{ type: 'SelectField', name: 'cluster', choices: [('c1', 'option1')] }] } + }, + isAdmin: false + } + } + } + ); + expect(wrapper.findAll('p')).toHaveLength(5); expect(wrapper.findAll('input')).toHaveLength(2); expect(wrapper.findAll('select')).toHaveLength(2); }); it('add assigned user', () => { - const wrapper = shallowMount(projectConfig); - wrapper.vm._data.assignee = ['1']; - wrapper.vm._data.users = { 1: { id: 1, fullname: 'user1' }, 2: { id: 2, fullname: 'user2' } }; - wrapper.vm._data.searchResult = [{ id: 1, fullname: 'user1' }, { id: 2, fullname: 'user2' }]; - - expect(wrapper.findAll('p')).toHaveLength(2); - const user2 = wrapper.findAll('p').at(1); + const wrapper = shallowMount(projectConfig, + { + data() { + return { + assignee: ['1'], + users: [{ 1: { id: 1, fullname: 'sally fields', last_name: 'fields' }}, {2: { id: 2, fullname: 'tom hanks', last_name: 'hanks' } }], + searchResult: [{ id: 1, fullname: 'sally fields', last_name: 'fields' }, { id: 2, fullname: 'tom hanks', last_name: 'hanks' }] + } + } + } + ); + expect(wrapper.findAll('#assign-user-column p')).toHaveLength(2); + const user2 = wrapper.findAll('#assign-user-column p').at(1); user2.trigger('click'); - expect(wrapper.findAll('p')).toHaveLength(2); + expect(wrapper.findAll('#assign-user-column p')).toHaveLength(2); }); - it('remove assigned user', () => { - const wrapper = shallowMount(projectConfig); - wrapper.vm._data.assignee = ['1']; - wrapper.vm._data.users = { 1: { id: 1, fullname: 'user' } }; - wrapper.vm._data.searchResult = [{ id: 1, fullname: 'user' }]; - - expect(wrapper.findAll('p')).toHaveLength(5); - const user1 = wrapper.findAll('p').at(2); + it('remove assigned user', async () => { + const wrapper = shallowMount(projectConfig, + { + data() { + return { + assignee: ['1'], + users: { 1: { id: 1, fullname: 'user 1', last_name: '1' } }, + searchResult: [{ id: 1, fullname: 'user 1', last_name: '1' }], + isAdmin: false + } + } + }); + expect(wrapper.findAll('p.assigned-user')).toHaveLength(1); + const user1 = wrapper.findAll('#users').at(1); user1.trigger('click'); - expect(wrapper.findAll('p')).toHaveLength(5); + await localVue.nextTick(); + expect(wrapper.findAll('p.assigned-user')).toHaveLength(1); }); it('saves config', async () => { From 2beb06e54ebdddd002147e4cc9284491438b7465 Mon Sep 17 00:00:00 2001 From: Peter Le Date: Thu, 14 Nov 2024 15:28:27 -0500 Subject: [PATCH 3/3] lint --- static/src/components/setting/index.vue | 11 ++++++++--- static/src/test/components/setting/index.spec.js | 14 +++++++------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/static/src/components/setting/index.vue b/static/src/components/setting/index.vue index 77f485475..1b95401a1 100644 --- a/static/src/components/setting/index.vue +++ b/static/src/components/setting/index.vue @@ -5,7 +5,10 @@ class="col-md-12" :style="waiting && 'opacity: 0.5'" > -
+

Authorized Services

@@ -121,7 +124,9 @@ :value="u.id" @click="remove($event, u.id)" > -

{{ u.fullname }}

+

+ {{ u.fullname }} +

@@ -202,7 +207,7 @@ export default { completed_tasks_cleanup_days: null, allow_taskrun_edit: false, authorizedServices: [], - isAdmin: false, + isAdmin: false }; }, created () { diff --git a/static/src/test/components/setting/index.spec.js b/static/src/test/components/setting/index.spec.js index a80244898..80e88de62 100644 --- a/static/src/test/components/setting/index.spec.js +++ b/static/src/test/components/setting/index.spec.js @@ -80,7 +80,7 @@ describe('projectConfig', () => { it('show external config', () => { const wrapper = shallowMount(projectConfig, { - data() { + data () { return { externalConfigDict: { target_bucket: 'bucket', cluster: 'c1' }, inputFields: { @@ -88,7 +88,7 @@ describe('projectConfig', () => { hdfs: { display: 'test2', fields: [{ type: 'SelectField', name: 'cluster', choices: [('c1', 'option1')] }] } }, isAdmin: false - } + }; } } ); @@ -100,12 +100,12 @@ describe('projectConfig', () => { it('add assigned user', () => { const wrapper = shallowMount(projectConfig, { - data() { + data () { return { assignee: ['1'], - users: [{ 1: { id: 1, fullname: 'sally fields', last_name: 'fields' }}, {2: { id: 2, fullname: 'tom hanks', last_name: 'hanks' } }], + users: [{ 1: { id: 1, fullname: 'sally fields', last_name: 'fields' } }, { 2: { id: 2, fullname: 'tom hanks', last_name: 'hanks' } }], searchResult: [{ id: 1, fullname: 'sally fields', last_name: 'fields' }, { id: 2, fullname: 'tom hanks', last_name: 'hanks' }] - } + }; } } ); @@ -118,13 +118,13 @@ describe('projectConfig', () => { it('remove assigned user', async () => { const wrapper = shallowMount(projectConfig, { - data() { + data () { return { assignee: ['1'], users: { 1: { id: 1, fullname: 'user 1', last_name: '1' } }, searchResult: [{ id: 1, fullname: 'user 1', last_name: '1' }], isAdmin: false - } + }; } }); expect(wrapper.findAll('p.assigned-user')).toHaveLength(1);