From 9379f48a6ac4598408e736e6d733d4e57cd62127 Mon Sep 17 00:00:00 2001 From: Nevin Morgan Date: Tue, 24 Sep 2024 16:36:09 -0400 Subject: [PATCH] update isVocabularyEditor to use Permission model --- app/Models/User.php | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/app/Models/User.php b/app/Models/User.php index 76ff7e2..13256f5 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -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); } }