diff --git a/app/assets/sass/partials/_content.scss b/app/assets/sass/partials/_content.scss index a94fee8b..87412d08 100644 --- a/app/assets/sass/partials/_content.scss +++ b/app/assets/sass/partials/_content.scss @@ -59,5 +59,24 @@ body.dashboard { padding: 8px 0; } } + + .user-grid { + .user { + img { + border-radius: 5px; + margin-bottom: 15px; + border: 0; + } + + .name { + font-weight: 600; + } + + .email { + color: #444; + margin-top: 4px; + } + } + } } } diff --git a/app/lang/en/cachet.php b/app/lang/en/cachet.php index 49bf6a0e..6e4e81ab 100644 --- a/app/lang/en/cachet.php +++ b/app/lang/en/cachet.php @@ -49,6 +49,8 @@ return [ 'metrics-add' => 'Add Metric Point', 'status_page' => 'Status Page', 'settings' => 'Settings', + 'team' => 'Team Members', + 'team-add' => 'Add Team Member', 'notifications' => 'Notifications', 'toggle_navigation' => 'Toggle Navigation', 'search' => 'Search...', diff --git a/app/routes/dashboard.php b/app/routes/dashboard.php index 2974c015..71ac5f62 100644 --- a/app/routes/dashboard.php +++ b/app/routes/dashboard.php @@ -28,6 +28,13 @@ Route::group(['before' => 'auth', 'prefix' => 'dashboard', 'namespace' => 'Cache // Notifications Route::get('notifications', ['as' => 'dashboard.notifications', 'uses' => 'DashboardController@showNotifications']); + // Team Members + Route::get('team', ['as' => 'dashboard.team', 'uses' => 'DashboardController@showTeamView']); + Route::get('team/add', ['as' => 'dashboard.team.add', 'uses' => 'DashboardController@showAddTeamMemberView']); + Route::get('team/{user}', 'DashboardController@showTeamMemberView'); + Route::post('team/add', 'DashboardController@postAddUser'); + Route::post('team/{user}', 'DashboardController@postUpdateUser'); + // Settings Route::get('settings/setup', ['as' => 'dashboard.settings.setup', 'uses' => 'DashSettingsController@showSetupView']); Route::get('settings/security', ['as' => 'dashboard.settings.security', 'uses' => 'DashSettingsController@showSecurityView']); @@ -37,7 +44,7 @@ Route::group(['before' => 'auth', 'prefix' => 'dashboard', 'namespace' => 'Cache // User Settings Route::get('user', ['as' => 'dashboard.user', 'uses' => 'DashUserController@showUser']); - Route::get('/user/{user}/api/regen', 'DashUserController@regenerateApiKey'); + Route::get('user/{user}/api/regen', 'DashUserController@regenerateApiKey'); Route::post('user', 'DashUserController@postUser'); // Internal API. diff --git a/app/views/dashboard/team/edit.blade.php b/app/views/dashboard/team/edit.blade.php new file mode 100644 index 00000000..086db972 --- /dev/null +++ b/app/views/dashboard/team/edit.blade.php @@ -0,0 +1,46 @@ +@extends('layout.dashboard') + +@section('content') +
+ + {{ trans('cachet.dashboard.user') }} + +
+
+
+
+ @if($updated = Session::get('updated')) +
+ @if($updated) + Awesome. Profile updated. + @else + Whoops. Something went wrong when updating. + @endif +
+ @endif + +
+
+
+ + +
+
+ + +
+
+ + +
+
+ + + @if(Auth::user()->isAdmin) + Revoke API Key + @endif +
+
+
+
+@stop diff --git a/app/views/dashboard/team/index.blade.php b/app/views/dashboard/team/index.blade.php new file mode 100644 index 00000000..73dfd121 --- /dev/null +++ b/app/views/dashboard/team/index.blade.php @@ -0,0 +1,32 @@ +@extends('layout.dashboard') + +@section('content') +
+ + {{ trans('cachet.dashboard.team') }} + + + {{ trans('cachet.dashboard.team-add') }} + +
+
+
+
+
+

Team Members will be able to add, modify & edit components and incidents.

+ +
+ @foreach($teamMembers as $member) +
+ + + +
{{ $member->username }}
+ +
+ @endforeach +
+
+
+
+@stop diff --git a/app/views/dashboard/team/new.blade.php b/app/views/dashboard/team/new.blade.php new file mode 100644 index 00000000..359e20d8 --- /dev/null +++ b/app/views/dashboard/team/new.blade.php @@ -0,0 +1,43 @@ +@extends('layout.dashboard') + +@section('content') +
+ + {{ trans('cachet.dashboard.user') }} + +
+
+
+
+ @if($created = Session::get('created')) +
+ Awesome. New user has been created. +
+ @elseif($errors = Session::get('errors')) +
+ Whoops. Something went wrong: {{ $errors }} +
+ @endif + +
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+
+@stop diff --git a/app/views/partials/dashboard/sidebar.blade.php b/app/views/partials/dashboard/sidebar.blade.php index de4b2f1c..042b5809 100644 --- a/app/views/partials/dashboard/sidebar.blade.php +++ b/app/views/partials/dashboard/sidebar.blade.php @@ -48,6 +48,11 @@ {{ trans('cachet.dashboard.components') }} +
  • + + {{ trans('cachet.dashboard.team') }} + +
  • {{--
  • {{ trans('cachet.dashboard.metrics') }} diff --git a/src/Http/Controllers/DashboardController.php b/src/Http/Controllers/DashboardController.php index 488a21a3..338ab88a 100644 --- a/src/Http/Controllers/DashboardController.php +++ b/src/Http/Controllers/DashboardController.php @@ -3,7 +3,10 @@ namespace CachetHQ\Cachet\Http\Controllers; use CachetHQ\Cachet\Models\Component; +use CachetHQ\Cachet\Models\User; +use GrahamCampbell\Binput\Facades\Binput; use Illuminate\Routing\Controller; +use Illuminate\Support\Facades\Redirect; use Illuminate\Support\Facades\View; class DashboardController extends Controller @@ -23,6 +26,80 @@ class DashboardController extends Controller ]); } + /** + * Shows the team members view. + * + * @return \Illuminate\View\View + */ + public function showTeamView() + { + $team = User::all(); + + return View::make('dashboard.team.index')->with([ + 'pageTitle' => 'Team Members - Dashboard', + 'teamMembers' => $team, + ]); + } + + /** + * Shows the edit team member view. + * + * @return \Illuminate\View\View + */ + public function showTeamMemberView(User $user) + { + return View::make('dashboard.team.edit')->with([ + 'pageTitle' => 'Edit User - Dashboard', + 'user' => $user, + ]); + } + + /** + * Shows the add team member view. + * + * @return \Illuminate\View\View + */ + public function showAddTeamMemberView() + { + return View::make('dashboard.team.new')->with([ + 'pageTitle' => 'Add User - Dashboard', + ]); + } + + /** + * Creates a new team member. + * + * @return \Illuminate\Http\RedirectResponse + */ + public function postAddUser() + { + $user = User::create(Binput::all()); + + if ($user->isValid()) { + return Redirect::back()->with('created', $user->isValid()); + } else { + return Redirect::back() + ->withInput(Binput::except('password')) + ->with('errors', $user->getErrors()); + } + } + + /** + * Updates a user. + * + * @param \CachetHQ\Cachet\Models\User $user + * + * @return \Illuminate\View\View + */ + public function postUpdateUser(User $user) + { + $items = Binput::all(); + + $updated = $user->update($items); + + return Redirect::back()->with('updated', $updated); + } + /** * Shows the metrics view. * diff --git a/src/Models/User.php b/src/Models/User.php index fb2e86ff..59917a8d 100644 --- a/src/Models/User.php +++ b/src/Models/User.php @@ -9,6 +9,7 @@ use Illuminate\Auth\UserTrait; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Support\Facades\Hash; +use Watson\Validating\ValidatingTrait; /** * @property int $id @@ -23,7 +24,18 @@ use Illuminate\Support\Facades\Hash; */ class User extends Model implements UserInterface, RemindableInterface { - use UserTrait, RemindableTrait; + use RemindableTrait, UserTrait, ValidatingTrait; + + /** + * The validation rules. + * + * @var string[] + */ + protected $rules = [ + 'username' => 'required|alpha|unique:users', + 'email' => 'required|email|unique:users', + 'password' => 'required', + ]; /** * The hidden properties. @@ -37,7 +49,7 @@ class User extends Model implements UserInterface, RemindableInterface /** * The properties that cannot be mass assigned. * - * @var array + * @var string[] */ protected $guarded = []; @@ -111,4 +123,14 @@ class User extends Model implements UserInterface, RemindableInterface { return str_random(20); } + + /** + * Returns whether a user is at admin level. + * + * @return bool + */ + public function getIsAdminAttribute() + { + return (bool) $this->level; + } }