From 2bac28a55337bc4d1e992c0545552dde84d9af86 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Thu, 20 Feb 2014 19:26:17 +0100 Subject: [PATCH] More capable privilege system Following privileges for post actions can now understand different settings for everyone and for uploader: * Scoring posts * Featuring posts * Flagging posts * Favoriting posts Additionally, privilege for flagging users can now understand different settings for everyone and for the user that is currently logged in. In other words: with this update admin can configure privileges so that scoring own posts or flagging oneself will be prohibited, while scoring other people's posts or flagging others will be okay. --- data/config.ini | 9 +++------ src/Controllers/PostController.php | 10 +++++----- src/Controllers/UserController.php | 2 +- src/Views/post-view.phtml | 8 ++++---- src/Views/user-view.phtml | 2 +- 5 files changed, 14 insertions(+), 17 deletions(-) diff --git a/data/config.ini b/data/config.ini index 04af9432..2adcee5e 100644 --- a/data/config.ini +++ b/data/config.ini @@ -86,14 +86,11 @@ editPostThumb=moderator editPostSource=moderator editPostRelations.own=registered editPostRelations.all=moderator -editPostFile.all=moderator -editPostFile.own=moderator +editPostFile=moderator massTag.own=registered massTag.all=power-user -hidePost.own=moderator -hidePost.all=moderator -deletePost.own=moderator -deletePost.all=moderator +hidePost=moderator +deletePost=moderator featurePost=moderator scorePost=registered flagPost=registered diff --git a/src/Controllers/PostController.php b/src/Controllers/PostController.php index f0b28a37..55dff495 100644 --- a/src/Controllers/PostController.php +++ b/src/Controllers/PostController.php @@ -254,7 +254,7 @@ class PostController public function flagAction($id) { $post = PostModel::findByIdOrName($id); - PrivilegesHelper::confirmWithException(Privilege::FlagPost); + PrivilegesHelper::confirmWithException(Privilege::FlagPost, PrivilegesHelper::getIdentitySubPrivilege($post->getUploader())); if (InputHelper::get('submit')) { @@ -339,7 +339,7 @@ class PostController public function addFavoriteAction($id) { $post = PostModel::findByIdOrName($id); - PrivilegesHelper::confirmWithException(Privilege::FavoritePost); + PrivilegesHelper::confirmWithException(Privilege::FavoritePost, PrivilegesHelper::getIdentitySubPrivilege($post->getUploader())); if (InputHelper::get('submit')) { @@ -358,7 +358,7 @@ class PostController public function remFavoriteAction($id) { $post = PostModel::findByIdOrName($id); - PrivilegesHelper::confirmWithException(Privilege::FavoritePost); + PrivilegesHelper::confirmWithException(Privilege::FavoritePost, PrivilegesHelper::getIdentitySubPrivilege($post->getUploader())); if (InputHelper::get('submit')) { @@ -379,7 +379,7 @@ class PostController public function scoreAction($id, $score) { $post = PostModel::findByIdOrName($id); - PrivilegesHelper::confirmWithException(Privilege::ScorePost); + PrivilegesHelper::confirmWithException(Privilege::ScorePost, PrivilegesHelper::getIdentitySubPrivilege($post->getUploader())); if (InputHelper::get('submit')) { @@ -399,7 +399,7 @@ class PostController public function featureAction($id) { $post = PostModel::findByIdOrName($id); - PrivilegesHelper::confirmWithException(Privilege::FeaturePost); + PrivilegesHelper::confirmWithException(Privilege::FeaturePost, PrivilegesHelper::getIdentitySubPrivilege($post->getUploader())); PropertyModel::set(PropertyModel::FeaturedPostId, $post->id); PropertyModel::set(PropertyModel::FeaturedPostDate, time()); PropertyModel::set(PropertyModel::FeaturedPostUserName, $this->context->user->name); diff --git a/src/Controllers/UserController.php b/src/Controllers/UserController.php index 3c0924ce..2c6ca8d5 100644 --- a/src/Controllers/UserController.php +++ b/src/Controllers/UserController.php @@ -140,7 +140,7 @@ class UserController public function flagAction($name) { $user = UserModel::findByNameOrEmail($name); - PrivilegesHelper::confirmWithException(Privilege::FlagUser); + PrivilegesHelper::confirmWithException(Privilege::FlagUser, PrivilegesHelper::getIdentitySubPrivilege($user)); if (InputHelper::get('submit')) { diff --git a/src/Views/post-view.phtml b/src/Views/post-view.phtml index c9812aee..b6ab3649 100644 --- a/src/Views/post-view.phtml +++ b/src/Views/post-view.phtml @@ -130,7 +130,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0; context->transport->post->score ?> - + context->transport->post->getUploader()))): ?>  [ $this->context->transport->post->id, 'score' => $score]); } ?> @@ -173,7 +173,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0; - + context->transport->post->getUploader()))): ?>