Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion app/Http/Controllers/API/GroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1074,10 +1074,15 @@ public function updateGroupv2(Request $request, $idGroup): JsonResponse {
'email' => $email,
];

// Hosts can edit the postcode (area stays admin/coordinator only, below). Only touch it when sent, so a
// partial update doesn't blank it.
if ($request->has('postcode')) {
$data['postcode'] = $postcode;
}

if ($user->hasRole('Administrator') || ($user->hasRole('NetworkCoordinator') && $isCoordinatorForGroup)) {
// Got permission to update these.
$data['area'] = $area;
$data['postcode'] = $postcode;
$data['archived_at'] = $archived_at;
}

Expand Down Expand Up @@ -1212,13 +1217,15 @@ private function validateGroupParams(Request $request, $create, ?Group $existing
'location' => ['required', 'max:255'],
'description' => ['required'],
'website' => ['nullable', 'url', 'max:255'],
'postcode' => ['nullable', 'max:32'],
]);
} else {
$request->validate([
'name' => ['max:255'],
'location' => ['max:255'],
'website' => ['nullable', 'url', 'max:255'],
'archived_at' => ['nullable', 'date'],
'postcode' => ['nullable', 'max:32'],
]);
}

Expand Down
1 change: 0 additions & 1 deletion resources/js/components/GroupAddEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
:lat.sync="lat"
:lng.sync="lng"
:postcode.sync="postcode"
:can-edit-postcode="canApprove"
class="group-location"
:has-error="$v.location.$error"
ref="location"
Expand Down
7 changes: 1 addition & 6 deletions resources/js/components/GroupLocation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</b-form-group>
<b-form-group>
<label for="group_postcode">{{ __('groups.postcode') }}:</label>
<b-input id="group_postcode" name="postcode" v-model="currentPostcode" :class="{ hasError: hasError }" :readonly="!canEditPostcode" />
<b-input id="group_postcode" name="postcode" v-model="currentPostcode" maxlength="32" :class="{ hasError: hasError }" />
<small>{{ __('groups.groups_postcode_small') }}</small>
</b-form-group>
</div>
Expand Down Expand Up @@ -77,11 +77,6 @@ export default {
type: Boolean,
required: false,
default: false
},
canEditPostcode: {
type: Boolean,
required: false,
default: false
}
},
components: {
Expand Down
33 changes: 33 additions & 0 deletions tests/Feature/Groups/GroupEditTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,39 @@
]);
}

/** @test */
public function host_can_edit_postcode_but_not_area(): void {
$group = Group::factory()->create(['postcode' => 'SW9 7QD', 'area' => 'London']);

$host = User::factory()->host()->create();
$group->addVolunteer($host);
$group->makeMemberAHost($host);
$this->actingAs($host);

$response = $this->patch('/api/v2/groups/' . $group->idgroups, [
'postcode' => 'E8 1AA',

Check failure on line 105 in tests/Feature/Groups/GroupEditTest.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "E8 1AA" 3 times.

See more on https://sonarcloud.io/project/issues?id=TheRestartProject_restarters.net&issues=AaDOznsOc7K7ZFqy6-Fu&open=AaDOznsOc7K7ZFqy6-Fu&pullRequest=917
'area' => 'Elsewhere',
]);
$response->assertSuccessful();

$group->refresh();
$this->assertEquals('E8 1AA', $group->postcode);
$this->assertEquals('London', $group->area);

// A partial update that doesn't send the postcode leaves it alone.
$response = $this->patch('/api/v2/groups/' . $group->idgroups, [
'network_data' => ['foo' => 'bar'],
]);
$response->assertSuccessful();
$this->assertEquals('E8 1AA', $group->refresh()->postcode);

// Longer than the column.
$this->expectException(\Illuminate\Validation\ValidationException::class);
$this->patch('/api/v2/groups/' . $group->idgroups, [
'postcode' => str_repeat('X', 33),
]);
}

/** @test */
public function image_upload(): void {
Storage::fake('avatars');
Expand Down