From 65c1e549f2f688fc05dedbb5dc438c1a3ac45b40 Mon Sep 17 00:00:00 2001 From: wandji20 Date: Thu, 29 Feb 2024 14:29:04 +0100 Subject: [PATCH 1/2] Set predefined Viewer role when creating new project [SCI-10326] --- app/javascript/vue/projects/modals/new.vue | 31 ++++++++++++++++--- .../lists/project_and_folder_serializer.rb | 4 ++- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/app/javascript/vue/projects/modals/new.vue b/app/javascript/vue/projects/modals/new.vue index bbf674fbb..5eefccedd 100644 --- a/app/javascript/vue/projects/modals/new.vue +++ b/app/javascript/vue/projects/modals/new.vue @@ -31,12 +31,12 @@
- +
@@ -63,19 +63,32 @@ export default { components: { SelectDropdown, }, + watch: { + visible(newValue) { + if (newValue) { + [this.defaultRole] = this.userRoles.find((role) => role[1] === 'Viewer'); + } else { + this.defaultRole = null; + } + } + }, + mounted() { + this.fetchUserRoles(); + }, data() { return { name: '', visible: false, defaultRole: null, error: null, - disableSubmit: false + disableSubmit: false, + userRoles: [] }; }, methods: { - submit() { + async submit() { this.disableSubmit = true; - axios.post(this.createUrl, { + await axios.post(this.createUrl, { project: { name: this.name, visibility: (this.visible ? 'visible' : 'hidden'), @@ -93,6 +106,14 @@ export default { changeRole(role) { this.defaultRole = role; }, + fetchUserRoles() { + if (this.userRolesUrl) { + axios.get(this.userRolesUrl) + .then((response) => { + this.userRoles = response.data.data; + }); + } + } }, }; diff --git a/app/serializers/lists/project_and_folder_serializer.rb b/app/serializers/lists/project_and_folder_serializer.rb index f0e7e2b08..1ee7c3df0 100644 --- a/app/serializers/lists/project_and_folder_serializer.rb +++ b/app/serializers/lists/project_and_folder_serializer.rb @@ -64,6 +64,8 @@ module Lists count: object.comments.count, count_unseen: count_unseen_comments(object, @user) } + else + {} end end @@ -96,7 +98,7 @@ module Lists def permissions { - create_comments: can_create_project_comments?(object) + create_comments: comment_addable?(object) } end From b497c7e9a7506d93ef205331a191be96d99c94e2 Mon Sep 17 00:00:00 2001 From: wandji20 Date: Fri, 1 Mar 2024 11:45:15 +0100 Subject: [PATCH 2/2] Add preselected role for new protocol template [SCI-10326] --- app/javascript/vue/projects/modals/edit.vue | 25 +++++++++++++++++-- app/javascript/vue/projects/modals/new.vue | 2 +- app/javascript/vue/protocols/modals/new.vue | 25 +++++++++++++++++-- .../lists/project_and_folder_serializer.rb | 4 +-- 4 files changed, 48 insertions(+), 8 deletions(-) diff --git a/app/javascript/vue/projects/modals/edit.vue b/app/javascript/vue/projects/modals/edit.vue index 2a4fc9c1c..04f3ac812 100644 --- a/app/javascript/vue/projects/modals/edit.vue +++ b/app/javascript/vue/projects/modals/edit.vue @@ -29,12 +29,12 @@
- +
@@ -60,12 +60,25 @@ export default { components: { SelectDropdown, }, + watch: { + visible(newValue) { + if (newValue) { + [this.defaultRole] = this.userRoles.find((role) => role[1] === 'Viewer'); + } else { + this.defaultRole = null; + } + } + }, + mounted() { + this.fetchUserRoles(); + }, data() { return { name: this.project.name, visible: !this.project.hidden, defaultRole: this.project.default_public_user_role_id, error: null, + userRoles: [] }; }, methods: { @@ -86,6 +99,14 @@ export default { changeRole(role) { this.defaultRole = role; }, + fetchUserRoles() { + if (this.userRolesUrl) { + axios.get(this.userRolesUrl) + .then((response) => { + this.userRoles = response.data.data; + }); + } + } }, }; diff --git a/app/javascript/vue/projects/modals/new.vue b/app/javascript/vue/projects/modals/new.vue index 5eefccedd..9d48fa18d 100644 --- a/app/javascript/vue/projects/modals/new.vue +++ b/app/javascript/vue/projects/modals/new.vue @@ -36,7 +36,7 @@ diff --git a/app/javascript/vue/protocols/modals/new.vue b/app/javascript/vue/protocols/modals/new.vue index 467b34750..5ca00669a 100644 --- a/app/javascript/vue/protocols/modals/new.vue +++ b/app/javascript/vue/protocols/modals/new.vue @@ -30,12 +30,12 @@
- +
@@ -61,11 +61,24 @@ export default { components: { SelectDropdown }, + watch: { + visible(newValue) { + if (newValue) { + [this.defaultRole] = this.userRoles.find((role) => role[1] === 'Viewer'); + } else { + this.defaultRole = null; + } + } + }, + mounted() { + this.fetchUserRoles(); + }, data() { return { name: '', visible: false, defaultRole: null, + userRoles: [], error: null }; }, @@ -86,6 +99,14 @@ export default { }, changeRole(role) { this.defaultRole = role; + }, + fetchUserRoles() { + if (this.userRolesUrl) { + axios.get(this.userRolesUrl) + .then((response) => { + this.userRoles = response.data.data; + }); + } } } }; diff --git a/app/serializers/lists/project_and_folder_serializer.rb b/app/serializers/lists/project_and_folder_serializer.rb index 1ee7c3df0..f0e7e2b08 100644 --- a/app/serializers/lists/project_and_folder_serializer.rb +++ b/app/serializers/lists/project_and_folder_serializer.rb @@ -64,8 +64,6 @@ module Lists count: object.comments.count, count_unseen: count_unseen_comments(object, @user) } - else - {} end end @@ -98,7 +96,7 @@ module Lists def permissions { - create_comments: comment_addable?(object) + create_comments: can_create_project_comments?(object) } end