Skip to content

Commit 6c2f439

Browse files
JuragerJurager
Jurager
authored and
Jurager
committed
prepare for new release
1 parent 9519cd9 commit 6c2f439

38 files changed

+510
-250
lines changed

README.md

+45-40
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ You can add a user to a global group to grant them access to all teams with the
1414
> The documentation for this package is currently being written. For now, please refer to this readme for information on the functionality and usage of the package.
1515
1616
- [Requirements](#requirements)
17+
- [Schema](#schema)
1718
- [Installation](#installation)
1819
- [Actions](#actions)
1920
- [Teams](#teams)
@@ -39,6 +40,10 @@ Requirements
3940
-------------------------------------------
4041
`PHP >= 8.1` and `Laravel 8.x or higher`
4142

43+
Schema
44+
-------------------------------------------
45+
![Schema](schema.png "Title")
46+
4247
Installation
4348
-------------------------------------------
4449

@@ -100,49 +105,49 @@ $team->users()
100105
$team->allUsers()
101106

102107
// Determine if the given user is a team member...
103-
$team->hasUser((object) $user)
108+
$team->hasUser(object $user)
104109

105110
// Get all the abilities belong to the team.
106111
$team->abilities()
107112

108113
// Get all the team's roles.
109114
$team->roles()
110115

111-
// Get the role from the team by role id or name
112-
$team->findRole((int|string) $id)
113-
114116
// Return the user role object from the team
115-
$team->userRole((object) $user)
117+
$team->userRole(object $user)
118+
119+
// Get the role from the team by role id or code
120+
$team->getRole(int|string $keyword)
116121

117122
// Add new role to the team
118-
$team->addRole((string) $code, (array) $capabilities)
123+
$team->addRole(string $code, array $capabilities)
119124

120125
// Update the role in the team
121-
$team->updateRole((string) $code, (array) $capabilities)
126+
$team->updateRole(string $code, array $capabilities)
122127

123128
// Deletes the given role from team
124-
$team->deleteRole((string) $code)
129+
$team->deleteRole(string $code)
125130

126131
// Get all groups of the team.
127132
$team->groups()
128133

129-
// Get team group by its code
130-
$team->group((string) $code)
134+
// Get team group by its id or code
135+
$team->getGroup(int|string $keyword)
131136

132137
// Add new group to the team
133-
$team->addGroup((string) $code, (string) $name)
138+
$team->addGroup(string $code, string $name)
134139

135140
// Delete group from the team
136-
$team->deleteGroup((string) $code)
141+
$team->deleteGroup(string $code)
137142

138143
// Determine if the team has a member with the given email address...
139-
$team->hasUserWithEmail((array) $emailAddress)
144+
$team->hasUserWithEmail(array $email)
140145

141146
// Determine if the given user is a team member with the given permission...
142-
$team->userHasPermission((object) $user, (string|array) $permission, (bool) $require = false)
147+
$team->userHasPermission(object $user, string|array $permission, bool $require = false)
143148

144149
// Remove the given user from the team.
145-
$team->deleteUser((object) $user);
150+
$team->deleteUser(object $user);
146151

147152
// Determine if the team has a member with the given email address...
148153
$team->invitations()
@@ -169,34 +174,34 @@ $user->ownedTeams : Illuminate\Database\Eloquent\Collection
169174
$user->allTeams() : Illuminate\Database\Eloquent\Collection
170175

171176
// Determine if a user owns a given team...
172-
$user->ownsTeam((object) $team) : bool
177+
$user->ownsTeam(object $team) : bool
173178

174179
// Determine if a user belongs to a given team...
175-
$user->belongsToTeam((object) $team) : bool
180+
$user->belongsToTeam(object $team) : bool
176181

177182
// Get the role that the user is assigned on the team...
178-
$user->teamRole((object) $team) : \Jurager\Teams\Role
183+
$user->teamRole(object $team) : \Jurager\Teams\Role
179184

180185
// Determine if the user has the given role on the given team...
181-
$user->hasTeamRole((object) $team, (string|array) 'admin', (bool) $require = false) : bool
186+
$user->hasTeamRole(object $team, string|array 'admin', bool $require = false) : bool
182187

183188
// Access an array of all permissions a user has for a given team...
184-
$user->teamPermissions((object) $team) : array
189+
$user->teamPermissions(object $team) : array
185190

186191
// Determine if a user has a given team permission...
187-
$user->hasTeamPermission((object) $team, (string|array) 'server:create', (bool) $require = false) : bool
192+
$user->hasTeamPermission(object $team, string|array 'server:create', bool $require = false) : bool
188193

189194
// Get list of abilities or forbidden abilities for users on certain model
190-
$user->teamAbilities((object) $team, (object) $server) : mixed
195+
$user->teamAbilities(object $team, object $server) : mixed
191196

192197
// Determine if a user has a given ability on certain model...
193-
$user->hasTeamAbility((object) $team, (string) 'server:edit', (object) $server) : bool
198+
$user->hasTeamAbility(object $team, string 'server:edit', object $server) : bool
194199

195200
// Add an ability for user to action on certain model, if permission is not found, will create a new one
196-
$user->allowTeamAbility((object) $team, (string) 'server:edit', (object) $server) : bool
201+
$user->allowTeamAbility(object $team, string 'server:edit', object $server) : bool
197202

198203
// Forbid an ability for user to action on certain model, used in case if global permission or role allowing this action
199-
$user->forbidTeamAbility((object) $team, (string) 'server:edit', (object) $server) : bool
204+
$user->forbidTeamAbility(object $team, string 'server:edit', object $server) : bool
200205
```
201206

202207
These methods enable you to efficiently manage and inspect a user's teams, roles, permissions, and abilities within your application.
@@ -221,25 +226,25 @@ The `Jurager\Teams\Traits\HasTeams` trait provides methods to inspect a user's t
221226

222227
```php
223228
// Add new group to the team
224-
$team->addGroup((string) $code, (string) $name)
229+
$team->addGroup(string $code, string $name)
225230

226231
// Delete group from the team
227-
$team->deleteGroup((string) $code)
232+
$team->deleteGroup(string $code)
228233

229234
// Get all groups of the team.
230235
$team->groups();
231236

232237
// Get team group by its code
233-
$team->group((string) $code);
238+
$team->getGroup(int|string $keyword);
234239

235240
// Get all group users
236-
$team->group((string) $code)->users();
241+
$team->getGroup(int|string $keyword)->users();
237242

238243
// Attach users or user to a group
239-
$team->group((string) $code)->attachUser((Collection|Model) $user);
244+
$team->getGroup(int|string $keyword)->attachUser(Collection|Model $user);
240245

241246
// Detach users or user from group
242-
$team->group((string) $code)->detachUser((Collection|Model) $user);
247+
$team->getGroup(int|string $keyword)->detachUser(Collection|Model $user);
243248
```
244249

245250
### Groups Permissions
@@ -248,20 +253,20 @@ You can manage permissions within a group using the following methods:
248253

249254
```php
250255
// Add an ability for user to action on certain model within team group, if permission is not found, will create a new one
251-
$user->allowTeamAbility((object) $team, (string) 'server:edit', (object) $server, (object|null) $group));
256+
$user->allowTeamAbility(object $team, string 'server:edit', object $server, object|null $group));
252257

253258
// Forbid an ability for user to action on certain model within team group
254-
$user->forbidTeamAbility((object) $team, (string) 'server:edit', (object) $server, (object|null) $group);
259+
$user->forbidTeamAbility(object $team, string 'server:edit', object $server, object|null $group);
255260

256261
// Delete user ability to action on certain model within team group
257-
$user->deleteTeamAbility((object) $team, (string) 'server:edit', (object) $server, (object|null) $group);
262+
$user->deleteTeamAbility(object $team, string 'server:edit', object $server, object|null $group);
258263
```
259264
> [!NOTE]
260265
> Team groups work together with abilities, so you should use ability checking methods to determine if users have specific access rights within groups.
261266
262267
```php
263268
// Determinate if user can perform an action
264-
$user->hasTeamAbility((object) $team, (string) 'server:edit', (object) $server)
269+
$user->hasTeamAbility(object $team, string 'server:edit', object $server)
265270
```
266271

267272
Middleware `ability` is used to check the user's rights within the team group during requests to your application
@@ -322,7 +327,7 @@ To ensure that incoming requests initiated by a team member can be executed by t
322327
> In most cases, it's unnecessary to check a user's role directly. Instead, focus on verifying specific granular permissions. Roles primarily serve as a way to group granular permissions for organizational purposes. Typically, you'll execute calls to this method within your application's [authorization policies](https://laravel.com/docs/authorization#creating-policies).
323328
324329
```php
325-
return $user->hasTeamPermission((string) $server->team, (string) 'server:update');
330+
return $user->hasTeamPermission(string $server->team, string 'server:update');
326331
```
327332

328333
This example demonstrates how to check if a user within a team has permission to update a server. Adjust the parameters according to your application's specific requirements and use cases.
@@ -340,23 +345,23 @@ Simply pass the name of the ability, and the package will create it if it's not
340345
To add the ability to edit an article within a team for a specific user, you need to provide the entity, such as the article object, and the team object:
341346

342347
```php
343-
User::allowTeamAbility((object) $team, string 'edit', (object) $article, (object|null) $group);
348+
User::allowTeamAbility(object $team, string 'edit', object $article, object|null $group);
344349
```
345350

346351
### Checking an Ability
347352

348353
To check if a user has a specific ability in a team, you can use the following method:
349354

350355
```php
351-
User::hasTeamAbility((object) $team, string 'edit', (object) $article);
356+
User::hasTeamAbility(object $team, string 'edit', object $article);
352357
```
353358

354359
### Forbidding an Ability
355360

356361
If you need to forbid a user from having a certain ability for instance, if the role abilities allow this ability, you can do so using the following method:
357362

358363
```php
359-
User::forbidTeamAbility((object) $team, (string) 'edit', (object) $article, (object|null) $group);
364+
User::forbidTeamAbility(object $team, string 'edit', object $article, object|null $group);
360365
```
361366

362367
### Creating Abilities
@@ -445,4 +450,4 @@ In this case, pass `article_id` as a request parameter or route parameter to all
445450

446451
## License
447452

448-
This package is open-sourced software licensed under the [MIT license](LICENSE.md).
453+
This package is open-sourced software licensed under the [MIT license](LICENSE.md).

config/teams.php

+17
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,23 @@
7171
'team_id' => 'team_id',
7272
],
7373

74+
/*
75+
|--------------------------------------------------------------------------
76+
| Invitations
77+
|--------------------------------------------------------------------------
78+
| Configures the team invitation feature, allowing users to be invited to join teams.
79+
*/
80+
'invitations' => [
81+
82+
'enabled' => true,
83+
84+
'routes' => [
85+
'register' => true,
86+
'url' => '/invitation/accept',
87+
'middleware' => 'web'
88+
]
89+
],
90+
7491
/*
7592
|--------------------------------------------------------------------------
7693
| Support
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration {
8+
/**
9+
* Run the migrations.
10+
*
11+
* @return void
12+
*/
13+
public function up(): void
14+
{
15+
Schema::table('users', static function (Blueprint $table) {
16+
$table->boolean(config('teams.support_field', 'is_support'))->nullable();
17+
});
18+
}
19+
20+
/**
21+
* Reverse the migrations.
22+
*
23+
* @return void
24+
*/
25+
public function down(): void
26+
{
27+
Schema::table('users', static function (Blueprint $table) {
28+
$table->dropColumn(config('teams.support_field', 'is_support'));
29+
});
30+
}
31+
};
+26-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,29 @@
1-
{{ __('You have been invited to join the :team team!', ['team' => $invitation->team->name]) }}
1+
<div style="font-family: Arial, sans-serif; background-color: #f3f4f6; padding: 20px; margin: auto; color: #333;">
2+
<!-- Header -->
3+
<div style="text-align: center; padding: 20px 0;">
4+
<h2 style="color: #333333; font-size: 28px; margin-bottom: 10px;">
5+
{{ __('You’re Invited to Join the :team Team!', ['team' => $invitation->team->name]) }}
6+
</h2>
7+
<p style="font-size: 16px; color: #666666; margin: 0;">
8+
{{ __('We are thrilled to have you with us! Follow the instructions below to join our team.') }}
9+
</p>
10+
</div>
211

3-
{{ __('If you do not have an account, you may create one by clicking the button below. After creating an account, you may click the invitation acceptance button in this email to accept the team invitation:') }}
12+
<!-- Invitation Info -->
13+
<p style="font-size: 15px; color: #555555; line-height: 1.7;">
14+
{{ __('If you already have an account or create one using the provided link, click below to accept the invitation and join the team!') }}
15+
</p>
416

5-
{{ __('Create Account') }}
17+
<!-- Accept Invitation Button -->
18+
<div style="margin-top: 20px; text-align: center;">
19+
<a href="{{ $url }}" style="display: inline-block; padding: 12px 28px; font-size: 16px; font-weight: bold; color: #ffffff; background-color: #28a745; border-radius: 6px; text-decoration: none; box-shadow: 0 4px 8px rgba(40, 167, 69, 0.3);">
20+
{{ __('Accept Invitation') }}
21+
</a>
22+
</div>
623

7-
{{ __('If you already have an account, you may accept this invitation by clicking the button below:') }}
8-
9-
{{ __('Accept Invitation') }}
24+
<!-- Footer -->
25+
<div style="margin-top: 30px; text-align: center; font-size: 14px; color: #999999;">
26+
<p>{{ __('If you have any questions, feel free to reach out to our support team.') }}</p>
27+
<p>{{ __('Best regards,') }}<br><strong>{{ config('app.name') }}</strong></p>
28+
</div>
29+
</div>

routes/web.php

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
use App\Http\Controllers\InviteController;
4+
use Illuminate\Support\Facades\Route;
5+
6+
Route::middleware(config('teams.invitations.routes.middleware'))
7+
->get(config('teams.invitations.routes.url'), [InviteController::class, 'inviteAccept'])
8+
->name('teams.invitations.accept');

schema.png

871 KB
Loading

src/Console/InstallCommand.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ public function handle(): void
4646
// Policies...
4747
(new Filesystem)->copyDirectory(__DIR__.'/../../stubs/app/Policies', app_path('Policies'));
4848

49+
// Controllers...
50+
(new Filesystem)->copyDirectory(__DIR__.'/../../stubs/app/Controllers', app_path('Http/Controllers/'));
51+
4952
$this->info('All done. Have a nice journey.');
5053
}
51-
}
54+
}

src/Mail/Invitation.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public function __construct(InvitationModel $invitation)
3434
*/
3535
public function build(): static
3636
{
37-
return $this->markdown('teams::emails.invitation', ['acceptUrl' => URL::signedRoute('invitations.accept', [
37+
return $this->markdown('teams::emails.invitation', ['url' => URL::signedRoute('teams.invitations.accept', [
3838
'invitation' => $this->invitation,
3939
])])->subject(__('Team Invitation'));
4040
}
41-
}
41+
}

src/Middleware/Ability.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@
77

88
class Ability extends Teams
99
{
10+
1011
/**
1112
* Handle incoming request.
1213
*
13-
* @param array ...$models
14+
* @param Request $request
15+
* @param Closure $next
16+
* @param string $ability
17+
* @param ...$models
18+
* @return mixed
1419
*/
1520
public function handle(Request $request, Closure $next, string $ability, ...$models): mixed
1621
{
@@ -20,4 +25,4 @@ public function handle(Request $request, Closure $next, string $ability, ...$mod
2025

2126
return $next($request);
2227
}
23-
}
28+
}

0 commit comments

Comments
 (0)