Permalink
Browse files

Admin Roles - update the roles and roles index

  • Loading branch information...
bpocallaghan committed Jun 1, 2018
1 parent 86a8967 commit b4c72124c50730583b1d1951d33aebe77d2805f0
@@ -25,7 +25,7 @@ public function __construct(User $user, $token = null)
// if token - add admin role and mark as claimed
$userInvite = UserInvite::whereToken($token)->whereNull('claimed_at')->first();
if ($userInvite) {
$roles[] = Role::$ADMIN;
$roles[] = Role::$BASE_ADMIN;
// set invite claimed
$user->update(['gender' => 'male']);
$userInvite->update(['claimed_at' => Carbon::now()]);
@@ -23,7 +23,7 @@ public function index()
{
save_resource_url();
$items = User::with('roles')->whereRole(Role::$ADMIN)->get();
$items = User::with('roles')->whereRole(Role::$BASE_ADMIN)->get();
return $this->view('settings.administrators.index', compact('items'));
}
@@ -18,7 +18,7 @@ class AuthenticateAdmin
public function handle($request, Closure $next, $guard = null)
{
// not logged in as an admin - logout and go home
if (!user()->isAdmin()) {
if (!user()->isBaseAdmin()) {
\Auth::logout();
return redirect()->guest('/');
@@ -12,16 +12,19 @@ class Role extends TitanCMSModel
// basic website
public static $WEBSITE = 'website'; // 1
// basic admin
public static $ADMIN = 'admin'; // 2
// base user
public static $USER = 'user'; // 2
// admin + analytics
public static $ANALYTICS = 'analytics'; // 3
// basic admin
public static $BASE_ADMIN = 'base_admin'; // 3
public static $ADMIN_SUPER = 'admin_super'; // 4
public static $ADMIN_SUPER = 'admin'; // 4
public static $DEVELOPER = 'developer'; // 5
// base admin + analytics only
public static $ANALYTICS = 'analytics'; // 6
protected $table = 'roles';
protected $guarded = ['id'];
@@ -6,6 +6,16 @@
trait UserAdmin
{
/**
* If User is base admin
* On /admin login validation and all /admin navigation
* @return bool
*/
public function isBaseAdmin()
{
return $this->hasRole(Role::$BASE_ADMIN);
}
/**
* If User is admin
* @return bool
@@ -11,40 +11,50 @@ public function run()
// basic website only role
Role::create([
'icon' => 'user',
'icon' => 'desktop',
'name' => 'Website',
'slug' => '/',
'keyword' => 'website',
]);
// basic admin role
// basic user (website or/and admin or any other accounts)
Role::create([
'icon' => 'user-secret',
'name' => 'Basic Admin',
'slug' => '/admin',
'keyword' => 'admin',
'icon' => 'user',
'name' => 'Base User',
'slug' => '/',
'keyword' => 'user',
]);
// admin and analytics
// base admin role (to be able to log into /admin)
Role::create([
'icon' => 'user-circle',
'name' => 'Analytics',
'icon' => 'user-secret',
'name' => 'Basic Admin',
'slug' => '/admin',
'keyword' => 'analytics',
'keyword' => 'base_admin',
]);
// super
Role::create([
'icon' => 'user-secret',
'name' => 'Admin',
'slug' => '/admin',
'keyword' => 'admin_super',
'keyword' => 'admin',
]);
// developer
Role::create([
'icon' => 'universal-access',
'name' => 'Developer',
'slug' => '/admin',
'keyword' => 'developer',
]);
// will only be able to view /admin and /admin/analytics
Role::create([
'icon' => 'user-circle',
'name' => 'Analytics',
'slug' => '/admin',
'keyword' => 'analytics',
]);
}
}
@@ -2,6 +2,7 @@
use App\User;
use Carbon\Carbon;
use App\Models\Role;
use Illuminate\Database\Seeder;
class UserTableSeeder extends Seeder
@@ -74,13 +75,14 @@ public function run(Faker\Generator $faker)
}*/
}
/**
* Add all the roles to the user
* @param $user
*/
private function addAllRolesToUser($user)
{
$user->syncRoles([
\App\Models\Role::$WEBSITE,
\App\Models\Role::$ADMIN,
\App\Models\Role::$ADMIN_SUPER,
\App\Models\Role::$DEVELOPER,
]);
$roles = Role::all()->pluck('keyword', 'id')->values();
$user->syncRoles($roles);
}
}

0 comments on commit b4c7212

Please sign in to comment.