2017-03-22 09:25:14 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Policies;
|
|
|
|
|
|
|
|
use App\Album;
|
2018-09-20 14:38:34 +01:00
|
|
|
use App\Facade\UserConfig;
|
2017-03-22 09:25:14 +00:00
|
|
|
use App\Group;
|
2018-09-16 08:41:36 +01:00
|
|
|
use App\Helpers\PermissionsHelper;
|
2017-03-22 09:25:14 +00:00
|
|
|
use App\Permission;
|
|
|
|
use App\User;
|
|
|
|
use Illuminate\Auth\Access\HandlesAuthorization;
|
|
|
|
|
|
|
|
class AlbumPolicy
|
|
|
|
{
|
|
|
|
use HandlesAuthorization;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new policy instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
public function before($user, $ability)
|
|
|
|
{
|
|
|
|
if ($user->is_admin)
|
|
|
|
{
|
|
|
|
// Admins can do anything
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-16 09:00:57 +01:00
|
|
|
public function changePermissions(User $user, Album $album)
|
|
|
|
{
|
|
|
|
// Only the album's owner (or an admin, matched by the before() rule) can change permissions
|
|
|
|
return $user->id == $album->user_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function changePhotoMetadata(User $user, Album $album)
|
|
|
|
{
|
|
|
|
if ($user->id == $album->user_id)
|
|
|
|
{
|
|
|
|
// The album's owner and can do everything
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-09-16 08:41:36 +01:00
|
|
|
return $this->userHasPermission($user, $album, 'change-photo-metadata');
|
2017-04-16 09:00:57 +01:00
|
|
|
}
|
|
|
|
|
2017-09-10 17:21:52 +01:00
|
|
|
public function delete(User $user, Album $album)
|
|
|
|
{
|
|
|
|
if ($user->id == $album->user_id)
|
|
|
|
{
|
|
|
|
// The album's owner and can do everything
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-09-16 08:41:36 +01:00
|
|
|
return $this->userHasPermission($user, $album, 'delete');
|
2017-09-10 17:21:52 +01:00
|
|
|
}
|
|
|
|
|
2017-04-16 09:00:57 +01:00
|
|
|
public function deletePhotos(User $user, Album $album)
|
|
|
|
{
|
|
|
|
if ($user->id == $album->user_id)
|
|
|
|
{
|
|
|
|
// The album's owner and can do everything
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-09-16 08:41:36 +01:00
|
|
|
return $this->userHasPermission($user, $album, 'delete-photos');
|
2017-04-16 09:00:57 +01:00
|
|
|
}
|
|
|
|
|
2017-03-22 09:25:14 +00:00
|
|
|
public function edit(User $user, Album $album)
|
|
|
|
{
|
|
|
|
if ($user->id == $album->user_id)
|
|
|
|
{
|
|
|
|
// The album's owner and can do everything
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-09-16 08:41:36 +01:00
|
|
|
return $this->userHasPermission($user, $album, 'edit');
|
2017-04-15 08:36:17 +01:00
|
|
|
}
|
|
|
|
|
2017-04-16 09:00:57 +01:00
|
|
|
public function manipulatePhotos(User $user, Album $album)
|
|
|
|
{
|
|
|
|
if ($user->id == $album->user_id)
|
|
|
|
{
|
|
|
|
// The album's owner and can do everything
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-09-16 08:41:36 +01:00
|
|
|
return $this->userHasPermission($user, $album, 'manipulate-photos');
|
2017-04-16 09:00:57 +01:00
|
|
|
}
|
|
|
|
|
2018-09-19 19:54:59 +01:00
|
|
|
public function moderateComments(User $user, Album $album)
|
|
|
|
{
|
|
|
|
if ($user->id == $album->user_id)
|
|
|
|
{
|
|
|
|
// The album's owner and can do everything
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->userHasPermission($user, $album, 'moderate-comments');
|
|
|
|
}
|
|
|
|
|
2018-09-20 14:38:34 +01:00
|
|
|
public function postComment(User $user, Album $album)
|
|
|
|
{
|
|
|
|
if ($user->id == $album->user_id)
|
|
|
|
{
|
|
|
|
// The album's owner and can do everything
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't allow comments to be posted if anonymous user, and anonymous comments disabled
|
|
|
|
if ($user->isAnonymous() && !UserConfig::get('allow_photo_comments_anonymous'))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->userHasPermission($user, $album, 'post-comment');
|
|
|
|
}
|
|
|
|
|
2017-04-16 09:00:57 +01:00
|
|
|
public function uploadPhotos(User $user, Album $album)
|
|
|
|
{
|
|
|
|
if ($user->id == $album->user_id)
|
|
|
|
{
|
|
|
|
// The album's owner and can do everything
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-09-16 08:41:36 +01:00
|
|
|
return $this->userHasPermission($user, $album, 'upload-photos');
|
2017-04-16 09:00:57 +01:00
|
|
|
}
|
|
|
|
|
2017-04-15 08:36:17 +01:00
|
|
|
public function view(User $user, Album $album)
|
|
|
|
{
|
|
|
|
if ($user->id == $album->user_id)
|
|
|
|
{
|
|
|
|
// The album's owner and can do everything
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-09-16 08:41:36 +01:00
|
|
|
return $this->userHasPermission($user, $album, 'view');
|
2017-04-15 08:36:17 +01:00
|
|
|
}
|
|
|
|
|
2018-09-16 08:41:36 +01:00
|
|
|
private function userHasPermission(User $user, Album $album, $permission)
|
2017-04-15 08:36:17 +01:00
|
|
|
{
|
2018-09-16 08:41:36 +01:00
|
|
|
$helper = new PermissionsHelper();
|
|
|
|
return $helper->userCan_Album($album, $user, $permission);
|
2017-03-22 09:25:14 +00:00
|
|
|
}
|
|
|
|
}
|