diff --git a/app/Group.php b/app/Group.php new file mode 100644 index 0000000..2b60450 --- /dev/null +++ b/app/Group.php @@ -0,0 +1,17 @@ +middleware('auth'); + View::share('is_admin', true); + } + + /** + * Show the form for creating a new resource. + * + * @return \Illuminate\Http\Response + */ + public function create() + { + $this->authorize('admin-access'); + + return Theme::render('admin.create_group'); + } + + public function delete($id) + { + $this->authorize('admin-access'); + + $group = Group::where('id', intval($id))->first(); + if (is_null($group)) + { + App::abort(404); + } + + return Theme::render('admin.delete_group', ['group' => $group]); + } + + /** + * Remove the specified resource from storage. + * + * @param int $id + * @return \Illuminate\Http\Response + */ + public function destroy(Request $request, $id) + { + $this->authorize('admin-access'); + + /** @var Group $group */ + $group = Group::where('id', intval($id))->first(); + if (is_null($group)) + { + App::abort(404); + } + + try + { + $group->delete(); + $request->session()->flash('success', trans('admin.group_deletion_successful', [ + 'name' => $group->name + ])); + } + catch (\Exception $ex) + { + $request->session()->flash('error', trans('admin.group_deletion_failed', [ + 'error_message' => $ex->getMessage(), + 'name' => $group->name + ])); + } + + return redirect(route('groups.index')); + } + + /** + * Show the form for editing the specified resource. + * + * @param int $id + * @return \Illuminate\Http\Response + */ + public function edit($id) + { + $this->authorize('admin-access'); + + $group = Group::where('id', intval($id))->first(); + if (is_null($group)) + { + App::abort(404); + } + + return Theme::render('admin.edit_group', ['group' => $group]); + } + + /** + * Display a listing of the resource. + * + * @return \Illuminate\Http\Response + */ + public function index(Request $request) + { + $this->authorize('admin-access'); + + $groups = Group::orderBy('name') + ->paginate(UserConfig::get('items_per_page')); + + return Theme::render('admin.list_groups', [ + 'error' => $request->session()->get('error'), + 'groups' => $groups, + 'success' => $request->session()->get('success'), + 'warning' => $request->session()->get('warning') + ]); + } + + /** + * Store a newly created resource in storage. + * + * @param \Illuminate\Http\Request $request + * @return \Illuminate\Http\Response + */ + public function store(StoreGroupRequest $request) + { + $this->authorize('admin-access'); + + $group = new Group(); + $group->fill($request->only(['name'])); + $group->save(); + + return redirect(route('groups.index')); + } + + /** + * Update the specified resource in storage. + * + * @param \Illuminate\Http\Request $request + * @param int $id + * @return \Illuminate\Http\Response + */ + public function update(StoreGroupRequest $request, $id) + { + $this->authorize('admin-access'); + + $group = Group::where('id', intval($id))->first(); + if (is_null($group)) + { + App::abort(404); + } + + $group->fill($request->only(['name'])); + $group->save(); + + return redirect(route('groups.index')); + } +} \ No newline at end of file diff --git a/app/Http/Requests/StoreGroupRequest.php b/app/Http/Requests/StoreGroupRequest.php new file mode 100644 index 0000000..31234c5 --- /dev/null +++ b/app/Http/Requests/StoreGroupRequest.php @@ -0,0 +1,38 @@ +method()) + { + case 'POST': + return ['name' => 'required:max:255|unique:groups,name']; + + case 'PUT': + $groupId = intval($this->segment(3)); + return ['name' => 'required:max:255|unique:groups,name,' . $groupId]; + } + + return []; + } +} \ No newline at end of file diff --git a/database/migrations/2017_02_13_095245_create_groups_table.php b/database/migrations/2017_02_13_095245_create_groups_table.php new file mode 100644 index 0000000..a5268e4 --- /dev/null +++ b/database/migrations/2017_02_13_095245_create_groups_table.php @@ -0,0 +1,33 @@ +increments('id'); + $table->string('name'); + + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('groups'); + } +} diff --git a/resources/lang/en/admin.php b/resources/lang/en/admin.php index 22cfd61..51dc8ba 100644 --- a/resources/lang/en/admin.php +++ b/resources/lang/en/admin.php @@ -31,6 +31,8 @@ return [ 'create_album_intro' => 'Photo albums contain individual photographs together in the same way as a physical photo album or memory book.', 'create_album_intro2' => 'Complete the form below to create a photo album.', 'create_album_no_storage' => 'There are currently no storage locations set up. Please create a location to store your photos before creating an album.', + 'create_group' => 'Create a group', + 'create_group_intro' => 'Complete the form below to create a group in which to organise your users.', 'create_storage' => 'Create storage location', 'create_storage_intro' => 'Complete the form below to create a new storage location to hold your photos. You can then select this storage location when you create an album.', 'create_user' => 'Create user', @@ -44,6 +46,9 @@ return [ 'delete_album_warning' => 'This is a permanent action that cannot be undone!', 'delete_bulk_photos_message' => 'Are you sure you want to delete the selected photos? This action cannot be undone!', 'delete_bulk_photos_title' => 'Delete selected photos', + 'delete_group' => 'Delete group: :name', + 'delete_group_confirm' => 'Are you sure you want to permanently remove the ":name" group? Users who are members of this group may lose permissions.', + 'delete_group_warning' => 'This is a permanent action that cannot be reversed!', 'delete_photo_message' => 'Are you sure you want to delete this photo? This action cannot be undone!', 'delete_photo_successful_message' => 'The photo ":name" was deleted successfully.', 'delete_photo_title' => 'Delete photo', @@ -59,15 +64,21 @@ return [ 'edit_album_action' => 'Edit album details', 'edit_album_intro' => 'Photo albums contain individual photographs in the same way as a physical photo album or memory book.', 'edit_album_intro2' => 'Complete the form below to edit the properties of the album: :album_name.', + 'edit_group_intro' => 'You can use the form below to edit the above group. Changes take effect immediately.', + 'edit_group_title' => 'Edit group: :group_name', 'edit_storage' => 'Edit storage location: :storage_name', 'edit_storage_intro' => 'Use the form below to update the details of the :storage_name storage location.', 'edit_user_intro' => 'You can use the form below to edit the above user account. Changes take effect immediately.', 'edit_user_title' => 'Edit user account: :name', + 'group_deletion_failed' => 'An error occurred while removing the ":name" group: :error_message', + 'group_deletion_successful' => 'The ":name" group was removed successfully.', 'inactive_storage_legend' => 'Inactive storage location that cannot be used for new albums.', 'is_uploading' => 'Uploading in progress...', 'legend' => 'Legend/Key', 'list_albums_intro' => 'Albums contain collections of individual photographs in the same way as a physical photo album or memory book.', 'list_albums_title' => 'Albums', + 'list_groups_intro' => 'Organise your users into categories or types by using groups. You can assign permissions on albums to groups of users to make administration and management easier.', + 'list_groups_title' => 'Groups', 'list_storages_intro' => 'Storage locations specify the physical location where your photograph files are held. This may be on your local server\'s filesystem, or on a cloud storage provider such as Rackspace or Amazon S3.', 'list_storages_title' => 'Storage Locations', 'list_users_intro' => 'User accounts allow people to login to your gallery to manage your albums. If you have disabled self-registration, you can create user accounts here to allow people to login.', @@ -79,6 +90,8 @@ return [ 'move_successful_message' => 'The photo ":name" was moved successfully to the ":album" album.', 'no_albums_text' => 'You have no photo albums yet. Click the button below to create one.', 'no_albums_title' => 'No Photo Albums', + 'no_groups_text' => 'You have no groups yet. Click the button below to create one.', + 'no_groups_title' => 'No Groups', 'no_photo_selected_message' => 'Please select at least one photo.', 'no_storages_text' => 'You need a storage location to store your uploaded photographs.', 'no_storages_text2' => 'This can be on your server\'s local filesystem or a cloud location such as Amazon S3 or Rackspace.', diff --git a/resources/lang/en/navigation.php b/resources/lang/en/navigation.php index e26b179..4a1ff51 100644 --- a/resources/lang/en/navigation.php +++ b/resources/lang/en/navigation.php @@ -4,12 +4,15 @@ return [ 'admin' => 'Admin', 'albums' => 'Albums', 'create_album' => 'Create album', + 'create_group' => 'Create group', 'create_storage' => 'Create storage', 'create_user' => 'Create user', 'delete_album' => 'Delete album', + 'delete_group' => 'Delete group', 'delete_storage' => 'Delete storage location', 'delete_user' => 'Delete user', 'edit_album' => 'Edit album', + 'edit_group' => 'Edit group', 'edit_storage' => 'Edit storage location', 'edit_user' => 'Edit user', 'groups' => 'Groups', diff --git a/resources/views/themes/base/admin/create_group.blade.php b/resources/views/themes/base/admin/create_group.blade.php new file mode 100644 index 0000000..40bcc79 --- /dev/null +++ b/resources/views/themes/base/admin/create_group.blade.php @@ -0,0 +1,49 @@ +@extends('themes.base.layout') +@section('title', trans('admin.create_group')) + +@section('breadcrumb') + +@endsection + +@section('content') +
+
+
+

@yield('title')

+

@lang('admin.create_group_intro')

+
+ + {!! Form::open(['route' => 'groups.store', 'method' => 'POST']) !!} +
+
+
+ {!! Form::label('name', trans('forms.name_label'), ['class' => 'control-label']) !!} + {!! Form::text('name', old('name'), ['class' => 'form-control']) !!} + + @if ($errors->has('name')) + + {{ $errors->first('name') }} + + @endif +
+ +
+ @lang('forms.cancel_action') + {!! Form::submit(trans('forms.create_action'), ['class' => 'btn btn-success']) !!} +
+
+
+ {!! Form::close() !!} +
+
+
+@endsection \ No newline at end of file diff --git a/resources/views/themes/base/admin/delete_group.blade.php b/resources/views/themes/base/admin/delete_group.blade.php new file mode 100644 index 0000000..6e08bf5 --- /dev/null +++ b/resources/views/themes/base/admin/delete_group.blade.php @@ -0,0 +1,35 @@ +@extends('themes.base.layout') +@section('title', trans('admin.delete_group', ['name' => $group->name])) + +@section('breadcrumb') + +@endsection + +@section('content') +
+
+
+

@yield('title')

+

@lang('admin.delete_group_confirm', ['name' => $group->name])

+
+ @lang('admin.delete_group_warning') +
+
+ {!! Form::open(['route' => ['groups.destroy', $group->id], 'method' => 'DELETE']) !!} + @lang('forms.cancel_action') + {!! Form::submit(trans('forms.delete_action'), ['class' => 'btn btn-danger']) !!} + {!! Form::close() !!} +
+
+
+
+@endsection \ No newline at end of file diff --git a/resources/views/themes/base/admin/edit_group.blade.php b/resources/views/themes/base/admin/edit_group.blade.php new file mode 100644 index 0000000..9543fb8 --- /dev/null +++ b/resources/views/themes/base/admin/edit_group.blade.php @@ -0,0 +1,49 @@ +@extends('themes.base.layout') +@section('title', trans('admin.edit_group_title', ['group_name' => $group->name])) + +@section('breadcrumb') + +@endsection + +@section('content') +
+
+
+

@yield('title')

+

@lang('admin.edit_group_intro')

+
+ + {!! Form::model($group, ['route' => ['groups.update', $group->id], 'method' => 'PUT']) !!} +
+
+
+ {!! Form::label('name', trans('forms.name_label'), ['class' => 'control-label']) !!} + {!! Form::text('name', old('name'), ['class' => 'form-control']) !!} + + @if ($errors->has('name')) + + {{ $errors->first('name') }} + + @endif +
+ +
+ @lang('forms.cancel_action') + {!! Form::submit(trans('forms.save_action'), ['class' => 'btn btn-success']) !!} +
+
+
+ {!! Form::close() !!} +
+
+
+@endsection \ No newline at end of file diff --git a/resources/views/themes/base/admin/list_groups.blade.php b/resources/views/themes/base/admin/list_groups.blade.php new file mode 100644 index 0000000..6f5cb45 --- /dev/null +++ b/resources/views/themes/base/admin/list_groups.blade.php @@ -0,0 +1,61 @@ +@extends('themes.base.layout') +@section('title', trans('admin.list_groups_title')) + +@section('breadcrumb') + +@endsection + +@section('content') +
+
+
+

@yield('title')

+
+

@lang('admin.list_groups_intro')

+
+ + @if (count($groups) == 0) +
+

@lang('admin.no_groups_title')

+

@lang('admin.no_groups_text')

+

+ @lang('admin.create_group') +

+
+ @else + + + @foreach ($groups as $group) + + + + + @endforeach + +
+ {{ $group->name }} + + @lang('forms.edit_action') + @lang('forms.delete_action') +
+ +
+ {{ $groups->links() }} +
+ + + @endif +
+
+
+@endsection \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 4a5fb05..4cb2c30 100644 --- a/routes/web.php +++ b/routes/web.php @@ -62,6 +62,7 @@ Route::group(['prefix' => 'admin'], function () { Route::resource('users', 'Admin\UserController'); // Group management + Route::get('groups/{id}/delete', 'Admin\GroupController@delete')->name('groups.delete'); Route::resource('groups', 'Admin\GroupController'); });