From 806d0696f0cb75b4fae2ec33729c7753051e8caf Mon Sep 17 00:00:00 2001 From: Andy Heathershaw Date: Sun, 14 Jul 2019 16:28:46 +0100 Subject: [PATCH] #127: InstallController now sets default options and permissions for new installations --- app/Http/Controllers/InstallController.php | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/app/Http/Controllers/InstallController.php b/app/Http/Controllers/InstallController.php index 7fa9594..eb2a4c1 100644 --- a/app/Http/Controllers/InstallController.php +++ b/app/Http/Controllers/InstallController.php @@ -2,10 +2,12 @@ namespace App\Http\Controllers; +use App\AlbumDefaultAnonymousPermission; use App\Configuration; use App\Facade\UserConfig; use App\Helpers\MiscHelper; use App\Http\Requests\StoreUserRequest; +use App\Permission; use App\Storage; use App\User; use Illuminate\Http\Request; @@ -156,6 +158,9 @@ class InstallController extends Controller $versionNumber->value = config('app.version'); $versionNumber->save(); + // Default settings + $this->setConfigurationForNewSystems(); + $request->session()->put('install_stage', 3); return redirect(route('install.administrator')); } @@ -210,4 +215,47 @@ class InstallController extends Controller } } } + + private function setDefaultAnonymousPermission($section, $permission) + { + $permission = Permission::where([ + ['section', $section], + ['description', $permission] + ])->first(); + + if (is_null($permission)) + { + return; + } + + $adap = new AlbumDefaultAnonymousPermission(); + $adap->permission_id = $permission->id; + $adap->save(); + } + + private function setConfigurationForNewSystems() + { + /** @var Configuration $socialFeeds */ + $socialFeeds = UserConfig::getOrCreateModel('social_user_feeds'); + $socialFeeds->value = true; + $socialFeeds->save(); + + /** @var Configuration $socialProfiles */ + $socialProfiles = UserConfig::getOrCreateModel('social_user_profiles'); + $socialProfiles->value = true; + $socialProfiles->save(); + + /** @var Configuration $photoComments */ + $photoComments = UserConfig::getOrCreateModel('allow_photo_comments'); + $photoComments->value = true; + $photoComments->save(); + + $defaultPermissions = ['album.list', 'album.view', 'album.post-comment']; + foreach ($defaultPermissions as $defaultPermission) + { + $permissionParts = explode('.', $defaultPermission); + + $this->setDefaultAnonymousPermission($permissionParts[0], $permissionParts[1]); + } + } } \ No newline at end of file