/** * Assigns a role to a user for all apps in the system. * * @param $user * @param $defaultRole * * @return bool * @throws \Exception */ public static function applyDefaultUserAppRole($user, $defaultRole) { $apps = App::all(); if (count($apps) === 0) { return false; } foreach ($apps as $app) { if (!UserAppRole::whereUserId($user->id)->whereAppId($app->id)->exists()) { $userAppRoleData = ['user_id' => $user->id, 'app_id' => $app->id, 'role_id' => $defaultRole]; UserAppRole::create($userAppRoleData); } } return true; }
public function index() { $uri = static::getURI($_SERVER); $dist = env('DF_INSTALL', ''); if (empty($dist) && false !== stripos(env('DB_DATABASE', ''), 'bitnami')) { $dist = 'Bitnami'; } $appCount = App::all()->count(); $adminCount = User::whereIsSysAdmin(1)->count(); $userCount = User::whereIsSysAdmin(0)->count(); $serviceCount = Service::all()->count(); $roleCount = Role::all()->count(); $status = ["uri" => $uri, "managed" => env('DF_MANAGED', false), "dist" => $dist, "demo" => Environment::isDemoApplication(), "version" => \Config::get('df.version'), "host_os" => PHP_OS, "resources" => ["app" => $appCount, "admin" => $adminCount, "user" => $userCount, "service" => $serviceCount, "role" => $roleCount]]; return ResponseFactory::sendResponse(ResponseFactory::create($status)); }