Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

55 management of application settings #60

Merged
merged 42 commits into from
Dec 1, 2020
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
5da3eb2
Added Setting controller and model, Added Initial view for applicatio…
rhrt04 Oct 2, 2020
75e79db
Added Update Settings functionality, removed controller & model, remo…
rhrt04 Oct 5, 2020
5cc7e1c
Updated route name for settings update, updated SettingsTest.php, tes…
rhrt04 Oct 6, 2020
bf42800
Added frontend unit test Application.spec.js for Application.vue
rhrt04 Oct 6, 2020
b427cd9
Updated CHANGELOG.md
rhrt04 Oct 6, 2020
5d823de
Removed redundant code, fixed order on CHANGELOG.md
rhrt04 Oct 6, 2020
b6aa25d
Updated preview logo image to fit to container.
rhrt04 Oct 6, 2020
a13a2b6
Updated permission/policy for application settings frontend, added mi…
rhrt04 Oct 20, 2020
141324e
Added invalid feedback error message for form inputs
rhrt04 Oct 20, 2020
79b5457
Updated updateSettings to empty errors array if succeeded
rhrt04 Oct 20, 2020
1d4612c
Added accessPermitted route test for application settings view
rhrt04 Oct 26, 2020
5a48d79
Merged master into branch
rhrt04 Oct 26, 2020
a0e91f5
Merge branch 'master' of github.com:THM-Health/PILOS into 55-manageme…
SamuelWei Oct 29, 2020
9ecf54b
Enable image upload, git comments, cleanup
SamuelWei Oct 30, 2020
707a037
fix broken test
SamuelWei Oct 30, 2020
92765ac
bugfix
SamuelWei Oct 30, 2020
9c75e93
Add checkbox for unlimited rooms, code cleanup
SamuelWei Oct 30, 2020
826ed2b
Merge branch 'master' of https://github.com/THM-Health/PILOS into 55-…
rhrt04 Nov 2, 2020
368fb19
Merge branch '55-management-of-application-settings' of https://githu…
rhrt04 Nov 2, 2020
c4a1964
Moved base64Encode inside export default, Updated tests
rhrt04 Nov 3, 2020
bbeb6cb
Updated Tests
rhrt04 Nov 8, 2020
7b9d986
Add readOnly to application settings, fix and add tests
SamuelWei Nov 23, 2020
01bb91f
Make appl. settings update more strict
SamuelWei Nov 23, 2020
7ebaa9d
git comments
SamuelWei Nov 25, 2020
ca227b8
Bugfix role permission seeder
Nov 25, 2020
68cbecb
Github comments, add favicon
SamuelWei Nov 25, 2020
916b0bb
Merge branch '55-management-of-application-settings' of github.com:TH…
SamuelWei Nov 25, 2020
bd3abff
lang fix, improve HTTP_PAYLOAD_TOO_LARGE errors
SamuelWei Nov 25, 2020
9328785
Update resources/js/views/settings/Application.vue
SamuelWei Nov 25, 2020
f8cf5cf
Github comments
SamuelWei Nov 30, 2020
b1df3d5
fix tests
SamuelWei Nov 30, 2020
49ee710
add minMax-Test
SamuelWei Dec 1, 2020
8efb04a
Add b-form and form validation
SamuelWei Dec 1, 2020
3ac6710
Add overlay and fix git comments
SamuelWei Dec 1, 2020
2a7ee10
Improve overlay
SamuelWei Dec 1, 2020
6f8e441
Merge branch 'master' of github.com:THM-Health/PILOS into 55-manageme…
SamuelWei Dec 1, 2020
c22d601
Remove duplicate translations
Dec 1, 2020
d70c9fd
Disable form fields when error occurs during model load
Dec 1, 2020
1521b48
Show overlay during save
Dec 1, 2020
0de179a
Fix failing frontend test
Dec 1, 2020
8d84b26
Merge remote-tracking branch 'remotes/origin/master' into 55-manageme…
Dec 1, 2020
7f6c4b6
Add some more frontend application settings tests and fix failing
Dec 1, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added global settings, .env as default; added logo path and room limit ([#34],[#36])
- 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 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 @@ -54,5 +55,7 @@ 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

[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();
SamuelWei marked this conversation as resolved.
Show resolved Hide resolved

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
SamuelWei marked this conversation as resolved.
Show resolved Hide resolved
'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'),
dsst95 marked this conversation as resolved.
Show resolved Hide resolved
'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,15 +20,23 @@ 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;

$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
15 changes: 12 additions & 3 deletions resources/js/lang/de/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,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 @@ -57,7 +62,9 @@ export default {

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

roles: {
Expand All @@ -78,7 +85,9 @@ export default {
overwrite: 'Überschreiben',
save: 'Speichern',
back: 'Zurück',
browse: 'Durchsuchen',
validation: {
tooLarge: 'Die ausgewählte Datei ist zu groß.'
}

true: 'Ja',
false: 'Nein'
};
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 @@ -45,5 +45,48 @@ export default {

users: {
title: 'Benutzer'
},

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',
SamuelWei marked this conversation as resolved.
Show resolved Hide resolved
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'
}
}
};
17 changes: 12 additions & 5 deletions resources/js/lang/en/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,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 @@ -57,7 +62,9 @@ export default {

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

roles: {
Expand All @@ -74,11 +81,11 @@ export default {
viewAny: 'Show all users'
}
},

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

true: 'Yes',
false: 'No'
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