Skip to content

Commit

Permalink
Merge pull request #738 from TheRestartProject/RES-1987_network_coord…
Browse files Browse the repository at this point in the history
…inators_demote_hosts

RES-1987 Allow network coordinators to remove host role on a group
  • Loading branch information
edwh authored Aug 21, 2024
2 parents fcaa6d6 + c5d6f2a commit 9b0a138
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 1 deletion.
1 change: 1 addition & 0 deletions lang/en/groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
'events' => 'event|events',
'no_volunteers' => 'There are no volunteers in this group',
'remove_volunteer' => 'Remove Volunteer',
'remove_host_role' => 'Remove Host role',
'make_host' => 'Make Host',
'not_counting' => 'Not counting toward this group\'s environmental impact is|Not counting toward this group\'s environmental impact are',
'calendar_copy_title' => 'Access all group events in your personal calendar',
Expand Down
1 change: 1 addition & 0 deletions lang/fr-BE/groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
'events' => 'évenement|évenements',
'group_facts' => 'Réalisations du Repair Café',
'make_host' => 'Nommer organisateur',
'remove_host_role' => 'Retirer rôle d\'organisateur',
'not_counting' => 'L\'impact environnemental de ce Repair Café n\'est pas pris en compte',
'no_volunteers' => 'Il n\'y a pas de bénévoles dans ce repair café',
'read_less' => '<img class="icon" src="/images/minus-icon.svg" style="width: 20px;" /> LIRE MOINS',
Expand Down
1 change: 1 addition & 0 deletions lang/fr/groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
'events' => 'évenement|évenements',
'group_facts' => 'Réalisations du Repair Café',
'make_host' => 'Nommer organisateur',
'remove_host_role' => 'Retirer rôle d\'organisateur',
'not_counting' => 'L\'impact environnemental de ce Repair Café n\'est pas pris en compte',
'no_volunteers' => 'Il n\'y a pas de bénévoles dans ce repair café',
'read_less' => '<img class="icon" src="/images/minus-icon.svg" style="width: 20px;" /> LIRE MOINS',
Expand Down
6 changes: 6 additions & 0 deletions resources/js/components/GroupPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ export default {
required: false,
default: false
},
candemote: {
type: Boolean,
required: false,
default: false
},
canSeeDelete: {
type: Boolean,
required: false,
Expand Down Expand Up @@ -164,6 +169,7 @@ export default {
// computed properties once we have good access to the session on the client.
this.initialGroup.idgroups = this.idgroups
this.initialGroup.canedit = this.canedit
this.initialGroup.candemote = this.candemote
this.initialGroup.ingroup = this.ingroup
this.$store.dispatch('groups/set', this.initialGroup)
Expand Down
13 changes: 13 additions & 0 deletions resources/js/components/GroupVolunteer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
</div>
</div>
<b-dropdown v-if="canedit" variant="none" ref="dropdown" class="edit-dropdown" no-caret>
<b-dropdown-item v-if="volunteer.host && candemote" @click="removeHostRole">{{ __('groups.remove_host_role') }}</b-dropdown-item>
<b-dropdown-item v-if="!volunteer.host" @click="makeVolunteerHost">{{ __('groups.make_host') }}</b-dropdown-item>
<b-dropdown-item @click="removeVolunteer">{{ __('groups.remove_volunteer') }}</b-dropdown-item>
</b-dropdown>
Expand Down Expand Up @@ -67,6 +68,11 @@ export default {
required: false,
default: false
},
candemote: {
type: Boolean,
required: false,
default: false
},
},
data () {
return {
Expand Down Expand Up @@ -140,6 +146,13 @@ export default {
this.error = e.message
}
},
async removeHostRole() {
try {
await this.$store.dispatch('volunteers/removehost', this.volunteer.id)
} catch (e) {
this.error = e.message
}
},
confirm() {
this.$refs.confirm.show()
}
Expand Down
2 changes: 1 addition & 1 deletion resources/js/components/GroupVolunteers.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<div class="mt-2">
<div v-if="volunteers.length">
<div class="maxheight" :key="'confirm-' + volunteers.length">
<GroupVolunteer v-for="a in volunteers" :key="'group-' + a.id" :id="a.id" :canedit="canedit" />
<GroupVolunteer v-for="a in volunteers" :key="'group-' + a.id" :id="a.id" :canedit="canedit" :candemote="candemote" />
</div>
<div class="d-flex justify-content-between">
<a class="justify-content-end" href="#" data-toggle="modal" data-target="#invite-to-group">
Expand Down
3 changes: 3 additions & 0 deletions resources/js/mixins/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ export default {
canedit() {
return this.group ? this.group.canedit : false
},
candemote() {
return this.group ? this.group.candemote : false
},
ingroup() {
return this.group ? this.group.ingroup : false
}
Expand Down
10 changes: 10 additions & 0 deletions resources/js/store/volunteers.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ export default {
},
makeHost(state, id) {
state.listGroup[id].host = true
},
removeHost(state, id) {
state.listGroup[id].host = false
}
},
actions: {
Expand All @@ -58,6 +61,13 @@ export default {
host: true
})
commit('makeHost', id)
},
async removehost({commit, dispatch}, id) {
const vol = this.state.volunteers.listGroup[id]
const ret = await axios.patch('/api/v2/groups/' + vol.group + '/volunteers/' + vol.user, {
host: false
})
commit('removeHost', id)
}
},
}
2 changes: 2 additions & 0 deletions resources/views/group/view.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
}
$can_edit_group = App\Helpers\Fixometer::hasRole($user, 'Administrator') || $isCoordinatorForGroup || $is_host_of_group;
$can_demote = App\Helpers\Fixometer::hasRole($user, 'Administrator') || $isCoordinatorForGroup;
$can_see_delete = App\Helpers\Fixometer::hasRole($user, 'Administrator');
$can_perform_delete = $can_see_delete && $group->canDelete();
Expand Down Expand Up @@ -148,6 +149,7 @@
:top-devices="{{ json_encode($top, JSON_INVALID_UTF8_IGNORE) }}"
:events="{{ json_encode($expanded_events, JSON_INVALID_UTF8_IGNORE) }}"
:canedit="{{ $can_edit_group ? 'true' : 'false' }}"
:candemote="{{ $can_demote ? 'true' : 'false' }}"
:can-see-delete="{{ $can_see_delete ? 'true' : 'false' }}"
:can-perform-delete="{{ $can_perform_delete ? 'true' : 'false' }}"
calendar-copy-url="{{ $showCalendar ? url("/calendar/group/{$group->idgroups}") : '' }}"
Expand Down
31 changes: 31 additions & 0 deletions tests/Feature/Groups/GroupHostTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,35 @@ public function testHostMakeHost()
$this->expectException(AuthenticationException::class);
$response = $this->delete("/api/v2/groups/{$this->idgroups}/volunteers/{$host->id}?api_token=" . $host->api_token);
}

public function providerTrueFalse()
{
return [
[false],
[true],
];
}

/**
* @dataProvider providerTrueFalse
*/
public function testNetworkCoordinatorDemoteHost($addToNetwork) {
$host = User::factory()->host()->create();
$this->group->addVolunteer($host);
$this->group->makeMemberAHost($host);

$coordinator = User::factory()->networkCoordinator()->create();

if ($addToNetwork) {
$this->network->addCoordinator($coordinator);
} else {
$this->expectException(AuthenticationException::class);
}

$response = $this->patch("/api/v2/groups/{$this->idgroups}/volunteers/{$host->id}?api_token=".$coordinator->api_token, [
'host' => true,
]);

$response->assertSuccessful();
}
}

0 comments on commit 9b0a138

Please sign in to comment.