Add patch to rename user_roles_id to roles_id, update related classes

This commit is contained in:
DariusIII
2018-08-01 10:46:21 +02:00
parent f80408a50e
commit 00f09c4a6e
10 changed files with 22 additions and 17 deletions
+1
View File
@@ -1,4 +1,5 @@
2018-08-01 DariusIII
* Chg: Add patch to rename user_roles_id to roles_id, update related classes
* Chg: Update role related classes, rename user_roles to roles where used
2018-07-30 DariusIII
* Chg: Update roleCheck function in User model
+1 -1
View File
@@ -113,7 +113,7 @@ if (! function_exists('makeFieldLinks')) {
case 'grabs':
$orderField = 'grabs';
break;
case 'user_roles_id':
case 'roles_id':
$orderField = 'users_role_id';
break;
case 'rolechangedate':
@@ -62,7 +62,7 @@ class RegisterController extends Controller
'email' => $data['email'],
'password' => User::hashPassword($data['password']),
'host' => $data['host'] ?? '',
'user_roles_id' => $data['user_roles_id'],
'roles_id' => $data['roles_id'],
'notes' => $data['notes'],
'invites' => $data['defaultinvites'],
'api_token' => md5(Password::getRepository()->createNewToken()),
@@ -135,7 +135,7 @@ class RegisterController extends Controller
'password' => $password,
'email' => $email,
'host' => $request->ip(),
'user_roles_id' => $userDefault !== null ? $userDefault['id'] : User::ROLE_USER,
'roles_id' => $userDefault !== null ? $userDefault['id'] : User::ROLE_USER,
'notes' => '',
'defaultinvites' => $userDefault !== null ? $userDefault['defaultinvites'] : Invitation::DEFAULT_INVITES,
]
+3 -3
View File
@@ -225,7 +225,7 @@ class BasePageController extends Controller
protected function setUserPreferences(): void
{
$this->userdata['categoryexclusions'] = User::getCategoryExclusion(Auth::id());
$this->userdata['rolecategoryexclusions'] = RoleExcludedCategory::getRoleCategoryExclusion($this->userdata['user_roles_id']);
$this->userdata['rolecategoryexclusions'] = RoleExcludedCategory::getRoleCategoryExclusion($this->userdata['roles_id']);
// Change the theme to user's selected theme if they selected one, else use the admin one.
if ((int) Settings::settingValue('site.main.userselstyle') === 1) {
@@ -256,7 +256,7 @@ class BasePageController extends Controller
if ($sab->integratedBool !== false && $sab->url !== '' && $sab->apikey !== '') {
$this->smarty->assign('sabapikeytype', $sab->apikeytype);
}
switch ((int) $this->userdata['user_roles_id']) {
switch ((int) $this->userdata['roles_id']) {
case User::ROLE_ADMIN:
$this->smarty->assign('isadmin', 'true');
break;
@@ -272,7 +272,7 @@ class BasePageController extends Controller
$role = User::ROLE_USER;
if (! empty($this->userdata)) {
$role = $this->userdata['user_roles_id'];
$role = $this->userdata['roles_id'];
}
$content = new Contents();
+1 -1
View File
@@ -179,7 +179,7 @@ class ProfileController extends BasePageController
$data['username'],
$request->input('email'),
$data['grabs'],
$data['user_roles_id'],
$data['roles_id'],
$data['notes'],
$data['invites'],
$request->has('movieview') ? 1 : 0,
+3 -3
View File
@@ -45,7 +45,7 @@ class RoleExcludedCategory extends Model
public static function getRoleCategoryExclusion($role): array
{
$ret = [];
$categories = self::query()->where('user_roles_id', $role)->get(['categories_id']);
$categories = self::query()->where('roles_id', $role)->get(['categories_id']);
foreach ($categories as $category) {
$ret[] = $category['categories_id'];
}
@@ -62,7 +62,7 @@ class RoleExcludedCategory extends Model
self::delRoleCategoryExclusions($role);
if (\count($catids) > 0) {
foreach ($catids as $catid) {
self::create(['user_roles_id' => $role, 'categories_id' => $catid]);
self::create(['roles_id' => $role, 'categories_id' => $catid]);
}
}
}
@@ -72,6 +72,6 @@ class RoleExcludedCategory extends Model
*/
public static function delRoleCategoryExclusions($role): void
{
self::query()->where('user_roles_id', $role)->delete();
self::query()->where('roles_id', $role)->delete();
}
}
+4 -4
View File
@@ -159,7 +159,7 @@ class User extends Authenticatable
*/
public function role()
{
return $this->belongsTo(Role::class, 'user_roles_id');
return $this->belongsTo(Role::class, 'roles_id');
}
/**
@@ -347,7 +347,7 @@ class User extends Authenticatable
'username' => $userName,
'email' => $email,
'grabs' => $grabs,
'user_roles_id' => $role,
'roles_id' => $role,
'notes' => substr($notes, 0, 255),
'invites' => $invites,
'movieview' => $movieview,
@@ -426,7 +426,7 @@ class User extends Authenticatable
*/
public static function updateUserRole(int $uid, int $role): int
{
return self::query()->where('id', $uid)->update(['user_roles_id' => $role]);
return self::query()->where('id', $uid)->update(['roles_id' => $role]);
}
/**
@@ -447,7 +447,7 @@ class User extends Authenticatable
$data = self::query()->whereDate('rolechangedate', '<', now())->get();
foreach ($data as $u) {
self::query()->where('id', $u['id'])->update(['user_roles_id' => self::ROLE_USER, 'rolechangedate' => null]);
self::query()->where('id', $u['id'])->update(['roles_id' => self::ROLE_USER, 'rolechangedate' => null]);
Mail::to($u['email'])->send(new AccountExpired($u['id']));
}
@@ -18,10 +18,10 @@ class CreateRoleExcludedCategoriesTable extends Migration {
$table->charset = 'utf8';
$table->collation = 'utf8_unicode_ci';
$table->increments('id');
$table->integer('user_roles_id');
$table->integer('roles_id');
$table->integer('categories_id')->nullable();
$table->timestamps();
$table->unique(['user_roles_id','categories_id'], 'ix_roleexcat_rolecat');
$table->unique(['roles_id','categories_id'], 'ix_roleexcat_rolecat');
});
}
+4
View File
@@ -0,0 +1,4 @@
# Rename user_roles_id to roles_id
ALTER TABLE users CHANGE user_roles_id roles_id INT(11) NOT NULL DEFAULT '1' COMMENT 'FK to roles.id';
ALTER TABLE role_excluded_categories CHANGE user_roles_id roles_id INT(11) NOT NULL DEFAULT '1' COMMENT 'FK to roles.id';
+1 -1
View File
@@ -99,7 +99,7 @@
<td>{$user->rolename}</td>
<td>{if !empty($user->rolechangedate)}{$user->rolechangedate}{/if}</td>
<td>{if {$user->verified} == 1} Yes {else} No {/if}</td>
<td>{if $user->user_roles_id !="2"}<a class="confirm_action" href="{$smarty.const.WWW_TOP}/admin/user-delete?id={$user->id}">delete</a>{/if}
<td>{if $user->roles_id !="2"}<a class="confirm_action" href="{$smarty.const.WWW_TOP}/admin/user-delete?id={$user->id}">delete</a>{/if}
</td>
</tr>
{/foreach}