Replace isAdmin, isDisabled and isModerator functions with direct role checking and remove roleCheck function from User model

This commit is contained in:
DariusIII
2018-08-03 11:10:01 +02:00
parent ebfa8210cb
commit dd977c65b7
6 changed files with 9 additions and 52 deletions
+1
View File
@@ -1,4 +1,5 @@
2018-08-03 DariusIII
* Chg: Replace isAdmin, isDisabled and isModerator functions with direct role checking and remove roleCheck function from User model
* Fix: Fix another instance of wrong isDisabled check
2018-08-02 DariusIII
* Fix: Fix wrong links to group browsing page in movie and xxx cover views
+1 -1
View File
@@ -79,7 +79,7 @@ class ApiController extends BasePageController
}
}
if (User::isDisabled($res['id'])) {
if ($res->hasRole('Disabled') === true) {
Utility::showApiError(101);
}
+2 -2
View File
@@ -31,7 +31,7 @@ class GetNzbController extends BasePageController
$uid = Auth::id();
$maxDownloads = $this->userdata->role->downloadrequests;
$rssToken = $this->userdata['api_token'];
if (User::isDisabled($this->userdata['id'])) {
if ($this->userdata->hasRole('Disabled') === true) {
Utility::showApiError(101);
}
} else {
@@ -47,7 +47,7 @@ class GetNzbController extends BasePageController
$uid = $res['id'];
$rssToken = $res['api_token'];
$maxDownloads = $res->role->downloadrequests;
if (User::isDisabled($res['id'])) {
if ($res->hasRole('Disabled') === true) {
Utility::showApiError(101);
}
}
+4 -4
View File
@@ -30,8 +30,8 @@ class ProfileController extends BasePageController
$this->setPrefs();
$sab = new SABnzbd($this);
$userID = Auth::id();
$privileged = User::isAdmin($userID) || User::isModerator($userID);
$userID = $this->userdata->id;
$privileged = $this->userdata->hasRole('Admin') === true || $this->userdata->hasRole('Moderator');
$privateProfiles = (int) Settings::settingValue('..privateprofiles') === 1;
$publicView = false;
@@ -52,8 +52,8 @@ class ProfileController extends BasePageController
}
}
$downloadlist = UserDownload::getDownloadRequestsForUser($userID);
$this->smarty->assign('downloadlist', $downloadlist);
$downloadList = UserDownload::getDownloadRequestsForUser($userID);
$this->smarty->assign('downloadlist', $downloadList);
$data = User::find($userID);
if ($data === null) {
+1 -1
View File
@@ -86,7 +86,7 @@ class RssController extends BasePageController
$rssToken = $res['api_token'];
$maxRequests = $res->role->apirequests;
if (User::isDisabled($res['id'])) {
if ($res->hasRole('Disabled') === true) {
Utility::showApiError(101);
}
}
-44
View File
@@ -692,16 +692,6 @@ class User extends Authenticatable
return self::query()->where('api_token', $rssToken)->first();
}
/**
* @param int $userId
*
* @return bool
*/
public static function isDisabled($userId): bool
{
return self::roleCheck('Disabled', $userId);
}
/**
* @param $url
*
@@ -987,40 +977,6 @@ class User extends Authenticatable
return self::hashSHA1($siteseed.$host.$siteseed);
}
/**
* @param string $role
* @param int $userId
* @return bool
*/
public static function roleCheck($role, $userId): bool
{
$user = self::find($userId);
return $user->hasRole($role);
}
/**
* Wrapper for roleCheck specifically for Admins.
*
* @param int $userID
* @return bool
*/
public static function isAdmin($userID): bool
{
return self::roleCheck('Admin', (int) $userID);
}
/**
* Wrapper for roleCheck specifically for Moderators.
*
* @param int $userId
* @return bool
*/
public static function isModerator($userId): bool
{
return self::roleCheck('Moderator', (int) $userId);
}
/**
* @param $serverUrl
* @param $uid