From d1cae1b8a3f27aaee1ed00c3bd1cff79553ef9ee Mon Sep 17 00:00:00 2001 From: BacLuc Date: Fri, 14 May 2021 19:35:28 +0200 Subject: [PATCH] Collaborators.vue: make invitation as guest possible Issue: #1415 --- .../config/Rest/campCollaboration.config.php | 1 + .../test/Rest/CampCollaborationTest.php | 11 ++++++++-- common/locales/en.json | 3 ++- .../components/camp/CollaboratorListItem.vue | 1 + frontend/src/views/camp/Collaborators.vue | 1 + .../src/views/camp/__tests__/Admin.spec.js | 21 +++++++++++++++++++ 6 files changed, 35 insertions(+), 3 deletions(-) diff --git a/backend/module/eCampApi/config/Rest/campCollaboration.config.php b/backend/module/eCampApi/config/Rest/campCollaboration.config.php index f17cfc10bd1..eb212600956 100644 --- a/backend/module/eCampApi/config/Rest/campCollaboration.config.php +++ b/backend/module/eCampApi/config/Rest/campCollaboration.config.php @@ -21,6 +21,7 @@ ->addValidatorInArray([ CampCollaboration::ROLE_MEMBER, CampCollaboration::ROLE_MANAGER, + CampCollaboration::ROLE_GUEST, ]) ) ->buildConfig() diff --git a/backend/module/eCampApi/test/Rest/CampCollaborationTest.php b/backend/module/eCampApi/test/Rest/CampCollaborationTest.php index 2ba0cf7e960..c30f2a8b93a 100644 --- a/backend/module/eCampApi/test/Rest/CampCollaborationTest.php +++ b/backend/module/eCampApi/test/Rest/CampCollaborationTest.php @@ -226,10 +226,13 @@ public function testCreateSuccess(): void { $this->assertEquals(CampCollaboration::STATUS_INVITED, $this->getResponseContent()->status); } - public function testCreateOnlyWithEmail(): void { + /** + * @dataProvider getRoles + */ + public function testCreateOnlyWithEmail(string $role): void { $inviteEmail = 'my.mail@fantasy.com'; $this->setRequestContent([ - 'role' => CampCollaboration::ROLE_MEMBER, + 'role' => $role, 'campId' => $this->campCollaboration1->getCamp()->getId(), 'inviteEmail' => $inviteEmail, 'userId' => null, @@ -244,6 +247,10 @@ public function testCreateOnlyWithEmail(): void { $this->assertThat($this->getResponseContent()->_embedded, self::logicalNot(self::classHasAttribute('user'))); } + public static function getRoles(): array { + return [[CampCollaboration::ROLE_GUEST], [CampCollaboration::ROLE_MANAGER], [CampCollaboration::ROLE_MEMBER]]; + } + public function testCreateWithEmailOfExistingUser() { $inviteEmail = 'my.mail@fantasy.com'; $user2 = new User(); diff --git a/common/locales/en.json b/common/locales/en.json index 3f5bd9d57ca..38f18668fff 100644 --- a/common/locales/en.json +++ b/common/locales/en.json @@ -40,7 +40,8 @@ "collaborators": { "invite": "Invite", "manager": "Manager", - "member": "Member" + "member": "Member", + "guest": "Guest" }, "fields": { "addressCity": "City", diff --git a/frontend/src/components/camp/CollaboratorListItem.vue b/frontend/src/components/camp/CollaboratorListItem.vue index 9cee044740f..fec49ddf8cb 100644 --- a/frontend/src/components/camp/CollaboratorListItem.vue +++ b/frontend/src/components/camp/CollaboratorListItem.vue @@ -30,6 +30,7 @@ :items="[ { key: 'member', translation: $tc('entity.camp.collaborators.member') }, { key: 'manager', translation: $tc('entity.camp.collaborators.manager') }, + { key: 'guest', translation: $tc('entity.camp.collaborators.guest') }, ]" item-value="key" item-text="translation" diff --git a/frontend/src/views/camp/Collaborators.vue b/frontend/src/views/camp/Collaborators.vue index 179b6cd5fe7..5787bbefa1f 100644 --- a/frontend/src/views/camp/Collaborators.vue +++ b/frontend/src/views/camp/Collaborators.vue @@ -50,6 +50,7 @@ Displays collaborators of a single camp. :items="[ { key: 'member', translation: $tc('entity.camp.collaborators.member') }, { key: 'manager', translation: $tc('entity.camp.collaborators.manager') }, + { key: 'guest', translation: $tc('entity.camp.collaborators.guest') }, ]" item-value="key" item-text="translation" diff --git a/frontend/src/views/camp/__tests__/Admin.spec.js b/frontend/src/views/camp/__tests__/Admin.spec.js index b190c5cf63b..2de26ae7340 100644 --- a/frontend/src/views/camp/__tests__/Admin.spec.js +++ b/frontend/src/views/camp/__tests__/Admin.spec.js @@ -62,4 +62,25 @@ describe('Admin view', () => { expect(queryByText('components.camp.campDangerzone.title')).not.toBeInTheDocument() expect(queryByText('components.camp.campDangerzone.deleteCamp.title')).not.toBeInTheDocument() }) + + it('doesn\'t show the danger zone when the user has the guest role', async () => { + const { queryByText } = renderWithVuetify(Admin, { + props: { + camp: () => ({ + role: 'guest', + materialLists: () => {}, + _meta: { loading: false } + }) + }, + routes: [], + mocks: { + api: { reload: () => Promise.resolve() }, + $tc: key => key + }, + stubs: ['camp-settings', 'camp-address', 'camp-periods', 'camp-categories', 'camp-material-lists'] + }) + + expect(queryByText('components.camp.campDangerzone.title')).not.toBeInTheDocument() + expect(queryByText('components.camp.campDangerzone.deleteCamp.title')).not.toBeInTheDocument() + }) })