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 12 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
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: 41 additions & 11 deletions app/Http/Controllers/api/v1/ApplicationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,61 @@
namespace App\Http\Controllers\api\v1;

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

class ApplicationController extends Controller
{
/**
* Load basic application data, like settings
* @return \Illuminate\Http\JsonResponse
* @return JsonResponse
*/
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')
]
]
'logo' => setting('logo'),
'room_limit' => setting('room_limit'),
'pagination_page_size' => setting('pagination_page_size'),
'own_rooms_pagination_page_size' => setting('own_rooms_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')
]
]
]);
}

/**
* Update application settings data
* @param UpdateSetting $request
* @return JsonResponse
*/
public function updateSettings(UpdateSetting $request)
{
$data = $request->all();

// Settings defaults array keys for validation
$setting_keys = collect(config('settings.defaults'))->keys()->toArray();

foreach ($data as $key => $value) {
SamuelWei marked this conversation as resolved.
Show resolved Hide resolved
// If key exists in the settings array keys then update settings
if (in_array($key, $setting_keys)) {
setting([$key => $value])->save();
}
}

return response()->json(['data' => [
'logo' => setting('logo'),
'room_limit' => setting('room_limit'),
'pagination_page_size' => setting('pagination_page_size'),
'own_rooms_pagination_page_size' => setting('own_rooms_pagination_page_size')
]], 201);
}

/**
* Load current user
* @return UserResource
Expand Down
23 changes: 23 additions & 0 deletions app/Http/Requests/UpdateSetting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?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 [
'room_limit' => 'sometimes|required|numeric|max:255',
'logo' => 'sometimes|required|url|max:255',
SamuelWei marked this conversation as resolved.
Show resolved Hide resolved
'own_rooms_pagination_page_size' => 'sometimes|required|numeric|max:255',
'pagination_page_size' => 'sometimes|required|numeric|max:255'
];
}
}
5 changes: 5 additions & 0 deletions database/seeds/RolesAndPermissionsSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@ 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, 'role_limit' => -1 ]);
Expand Down
4 changes: 3 additions & 1 deletion resources/js/lang/de/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ export default {

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

roles: {
Expand Down
32 changes: 32 additions & 0 deletions resources/js/lang/de/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,37 @@ export default {

users: {
title: 'Benutzer'
},

application: {
title: 'Anwendung',
save: 'Abspeichern',
SamuelWei marked this conversation as resolved.
Show resolved Hide resolved
preview: 'Vorschauen',
SamuelWei marked this conversation as resolved.
Show resolved Hide resolved

updateSettingsSuccess: {
message: 'Einstellung wurde erfolgreich aktualisiert!',
title: 'Einstellung'
},

logo: {
title: 'Logo',
description: 'Das Anwendungslogo ändern. Bild URL eingeben',
SamuelWei marked this conversation as resolved.
Show resolved Hide resolved
hint: 'Bild URL'
},

roomLimit: {
title: 'Anzahl der Räume pro Benutzer',
description: 'Begrenzt die Anzahl der Räume, die ein Benutzer haben kann. Diese Einstellung gilt nicht für Administratoren. Der Wert -1 für unbegrenzte Anzahl der Räume eingeben'
SamuelWei marked this conversation as resolved.
Show resolved Hide resolved
},

paginationPageSize: {
title: 'Größe der Paginierung',
description: 'Begrenzt die Seitengrößen für die Paginierung der Datentabellen'
SamuelWei marked this conversation as resolved.
Show resolved Hide resolved
},

ownRoomsPaginationPageSize: {
title: 'Größe der Paginierung für eigene Räume',
description: 'Begrenzt die Seitengrößen für die Paginierung der eigenen Räume'
SamuelWei marked this conversation as resolved.
Show resolved Hide resolved
}
}
};
4 changes: 3 additions & 1 deletion resources/js/lang/en/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ export default {

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

roles: {
Expand Down
32 changes: 32 additions & 0 deletions resources/js/lang/en/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,37 @@ export default {

users: {
title: 'Users'
},

application: {
title: 'Application',
save: 'Save',
preview: 'Preview',

updateSettingsSuccess: {
message: 'Settings updated successfully!',
title: 'Settings'
},

logo: {
title: 'Logo',
description: 'Change the application logo. Enter the image URL',
hint: 'Image URL'
},

roomLimit: {
title: 'Number of rooms per user',
description: 'Limits the number of rooms that a user can have. This setting does not apply to administrators. Enter the value -1 for unlimited number of rooms'
},

paginationPageSize: {
title: 'Pagination page size',
description: 'Limits the number of page size for data tables pagination'
},

ownRoomsPaginationPageSize: {
title: 'Own rooms pagination page size',
description: 'Limits the number of page size for own rooms pagination'
}
}
};
20 changes: 20 additions & 0 deletions resources/js/policies/SettingPolicy.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,25 @@ export default {
*/
manage (permissionService) {
return !permissionService.currentUser ? false : permissionService.currentUser.permissions.includes('settings.manage');
},

/**
* Returns a boolean that indicates whether the user can view all application settings or not.
*
* @param permissionService
* @return {boolean}
*/
viewAny (permissionService) {
return !permissionService.currentUser ? false : permissionService.currentUser.permissions.includes('settings.viewAny');
},

/**
* Returns a boolean that indicates whether the user can update the application settings or not.
*
* @param permissionService
* @return {boolean}
*/
update (permissionService) {
return !permissionService.currentUser ? false : permissionService.currentUser.permissions.includes('settings.update');
}
};
14 changes: 14 additions & 0 deletions resources/js/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Settings from './views/settings/Settings';
import RolesIndex from './views/settings/roles/Index';
import RolesView from './views/settings/roles/View';
import Users from './views/settings/Users';
import Application from './views/settings/Application';
import SettingsHome from './views/settings/SettingsHome';
import Base from './api/base';

Expand Down Expand Up @@ -112,6 +113,19 @@ export const routes = [
});
}
}
},
{
path: 'application',
name: 'settings.application',
component: Application,
meta: {
requiresAuth: true,
accessPermitted: () => Promise.resolve(
PermissionService.can('manage', 'SettingPolicy') &&
PermissionService.can('viewAny', 'SettingPolicy') &&
PermissionService.can('update', 'SettingPolicy')
)
}
}
]
},
Expand Down
Loading