#112: Default album permissions are now used when creating a new album that does not inherit permissions, and is not marked as a private album

This commit is contained in:
Andy Heathershaw 2018-09-23 22:28:12 +01:00
parent a5569924be
commit 90c7591c31

View File

@ -660,21 +660,41 @@ class AlbumController extends Controller
$album->generateUrlPath();
$album->save();
// Link all default permissions to anonymous users (if a public album)
if (!$album->is_permissions_inherited)
// Link the default permissions (if a public album)
$isPrivate = (strtolower($request->get('is_private')) == 'on');
if (!$album->is_permissions_inherited && !$isPrivate)
{
$isPrivate = (strtolower($request->get('is_private')) == 'on');
$defaultAlbumUserPermissions = AlbumDefaultUserPermission::all();
$defaultAlbumGroupPermissions = AlbumDefaultGroupPermission::all();
$defaultAnonPermissions = AlbumDefaultAnonymousPermission::all();
if (!$isPrivate)
/** @var AlbumDefaultAnonymousPermission $permission */
foreach ($defaultAnonPermissions as $permission)
{
/** @var Permission $permission */
foreach (Permission::where(['section' => 'album', 'is_default' => true])->get() as $permission)
{
$album->anonymousPermissions()->attach($permission->id, [
'created_at' => new \DateTime(),
'updated_at' => new \DateTime()
]);
}
$album->anonymousPermissions()->attach($permission->permission_id, [
'created_at' => new \DateTime(),
'updated_at' => new \DateTime()
]);
}
/** @var AlbumDefaultGroupPermission $permission */
foreach ($defaultAlbumGroupPermissions as $permission)
{
$album->groupPermissions()->attach($permission->permission_id, [
'group_id' => $permission->group_id,
'created_at' => new \DateTime(),
'updated_at' => new \DateTime()
]);
}
/** @var AlbumDefaultUserPermission $permission */
foreach ($defaultAlbumUserPermissions as $permission)
{
$album->userPermissions()->attach($permission->permission_id, [
'user_id' => $permission->user_id,
'created_at' => new \DateTime(),
'updated_at' => new \DateTime()
]);
}
}