Skip to content

Commit

Permalink
Merge pull request #60 from THM-Health/55-management-of-application-s…
Browse files Browse the repository at this point in the history
…ettings

55 management of application settings
  • Loading branch information
dsst95 authored Dec 1, 2020
2 parents aad604c + 7f6c4b6 commit b93cf5b
Show file tree
Hide file tree
Showing 31 changed files with 1,549 additions and 40 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ MIX_WELCOME_MESSAGE_LIMIT=500
MIX_ROOM_NAME_LIMIT=50

DEFAULT_LOGO=/images/logo.svg
DEFAULT_FAVICON=/images/favicon.ico
DEFAULT_ROOM_LIMIT=-1
DEFAULT_PAGINATION_PAGE_SIZE=15
OWN_ROOMS_PAGINATION_PAGE_SIZE=5
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added setting menu for administrators ([#35], [#38])
- Added a middleware to check whether the request is in sync with model of the database and not stale ([#40], [#41])
- Added management of users and profile page ([#10], [#66])
- Added management of application settings ([#55], [#60])

[#1]: https://github.com/THM-Health/PILOS/issues/1
[#3]: https://github.com/THM-Health/PILOS/pull/3
Expand Down Expand Up @@ -56,6 +57,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#49]: https://github.com/THM-Health/PILOS/pull/49
[#50]: https://github.com/THM-Health/PILOS/issues/50
[#54]: https://github.com/THM-Health/PILOS/pull/54
[#55]: https://github.com/THM-Health/PILOS/issues/55
[#60]: https://github.com/THM-Health/PILOS/pull/60
[#66]: https://github.com/THM-Health/PILOS/pull/66


[unreleased]: https://github.com/THM-Health/PILOS/compare/3c8359cdb0395546fe97aeabf1a40f93002b182c...HEAD
52 changes: 39 additions & 13 deletions app/Http/Controllers/api/v1/ApplicationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,55 @@
namespace App\Http\Controllers\api\v1;

use App\Http\Controllers\Controller;
use App\Http\Requests\UpdateSetting;
use App\Http\Resources\ApplicationSettings;
use App\Http\Resources\User as UserResource;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Storage;

class ApplicationController extends Controller
{
/**
* Load basic application data, like settings
* @return \Illuminate\Http\JsonResponse
* @return ApplicationSettings
*/
public function settings()
{
return response()->json(['data' => [
'logo' => setting('logo'),
'room_limit' => setting('room_limit'),
'pagination_page_size' => setting('pagination_page_size'),
'bbb' => [
'file_mimes' => config('bigbluebutton.allowed_file_mimes'),
'max_filesize' => config('bigbluebutton.max_filesize'),
'room_name_limit' => config('bigbluebutton.room_name_limit'),
'welcome_message_limit' => config('bigbluebutton.welcome_message_limit')
]
]
]);
return new ApplicationSettings();
}

/**
* Update application settings data
* @param UpdateSetting $request
* @return ApplicationSettings
*/
public function updateSettings(UpdateSetting $request)
{
if ($request->has('logo_file')) {
$path = $request->file('logo_file')->store('images', 'public');
$url = Storage::url($path);
$logo = $url;
} else {
$logo = $request->logo;
}

if ($request->has('favicon_file')) {
$path = $request->file('favicon_file')->store('images', 'public');
$url = Storage::url($path);
$favicon = $url;
} else {
$favicon = $request->favicon;
}

setting()->set('logo', $logo);
setting()->set('favicon', $favicon);
setting()->set('name', $request->name);
setting()->set('room_limit', $request->room_limit);
setting()->set('own_rooms_pagination_page_size', $request->own_rooms_pagination_page_size);
setting()->set('pagination_page_size', $request->pagination_page_size);
setting()->save();

return new ApplicationSettings();
}

/**
Expand Down
27 changes: 27 additions & 0 deletions app/Http/Requests/UpdateSetting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class UpdateSetting extends FormRequest
{
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'name' => 'required|string|max:255',
'room_limit' => 'required|numeric|min:-1|max:100',
'logo' => 'required_without:logo_file|string|max:255',
'logo_file' => 'required_without:logo|image|max:500', // 500 KB, larger files are bad for loading times
'favicon' => 'required_without:favicon_file|string|max:255',
'favicon_file' => 'required_without:favicon|mimes:ico|max:500', // 500 KB, larger files are bad for loading times
'own_rooms_pagination_page_size' => 'required|numeric|min:1|max:25',
'pagination_page_size' => 'required|numeric|min:1|max:100'
];
}
}
35 changes: 35 additions & 0 deletions app/Http/Resources/ApplicationSettings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class ApplicationSettings extends JsonResource
{
public function __construct()
{
parent::__construct(null);
}

/**
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'name' => setting('name'),
'logo' => setting('logo'),
'favicon' => setting('favicon'),
'room_limit' => intval(setting('room_limit')),
'pagination_page_size' => intval(setting('pagination_page_size')),
'own_rooms_pagination_page_size' => intval(setting('own_rooms_pagination_page_size')),
'bbb' => [
'file_mimes' => config('bigbluebutton.allowed_file_mimes'),
'max_filesize' => intval(config('bigbluebutton.max_filesize')),
'room_name_limit' => intval(config('bigbluebutton.room_name_limit')),
'welcome_message_limit' => intval(config('bigbluebutton.welcome_message_limit'))
]
];
}
}
2 changes: 2 additions & 0 deletions config/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@
|
*/
'defaults' => [
'name' => env('APP_NAME', 'PILOS'),
'logo' => env('DEFAULT_LOGO', '/images/logo.svg'),
'favicon' => env('DEFAULT_FAVICON', '/images/favicon.ico'),
'room_limit' => env('DEFAULT_ROOM_LIMIT',-1),
'own_rooms_pagination_page_size' => env('OWN_ROOMS_PAGINATION_PAGE_SIZE',5),
'pagination_page_size' => env('DEFAULT_PAGINATION_PAGE_SIZE', 15),
Expand Down
10 changes: 9 additions & 1 deletion database/seeds/RolesAndPermissionsSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,28 @@ public function run()

$adminPermissions[] = Permission::firstOrCreate([ 'name' => 'rooms.create' ])->id;
$adminPermissions[] = Permission::firstOrCreate([ 'name' => 'rooms.delete' ])->id;

$adminPermissions[] = Permission::firstOrCreate([ 'name' => 'settings.manage' ])->id;
$adminPermissions[] = Permission::firstOrCreate([ 'name' => 'settings.viewAny' ])->id;
$adminPermissions[] = Permission::firstOrCreate([ 'name' => 'settings.update' ])->id;

$adminPermissions[] = Permission::firstOrCreate([ 'name' => 'roles.viewAny' ])->id;
$adminPermissions[] = Permission::firstOrCreate([ 'name' => 'roles.view' ])->id;
$adminPermissions[] = Permission::firstOrCreate([ 'name' => 'roles.create' ])->id;
$adminPermissions[] = Permission::firstOrCreate([ 'name' => 'roles.update' ])->id;
$adminPermissions[] = Permission::firstOrCreate([ 'name' => 'roles.delete' ])->id;

$adminPermissions[] = Permission::firstOrCreate([ 'name' => 'users.viewAny' ])->id;
$adminPermissions[] = Permission::firstOrCreate([ 'name' => 'users.view' ])->id;
$adminPermissions[] = Permission::firstOrCreate([ 'name' => 'users.create' ])->id;
$adminPermissions[] = Permission::firstOrCreate([ 'name' => 'users.update' ])->id;
$adminPermissions[] = Permission::firstOrCreate([ 'name' => 'users.delete' ])->id;
$adminPermissions[] = Permission::firstOrCreate([ 'name' => 'users.updateOwnAttributes' ])->id;

$adminRole = Role::firstOrCreate([ 'name' => 'admin', 'default' => true, 'room_limit' => -1 ]);
$adminRole = Role::where(['name' => 'admin', 'default' => true])->first();
if ($adminRole == null) {
$adminRole = Role::create([ 'name' => 'admin', 'default' => true, 'room_limit' => -1 ]);
}
$adminRole->permissions()->syncWithoutDetaching($adminPermissions);
}
}
Binary file added resources/images/favicon.ico
Binary file not shown.
1 change: 1 addition & 0 deletions resources/images/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions resources/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ Vue.config.errorHandler = function (error, vm, info) {
} else if (responseStatus === env.HTTP_GUESTS_ONLY) { // 420 => only for guests, redirect to home route
vm.flashMessage.info(vm.$t('app.flash.guestsOnly'));
vm.$router.replace({ name: 'home' });
} else if (responseStatus === env.HTTP_PAYLOAD_TOO_LARGE) { // 413 => payload to large
vm.flashMessage.error(vm.$t('app.flash.tooLarge'));
} else if (responseStatus !== undefined) { // Another error on server
vm.flashMessage.error({
message: errorMessage ? vm.$t('app.flash.serverError.message', { message: errorMessage }) : vm.$t('app.flash.serverError.emptyMessage'),
Expand Down
3 changes: 2 additions & 1 deletion resources/js/components/Room/FileComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<b-form-file
:disabled="isBusy"
:state="fieldState('file')"
:browse-text="$t('app.browse')"
:placeholder="$t('rooms.files.selectordrag')"
v-on:change="uploadFile($event)"
v-model="fileUpload"
Expand Down Expand Up @@ -353,7 +354,7 @@ export default {
}).catch((error) => {
if (error.response) {
if (error.response.status === env.HTTP_PAYLOAD_TOO_LARGE) {
this.errors = { file: [this.$t('rooms.files.validation.tooLarge')] };
this.errors = { file: [this.$t('app.validation.tooLarge')] };
return;
}
if (error.response.status === env.HTTP_UNPROCESSABLE_ENTITY) {
Expand Down
16 changes: 12 additions & 4 deletions resources/js/lang/de/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ export default {
title: 'Fehler'
},

tooLarge: {
message: 'Die übertragenen Daten waren zu groß!',
title: 'Fehler'
},

guestsOnly: {
message: 'Die Anfrage ist nur für nicht angemeldete Nutzer gestattet!',
title: 'Nür für Gäste'
Expand Down Expand Up @@ -59,7 +64,9 @@ export default {

settings: {
title: 'Einstellungen',
manage: 'Einstellungen verwalten'
manage: 'Einstellungen verwalten',
update: 'Einstellungen bearbeiten',
viewAny: 'Alle Einstellungen anzeigen'
},

roles: {
Expand All @@ -85,9 +92,10 @@ export default {
overwrite: 'Überschreiben',
save: 'Speichern',
back: 'Zurück',

true: 'Ja',
false: 'Nein',
browse: 'Durchsuchen',
validation: {
tooLarge: 'Die ausgewählte Datei ist zu groß.'
},

nextPage: 'Nächste Seite',
previousPage: 'Vorherige Seite',
Expand Down
3 changes: 0 additions & 3 deletions resources/js/lang/de/rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ export default {
},
formats: 'Erlaubte Dateiformate: {formats}',
size: 'Max. Dateigröße: {size} MB',
validation: {
tooLarge: 'Die ausgewählte Datei ist zu groß.'
},
termsOfUse: {
title: 'Nutzungsbedingungen',
content: 'Dateien, welche hier zum Download angeboten werden, sind ausschließlich für das persönliche Studium. Die Dateien, oder Inhalte aus diesen, dürfen nicht geteilt oder weiterverbreitet werden.',
Expand Down
43 changes: 43 additions & 0 deletions resources/js/lang/de/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,48 @@ export default {
confirm: 'Wollen Sie den Benutzer {firstname} {lastname} wirklich löschen?',
title: 'Benutzer löschen?'
}
},

application: {
title: 'Anwendung',
logo: {
title: 'Logo',
uploadTitle: 'Logo hochladen (max. 500 KB)',
urlTitle: 'URL zu Logo-Datei',
description: 'URL zum Logo',
hint: 'https://domain.tld/path/logo.svg',
selectFile: 'Logo-Datei auswählen',
alt: 'Favicon Vorschau'
},

favicon: {
title: 'Favicon',
uploadTitle: 'Favicon hochladen (max. 500 KB, Format: .ico)',
urlTitle: 'URL zu Favicon-Datei',
description: 'URL zum Favicon',
hint: 'https://domain.tld/path/favicon.ico',
selectFile: 'Favicon-Datei auswählen',
alt: 'Favicon Vorschau'
},

name: {
title: 'Name der Anwendung',
description: 'Ändert den Seitentitel'
},

roomLimit: {
title: 'Anzahl der Räume pro Benutzer',
description: 'Begrenzt die Anzahl der Räume, die ein Benutzer haben kann. Diese Einstellung wird von den gruppenspezifischen Grenzen überschrieben.'
},

paginationPageSize: {
title: 'Größe der Paginierung',
description: 'Begrenzt die Anzahl der gleichzeitig angezeigten Datensätze in Tabellen'
},

ownRoomsPaginationPageSize: {
title: 'Größe der Paginierung für eigene Räume',
description: 'Begrenzt die Anzahl der gleichzeitig angezeigten Räume auf der Startseite'
}
}
};
18 changes: 13 additions & 5 deletions resources/js/lang/en/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ export default {
title: 'Error'
},

tooLarge: {
message: 'The transmitted data was too large!',
title: 'Error'
},

guestsOnly: {
message: 'The request can only be done by guests!',
title: 'Only for guests'
Expand Down Expand Up @@ -59,7 +64,9 @@ export default {

settings: {
title: 'Settings',
manage: 'Manage settings'
manage: 'Manage settings',
update: 'Edit settings',
viewAny: 'Show all settings'
},

roles: {
Expand All @@ -81,19 +88,20 @@ export default {
updateOwnAttributes: 'Update own firstname, lastname and email'
}
},

overwrite: 'Overwrite',
save: 'Save',
back: 'Back',

true: 'Yes',
false: 'No',

nextPage: 'Next page',
previousPage: 'Previous page',

confirmPassword: {
title: 'Confirm password',
description: 'Please confirm your password before continuing!'
},

browse: 'Browse',
validation: {
tooLarge: 'The selected file is too large.'
}
};
3 changes: 0 additions & 3 deletions resources/js/lang/en/rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ export default {
},
formats: 'Allowed file formats: {formats}',
size: 'Max. file size: {size} MB',
validation: {
tooLarge: 'The selected file is too large.'
},
termsOfUse: {
title: 'Terms of Use',
content: 'Files that can be downloaded here are for personal study only. The files, or parts of them, may not be shared or distributed.',
Expand Down
Loading

0 comments on commit b93cf5b

Please sign in to comment.