#71: Started adding support for a DB-based permissions cache and ability to rebuild it

This commit is contained in:
Andy Heathershaw 2018-09-14 11:02:08 +01:00
parent 56f555cda6
commit 3f55d4e0f0
5 changed files with 101 additions and 3 deletions

View File

@ -0,0 +1,42 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateAlbumPermissionsCacheTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('album_permissions_cache', function (Blueprint $table) {
$table->unsignedInteger('user_id');
$table->unsignedInteger('album_id');
$table->unsignedInteger('permission_id');
$table->foreign('user_id')
->references('id')->on('users')
->onDelete('cascade');
$table->foreign('album_id')
->references('id')->on('albums')
->onDelete('cascade');
$table->foreign('permission_id')
->references('id')->on('permissions')
->onDelete('no action');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('album_permissions_cache');
}
}

View File

@ -44,4 +44,38 @@ function AboutViewModel(urls) {
); );
} }
}; };
}
/**
* This model is used by admin/settings.blade.php.
* @constructor
*/
function SettingsViewModel(urls) {
this.el = '#settings-app';
this.data = {
is_rebuilding_permissions_cache: false
};
this.methods = {
rebuildPermissionsCache: function () {
var self = this;
$.ajax(
urls.rebuild_permissions_cache,
{
complete: function() {
self.is_rebuilding_permissions_cache = false;
},
dataType: 'json',
error: function (xhr, textStatus, errorThrown) {
},
method: 'GET',
success: function (data) {
alert('success');
}
}
);
}
};
} }

View File

@ -209,6 +209,9 @@ return [
'analytics_enable_visitor_hits' => 'Enable built-in visitor hit tracking', 'analytics_enable_visitor_hits' => 'Enable built-in visitor hit tracking',
'analytics_enable_visitor_hits_description' => 'Visitor hits to the public gallery will be recorded in the Blue Twilight database, allowing for analysis such as the most popular album/photo.', 'analytics_enable_visitor_hits_description' => 'Visitor hits to the public gallery will be recorded in the Blue Twilight database, allowing for analysis such as the most popular album/photo.',
'analytics_tab' => 'Analytics', 'analytics_tab' => 'Analytics',
'permissions_cache' => 'Permissions Cache',
'permissions_cache_intro' => 'Blue Twilight maintains the permissions each user has to albums in the database. If you feel these aren\'t correct based on what\'s configured, you can rebuild the cache by clicking the button below.',
'rebuild_permissions_cache' => 'Rebuild Permissions Cache',
'security_allow_self_registration' => 'Allow self-registration', 'security_allow_self_registration' => 'Allow self-registration',
'security_allow_self_registration_description' => 'With this option enabled, users can sign up for their own accounts. You can grant permissions to accounts to allow users to upload their own photos or manage yours.', 'security_allow_self_registration_description' => 'With this option enabled, users can sign up for their own accounts. You can grant permissions to accounts to allow users to upload their own photos or manage yours.',
'social_facebook' => 'Facebook', 'social_facebook' => 'Facebook',

View File

@ -10,7 +10,7 @@
@section('content') @section('content')
<div class="container"> <div class="container">
<div class="row"> <div class="row">
<div class="col"> <div class="col" id="settings-app">
<h1>@yield('title')</h1> <h1>@yield('title')</h1>
<p style="margin-bottom: 30px;">@lang('admin.settings_intro')</p> <p style="margin-bottom: 30px;">@lang('admin.settings_intro')</p>
@ -239,7 +239,9 @@
</label> </label>
</div> </div>
<fieldset style="margin-top: 30px;"> <hr/>
<fieldset>
<legend>@lang('admin.settings_recaptcha')</legend> <legend>@lang('admin.settings_recaptcha')</legend>
<div class="form-group"> <div class="form-group">
@ -265,7 +267,9 @@
</div> </div>
</fieldset> </fieldset>
<fieldset style="margin-top: 20px;"> <hr/>
<fieldset>
<legend>@lang('admin.settings_image_protection')</legend> <legend>@lang('admin.settings_image_protection')</legend>
<div class="form-check"> <div class="form-check">
@ -284,6 +288,14 @@
</label> </label>
</div> </div>
</fieldset> </fieldset>
<hr/>
<fieldset>
<legend>@lang('admin.settings.permissions_cache')</legend>
<p>@lang('admin.settings.permissions_cache_intro')</p>
<button class="btn btn-primary">@lang('admin.settings.rebuild_permissions_cache')</button>
</fieldset>
</div> </div>
{{-- Analytics --}} {{-- Analytics --}}
@ -479,7 +491,13 @@
@push('scripts') @push('scripts')
<script type="text/javascript"> <script type="text/javascript">
var viewModel = new SettingsViewModel({
'rebuild_permissions_cache': '{{ route('admin.rebuildPermissionsCache') }}'
});
$(document).ready(function() { $(document).ready(function() {
var app = new Vue(viewModel);
$('#test-email-button').click(function() { $('#test-email-button').click(function() {
var data = $('form').serialize(); var data = $('form').serialize();
$('#test-email-status').show(); $('#test-email-status').show();

View File

@ -21,6 +21,7 @@ Route::group(['prefix' => 'admin'], function () {
Route::get('/photo-metadata', 'Admin\DefaultController@metadataUpgrade')->name('admin.metadataUpgrade'); Route::get('/photo-metadata', 'Admin\DefaultController@metadataUpgrade')->name('admin.metadataUpgrade');
Route::post('quick-upload', 'Admin\DefaultController@quickUpload')->name('admin.quickUpload'); Route::post('quick-upload', 'Admin\DefaultController@quickUpload')->name('admin.quickUpload');
Route::post('settings/save', 'Admin\DefaultController@saveSettings')->name('admin.saveSettings'); Route::post('settings/save', 'Admin\DefaultController@saveSettings')->name('admin.saveSettings');
Route::post('settings/rebuild-permissions-cache', 'Admin\DefaultController@rebuildPermissionsCache')->name('admin.rebuildPermissionsCache');
Route::post('settings/test-email', 'Admin\DefaultController@testMailSettings')->name('admin.testMailSettings'); Route::post('settings/test-email', 'Admin\DefaultController@testMailSettings')->name('admin.testMailSettings');
Route::get('settings', 'Admin\DefaultController@settings')->name('admin.settings'); Route::get('settings', 'Admin\DefaultController@settings')->name('admin.settings');
Route::post('statistics/save', 'Admin\StatisticsController@save')->name('admin.statistics.save'); Route::post('statistics/save', 'Admin\StatisticsController@save')->name('admin.statistics.save');