Skip to content

Commit 37948be

Browse files
authored
Ability to update Organisation details (#40)
* Update php.yml * Update php.yml * Update web.php * Create OrganisationController.php * Update web.php * Add ability to update organisation * Add OrganisationController tests * Add UI for updating an organisation * Fix code style
1 parent ecba7e7 commit 37948be

File tree

15 files changed

+271
-16
lines changed

15 files changed

+271
-16
lines changed

.github/workflows/php.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737

3838
- name: Get Composer dependencies
3939
id: cache-vendor
40-
uses: actions/cache@v3
40+
uses: actions/cache/restore@v3
4141
with:
4242
path: vendor
4343
key: ${{ runner.os }}-vendor-dev-${{ hashFiles('**/composer.lock') }}
@@ -58,17 +58,13 @@ jobs:
5858
name: Test
5959
needs: [lint, dependencies]
6060
runs-on: ubuntu-latest
61-
env:
62-
APP_ENV: testing
63-
DB_CONNECTION: sqlite
64-
DB_DATABASE: ":memory:"
6561

6662
steps:
6763
- uses: actions/checkout@v3
6864

6965
- name: Get Composer dependencies
7066
id: cache-vendor
71-
uses: actions/cache@v3
67+
uses: actions/cache/restore@v3
7268
with:
7369
path: vendor
7470
key: ${{ runner.os }}-vendor-dev-${{ hashFiles('**/composer.lock') }}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use App\Http\Requests\Organisation\OrganisationEdit;
6+
use App\Http\Requests\Organisation\OrganisationUpdate;
7+
use App\Http\Resources\OrganisationResource;
8+
9+
class OrganisationController extends Controller
10+
{
11+
public function edit(OrganisationEdit $request)
12+
{
13+
return \inertia('Organisation/Edit', [
14+
'organisation' => OrganisationResource::make($request->user()->currentOrganisation),
15+
]);
16+
}
17+
18+
public function update(OrganisationUpdate $request)
19+
{
20+
$request->user()->currentOrganisation->update($request->only('name'));
21+
22+
\session()->flash('message', \__('organisation.updated'));
23+
24+
return \back();
25+
}
26+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace App\Http\Requests\Organisation;
4+
5+
use Illuminate\Foundation\Http\FormRequest;
6+
7+
class OrganisationEdit extends FormRequest
8+
{
9+
public function authorize()
10+
{
11+
return $this->user()->can('manage-organisation');
12+
}
13+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace App\Http\Requests\Organisation;
4+
5+
use Illuminate\Foundation\Http\FormRequest;
6+
7+
class OrganisationUpdate extends FormRequest
8+
{
9+
public function authorize()
10+
{
11+
return $this->user()->can('manage-organisation');
12+
}
13+
14+
public function rules()
15+
{
16+
return [
17+
'name' => ['required', 'string', 'max:255'],
18+
];
19+
}
20+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace App\Http\Resources;
4+
5+
use Illuminate\Http\Resources\Json\JsonResource;
6+
7+
class OrganisationResource extends JsonResource
8+
{
9+
public function toArray($request)
10+
{
11+
return [
12+
'id' => $this->id,
13+
'name' => $this->name,
14+
];
15+
}
16+
}

bun.lockb

3.1 KB
Binary file not shown.

database/factories/UserFactory.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Database\Factories;
44

5+
use App\Models\User;
56
use Illuminate\Database\Eloquent\Factories\Factory;
67
use Illuminate\Support\Str;
78

@@ -28,4 +29,11 @@ public function unverified()
2829
'email_verified_at' => null,
2930
]);
3031
}
32+
33+
public function admin()
34+
{
35+
return $this->afterCreating(function (User $user) {
36+
$user->assignRole('admin');
37+
});
38+
}
3139
}

database/seeders/RolesAndPermissionsSeeder.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class RolesAndPermissionsSeeder extends Seeder
1414

1515
protected Collection $roles;
1616

17+
protected Collection $orgnaisationPermissions;
18+
1719
protected Collection $postPermissions;
1820

1921
public function run()
@@ -33,6 +35,10 @@ protected function createRoles()
3335

3436
protected function createPermissions()
3537
{
38+
$this->orgnaisationPermissions = \collect([
39+
Permission::create(['name' => 'manage-organisation']),
40+
]);
41+
3642
$this->postPermissions = \collect([
3743
Permission::create(['name' => 'create-posts']),
3844
Permission::create(['name' => 'view-posts']),
@@ -45,6 +51,8 @@ protected function createPermissions()
4551
protected function assignPermissionsToRoles()
4652
{
4753
$this->roles->get('admin')->givePermissionTo($this->postPermissions);
54+
$this->roles->get('admin')->givePermissionTo($this->orgnaisationPermissions);
55+
4856
$this->roles->get('user')->givePermissionTo($this->postPermissions);
4957
}
5058
}

lang/en/account.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22

33
return [
4-
54
'updated' => 'Your account has been updated.',
65
];

lang/en/organisation.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
return [
4+
'updated' => 'Your organisation has been updated.',
5+
];

0 commit comments

Comments
 (0)