Skip to content

Commit

Permalink
update isVocabularyEditor to use Permission model
Browse files Browse the repository at this point in the history
  • Loading branch information
nevinsm committed Sep 24, 2024
1 parent 7569471 commit 9379f48
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,9 @@ public function getPermissions()

public function isVocabularyEditor()
{
$userId = $this->id;
$vocabularyEditorPrivilegeLabel = 'Edit Vocabulary';
$roles = DB::table('appuser')->join('appuser_role_link', function ($join) use ($userId) {
$join->on('appuser.id', '=', 'appuser_role_link.uid')->where('appuser.id', '=', $userId);
})->join('privilege_role_link', 'privilege_role_link.rid', '=', 'appuser_role_link.rid')->
join('privilege', function ($join) use ($vocabularyEditorPrivilegeLabel) {
$join->on('privilege_role_link.pid', '=', 'privilege.id')->where('privilege.label', '=', $vocabularyEditorPrivilegeLabel);
})->select('appuser_role_link.rid')->get();
return $roles->count() > 0;
$permissions = $this->getPermissions();
$vocabEditor = Permission::where('label', 'Edit Vocabulary')->first();

return $permissions->contains($vocabEditor);
}
}

0 comments on commit 9379f48

Please sign in to comment.