Skip to content

Commit

Permalink
Fix #63 Fix #62 fix user permission bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ziishaned committed Apr 5, 2017
1 parent f28a37b commit 495bdde
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 149 deletions.
25 changes: 0 additions & 25 deletions app/Http/Controllers/InviteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,6 @@ public function __construct(Request $request, Invite $invite)
$this->invite = $invite;
}

public function index()
{

}

public function create()
{

}

public function store(Team $team)
{
$this->validate($this->request, Invite::INVITE_RULES, [
Expand Down Expand Up @@ -57,21 +47,6 @@ public function sendInvitationEmail($invitation, $team)
return true;
}

public function show($id)
{

}

public function edit($id)
{

}

public function update(Request $request, $id)
{

}

public function destroy(Team $team, $invitationCode)
{
$this->invite->where('code', $invitationCode)->where('team_id', $team->id)->delete();
Expand Down
7 changes: 1 addition & 6 deletions app/Http/Controllers/TeamController.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ public function isContentTypeJson()
return $this->request->header('content-type') == 'application/json';
}

public function edit($id)
{

}

public function update(Team $team)
{
if($team->name === $this->request->get('team_name')) {
Expand Down Expand Up @@ -111,7 +106,7 @@ public function postJoin(Team $team, $hash)

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

DB::table('users_roles')->update([
DB::table('users_roles')->insert([
'role_id' => $invitation->role_id,
'user_id' => $user->id,
'team_id' => $team->id,
Expand Down
4 changes: 1 addition & 3 deletions app/Http/Middleware/CheckPermission.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ public function handle($request, Closure $next, $permissions = null)
}
}

return response()->json([
'Unauthorized.'
], 401);
abort(403);
}
}
4 changes: 2 additions & 2 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function watchWikis()
*/
public function roles()
{
return $this->hasMany(Role::class, 'user_id', 'id')->with('permissions');
return $this->belongsToMany(Role::class, 'users_roles', 'user_id', 'role_id')->with('permissions');
}

/**
Expand Down Expand Up @@ -293,7 +293,7 @@ public function hasPermission($routePermissions)
{
$routePermissions = explode('|', $routePermissions);

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

foreach ($roles as $role) {
foreach ($role->permissions as $permission) {
Expand Down
Loading

0 comments on commit 495bdde

Please sign in to comment.