Skip to content

Commit 495bdde

Browse files
committed
Fix #63 Fix #62 fix user permission bug
1 parent f28a37b commit 495bdde

File tree

7 files changed

+162
-149
lines changed

7 files changed

+162
-149
lines changed

app/Http/Controllers/InviteController.php

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,6 @@ public function __construct(Request $request, Invite $invite)
1919
$this->invite = $invite;
2020
}
2121

22-
public function index()
23-
{
24-
25-
}
26-
27-
public function create()
28-
{
29-
30-
}
31-
3222
public function store(Team $team)
3323
{
3424
$this->validate($this->request, Invite::INVITE_RULES, [
@@ -57,21 +47,6 @@ public function sendInvitationEmail($invitation, $team)
5747
return true;
5848
}
5949

60-
public function show($id)
61-
{
62-
63-
}
64-
65-
public function edit($id)
66-
{
67-
68-
}
69-
70-
public function update(Request $request, $id)
71-
{
72-
73-
}
74-
7550
public function destroy(Team $team, $invitationCode)
7651
{
7752
$this->invite->where('code', $invitationCode)->where('team_id', $team->id)->delete();

app/Http/Controllers/TeamController.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,6 @@ public function isContentTypeJson()
5555
return $this->request->header('content-type') == 'application/json';
5656
}
5757

58-
public function edit($id)
59-
{
60-
61-
}
62-
6358
public function update(Team $team)
6459
{
6560
if($team->name === $this->request->get('team_name')) {
@@ -111,7 +106,7 @@ public function postJoin(Team $team, $hash)
111106

112107
$invitation = (new Invite)->getInvitation($team->id, $hash);
113108

114-
DB::table('users_roles')->update([
109+
DB::table('users_roles')->insert([
115110
'role_id' => $invitation->role_id,
116111
'user_id' => $user->id,
117112
'team_id' => $team->id,

app/Http/Middleware/CheckPermission.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ public function handle($request, Closure $next, $permissions = null)
2222
}
2323
}
2424

25-
return response()->json([
26-
'Unauthorized.'
27-
], 401);
25+
abort(403);
2826
}
2927
}

app/Models/User.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function watchWikis()
7777
*/
7878
public function roles()
7979
{
80-
return $this->hasMany(Role::class, 'user_id', 'id')->with('permissions');
80+
return $this->belongsToMany(Role::class, 'users_roles', 'user_id', 'role_id')->with('permissions');
8181
}
8282

8383
/**
@@ -293,7 +293,7 @@ public function hasPermission($routePermissions)
293293
{
294294
$routePermissions = explode('|', $routePermissions);
295295

296-
$roles = $this->with('roles')->findOrFail(Auth::user()->id)->roles;
296+
$roles = Auth::user()->roles;
297297

298298
foreach ($roles as $role) {
299299
foreach ($role->permissions as $permission) {

0 commit comments

Comments
 (0)