#71: Albums edit page now shows if an album is inheriting permissions, and this can be changed on edit album screen

This commit is contained in:
Andy Heathershaw 2018-09-16 09:12:35 +01:00
parent 90e9061ebc
commit 9ad52359df
8 changed files with 157 additions and 79 deletions

View File

@ -21,7 +21,7 @@ class Album extends Model
* @var array * @var array
*/ */
protected $fillable = [ protected $fillable = [
'name', 'description', 'url_alias', 'user_id', 'storage_id', 'default_view', 'parent_album_id', 'url_path' 'name', 'description', 'url_alias', 'user_id', 'storage_id', 'default_view', 'parent_album_id', 'url_path', 'is_permissions_inherited'
]; ];
/** /**

View File

@ -164,6 +164,7 @@ class AlbumController extends Controller
$albumService = new AlbumService(); $albumService = new AlbumService();
return Theme::render('admin.edit_album', [ return Theme::render('admin.edit_album', [
'active_tab' => $request->get('tab'),
'album' => $album, 'album' => $album,
'parent_albums' => $albumService->getFlattenedAlbumTree() 'parent_albums' => $albumService->getFlattenedAlbumTree()
]); ]);
@ -512,6 +513,7 @@ class AlbumController extends Controller
$currentParentID = $album->parent_album_id; $currentParentID = $album->parent_album_id;
$album->fill($request->only(['name', 'description', 'parent_album_id'])); $album->fill($request->only(['name', 'description', 'parent_album_id']));
$album->is_permissions_inherited = $request->has('is_permissions_inherited');
if (strlen($album->parent_album_id) == 0) if (strlen($album->parent_album_id) == 0)
{ {

View File

@ -0,0 +1,34 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateAlbumInheritPermissionsColumn extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('albums', function (Blueprint $table)
{
$table->boolean('is_permissions_inherited')->default(false);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('albums', function (Blueprint $table)
{
$table->dropColumn('is_permissions_inherited');
});
}
}

View File

@ -46,6 +46,24 @@ function AboutViewModel(urls) {
}; };
} }
/**
* This model is used by admin/edit_album.blade.php.
* @constructor
*/
function EditAlbumViewModel() {
this.el = '#edit-album-app';
this.data = {
parent_id: ''
};
this.computed = {
isParentAlbum: function() {
return this.parent_id == '';
}
}
}
/** /**
* This model is used by admin/settings.blade.php. * This model is used by admin/settings.blade.php.
* @constructor * @constructor

View File

@ -32,6 +32,8 @@ return [
'album_cameras_heading' => 'Cameras used in this album', 'album_cameras_heading' => 'Cameras used in this album',
'album_cameras_tab' => 'Cameras', 'album_cameras_tab' => 'Cameras',
'album_cameras_text' => 'Blue Twilight analyses the Exif data in your photos to determine which cameras have been used. The cameras that were found are displayed below.', 'album_cameras_text' => 'Blue Twilight analyses the Exif data in your photos to determine which cameras have been used. The cameras that were found are displayed below.',
'album_inheriting_permissions_p1' => 'Permissions inherited from parent album',
'album_inheriting_permissions_p2' => 'This album is inheriting permissions from its parent album. You can change the permissions applied to this album from the :l_parent_startparent album\'s permissions tab:l_parent_end. ',
'album_no_cameras_found_p1' => 'No cameras were found', 'album_no_cameras_found_p1' => 'No cameras were found',
'album_no_cameras_found_p2' => 'Upload more photos to this album or ensure the cameras you use support Exif image tagging.', 'album_no_cameras_found_p2' => 'Upload more photos to this album or ensure the cameras you use support Exif image tagging.',
'album_no_photos_p1' => 'No photos in this album', 'album_no_photos_p1' => 'No photos in this album',

View File

@ -26,6 +26,7 @@ return [
'edit_action' => 'Edit', 'edit_action' => 'Edit',
'email_label' => 'E-mail address:', 'email_label' => 'E-mail address:',
'enable_profile_page_label' => 'Allow others to see my profile page', 'enable_profile_page_label' => 'Allow others to see my profile page',
'inherit_album_permissions' => 'Inherit permissions from parent album',
'labels_label' => 'Labels:', 'labels_label' => 'Labels:',
'login_action' => 'Login', 'login_action' => 'Login',
'name_label' => 'Name:', 'name_label' => 'Name:',

View File

@ -10,7 +10,7 @@
@endsection @endsection
@section('content') @section('content')
<div class="container"> <div class="container" id="edit-album-app">
<div class="row"> <div class="row">
<div class="col"> <div class="col">
<h1>@lang('admin.edit_album', ['album_name' => $album->name])</h1> <h1>@lang('admin.edit_album', ['album_name' => $album->name])</h1>
@ -46,14 +46,23 @@
<div class="form-group"> <div class="form-group">
<label class="form-control-label" for="parent-album">@lang('forms.parent_album_label')</label> <label class="form-control-label" for="parent-album">@lang('forms.parent_album_label')</label>
<select class="form-control" name="parent_album_id" id="parent-album"> <select class="form-control" name="parent_album_id" id="parent-album" v-model="parent_id">
<option value="">@lang('forms.parent_album_placeholder')</option> <option value="">@lang('forms.parent_album_placeholder')</option>
@foreach ($parent_albums as $key => $value) @foreach ($parent_albums as $key => $value)
<option value="{{ $key }}"{{ $key == $album->id || $value->isChildOf($album) ? ' disabled="disabled"' : '' }}{{ $key == old('parent_album_id') ? ' selected="selected"' : '' }}>{{ $value->display_name }}{{ $key == old('parent_album_id') ? ' ' . trans('forms.select_current_text') : '' }}</option> <option value="{{ $key }}"{{ $key == $album->id || $value->isChildOf($album) ? ' disabled="disabled"' : '' }}>{{ $value->display_name }}{{ $key == old('parent_album_id') ? ' ' . trans('forms.select_current_text') : '' }}</option>
@endforeach @endforeach
</select> </select>
</div> </div>
<div class="form-group" v-if="!isParentAlbum">
<div class="mt-3 form-check">
<input type="checkbox" class="form-check-input" id="inherit-permissions" name="is_permissions_inherited"{{ $album->is_permissions_inherited ? ' checked="checked"' : '' }}>
<label class="form-check-label" for="inherit-permissions">
<strong>@lang('forms.inherit_album_permissions')</strong>
</label>
</div>
</div>
<div id="change-parent-warning" class="alert alert-warning" style="display: none;"> <div id="change-parent-warning" class="alert alert-warning" style="display: none;">
@lang('admin.edit_album_change_parent_warning') @lang('admin.edit_album_change_parent_warning')
@ -77,7 +86,12 @@
@push('scripts') @push('scripts')
<script type="text/javascript"> <script type="text/javascript">
var editAlbumViewModel = new EditAlbumViewModel();
editAlbumViewModel.data.parent_id = '{{ old('parent_album_id', $album->parent_album_id) }}';
$(document).ready(function() { $(document).ready(function() {
var app = new Vue(editAlbumViewModel);
// Show the change parent warning // Show the change parent warning
var current_parent_id = '{{ $album->parent_album_id }}'; var current_parent_id = '{{ $album->parent_album_id }}';
$('#parent-album').change(function() { $('#parent-album').change(function() {

View File

@ -3,87 +3,94 @@
<p>@lang('admin.security_text')</p> <p>@lang('admin.security_text')</p>
<hr/> <hr/>
<h5 style="font-weight: bold;">@lang('admin.security_groups_heading')</h5> @if ($album->is_permissions_inherited)
<div class="text-center mt-4">
<h4 class="text-success"><b>@lang('admin.album_inheriting_permissions_p1')</b></h4>
<p class="mb-0">@lang('admin.album_inheriting_permissions_p2', ['l_parent_start' => '<a href="' . route('albums.show', [$album->parent_album_id]) . '?tab=permissions">', 'l_parent_end' => '</a>'])</p>
</div>
@else
<h5 style="font-weight: bold;">@lang('admin.security_groups_heading')</h5>
<form action="{{ route('albums.set_group_permissions', ['id' => $album->id]) }}" method="post"> <form action="{{ route('albums.set_group_permissions', ['id' => $album->id]) }}" method="post">
{{ csrf_field() }} {{ csrf_field() }}
@if (count($existing_groups) > 0) @if (count($existing_groups) > 0)
<div id="groups-accordion" role="tablist" aria-multiselectable="true"> <div id="groups-accordion" role="tablist" aria-multiselectable="true">
@foreach ($existing_groups as $group) @foreach ($existing_groups as $group)
@include(Theme::viewName('partials.album_permissions'), [
'key_id' => 'group_' . $group->id,
'object_id' => $group->id,
'title' => $group->name,
'callback' => [$album, 'doesGroupHavePermission'],
'callback_object' => $group,
'parent_id' => 'groups-accordion'
])
@endforeach
</div>
@endif
<div class="row mt-3">
<div class="col-md-4">
<select class="form-control" name="group_id" style="margin-bottom: 2px;"@if (count($add_new_groups) == 0) disabled="disabled"@endif>
@foreach ($add_new_groups as $group)
<option value="{{ $group->id }}">{{ $group->name }}</option>
@endforeach
</select>
</div>
<div class="col-md-2">
<button type="submit" name="action" value="add_group" class="btn btn-primary">Assign Permissions</button>
</div>
<div class="col-md-6 text-right">
<button type="submit" name="action" value="update_group_permissions" class="btn btn-success">
<i class="fa fa-fw fa-check"></i> @lang('forms.save_action')
</button>
</div>
</div>
</form>
<hr/>
<h5 style="font-weight: bold;">@lang('admin.security_users_heading')</h5>
<form action="{{ route('albums.set_user_permissions', ['id' => $album->id]) }}" method="post">
{{ csrf_field() }}
<div id="users-accordion" role="tablist" aria-multiselectable="true">
{{-- Anonymous users --}}
@include(Theme::viewName('partials.album_permissions'), [
'key_id' => 'anonymous',
'object_id' => 'anonymous',
'title' => trans('admin.anonymous_users'),
'callback' => [$album, 'doesUserHavePermission'],
'callback_object' => null,
'parent_id' => 'users-accordion'
])
@foreach ($existing_users as $user)
@include(Theme::viewName('partials.album_permissions'), [ @include(Theme::viewName('partials.album_permissions'), [
'key_id' => 'group_' . $group->id, 'key_id' => 'user_' . $user->id,
'object_id' => $group->id, 'object_id' => $user->id,
'title' => $group->name, 'title' => $user->name,
'callback' => [$album, 'doesGroupHavePermission'], 'callback' => [$album, 'doesUserHavePermission'],
'callback_object' => $group, 'callback_object' => $user,
'parent_id' => 'groups-accordion' 'parent_id' => 'users-accordion'
]) ])
@endforeach @endforeach
</div> </div>
@endif
<div class="row mt-3"> <div class="row mt-3">
<div class="col-md-4"> <div class="col-md-4">
<select class="form-control" name="group_id" style="margin-bottom: 2px;"@if (count($add_new_groups) == 0) disabled="disabled"@endif> <input class="form-control" name="user_name" id="user-search-textbox" size="20" style="margin-bottom: 2px;" />
@foreach ($add_new_groups as $group) <input type="hidden" name="user_id" id="user-id-field" />
<option value="{{ $group->id }}">{{ $group->name }}</option> </div>
@endforeach <div class="col-md-2">
</select> <button type="submit" name="action" value="add_user" class="btn btn-primary">Assign Permissions</button>
</div>
<div class="col-md-6 text-right">
<button type="submit" name="action" value="update_user_permissions" class="btn btn-success">
<i class="fa fa-fw fa-check"></i> @lang('forms.save_action')
</button>
</div>
</div> </div>
<div class="col-md-2"> </form>
<button type="submit" name="action" value="add_group" class="btn btn-primary">Assign Permissions</button> @endif
</div>
<div class="col-md-6 text-right">
<button type="submit" name="action" value="update_group_permissions" class="btn btn-success">
<i class="fa fa-fw fa-check"></i> @lang('forms.save_action')
</button>
</div>
</div>
</form>
<hr/>
<h5 style="font-weight: bold;">@lang('admin.security_users_heading')</h5>
<form action="{{ route('albums.set_user_permissions', ['id' => $album->id]) }}" method="post">
{{ csrf_field() }}
<div id="users-accordion" role="tablist" aria-multiselectable="true">
{{-- Anonymous users --}}
@include(Theme::viewName('partials.album_permissions'), [
'key_id' => 'anonymous',
'object_id' => 'anonymous',
'title' => trans('admin.anonymous_users'),
'callback' => [$album, 'doesUserHavePermission'],
'callback_object' => null,
'parent_id' => 'users-accordion'
])
@foreach ($existing_users as $user)
@include(Theme::viewName('partials.album_permissions'), [
'key_id' => 'user_' . $user->id,
'object_id' => $user->id,
'title' => $user->name,
'callback' => [$album, 'doesUserHavePermission'],
'callback_object' => $user,
'parent_id' => 'users-accordion'
])
@endforeach
</div>
<div class="row mt-3">
<div class="col-md-4">
<input class="form-control" name="user_name" id="user-search-textbox" size="20" style="margin-bottom: 2px;" />
<input type="hidden" name="user_id" id="user-id-field" />
</div>
<div class="col-md-2">
<button type="submit" name="action" value="add_user" class="btn btn-primary">Assign Permissions</button>
</div>
<div class="col-md-6 text-right">
<button type="submit" name="action" value="update_user_permissions" class="btn btn-success">
<i class="fa fa-fw fa-check"></i> @lang('forms.save_action')
</button>
</div>
</div>
</form>
</div> </div>