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.
This commit is contained in:
Marcin Kurczewski 2014-02-20 19:26:17 +01:00
parent 28037af029
commit 2bac28a553
5 changed files with 14 additions and 17 deletions

View file

@ -86,14 +86,11 @@ editPostThumb=moderator
editPostSource=moderator editPostSource=moderator
editPostRelations.own=registered editPostRelations.own=registered
editPostRelations.all=moderator editPostRelations.all=moderator
editPostFile.all=moderator editPostFile=moderator
editPostFile.own=moderator
massTag.own=registered massTag.own=registered
massTag.all=power-user massTag.all=power-user
hidePost.own=moderator hidePost=moderator
hidePost.all=moderator deletePost=moderator
deletePost.own=moderator
deletePost.all=moderator
featurePost=moderator featurePost=moderator
scorePost=registered scorePost=registered
flagPost=registered flagPost=registered

View file

@ -254,7 +254,7 @@ class PostController
public function flagAction($id) public function flagAction($id)
{ {
$post = PostModel::findByIdOrName($id); $post = PostModel::findByIdOrName($id);
PrivilegesHelper::confirmWithException(Privilege::FlagPost); PrivilegesHelper::confirmWithException(Privilege::FlagPost, PrivilegesHelper::getIdentitySubPrivilege($post->getUploader()));
if (InputHelper::get('submit')) if (InputHelper::get('submit'))
{ {
@ -339,7 +339,7 @@ class PostController
public function addFavoriteAction($id) public function addFavoriteAction($id)
{ {
$post = PostModel::findByIdOrName($id); $post = PostModel::findByIdOrName($id);
PrivilegesHelper::confirmWithException(Privilege::FavoritePost); PrivilegesHelper::confirmWithException(Privilege::FavoritePost, PrivilegesHelper::getIdentitySubPrivilege($post->getUploader()));
if (InputHelper::get('submit')) if (InputHelper::get('submit'))
{ {
@ -358,7 +358,7 @@ class PostController
public function remFavoriteAction($id) public function remFavoriteAction($id)
{ {
$post = PostModel::findByIdOrName($id); $post = PostModel::findByIdOrName($id);
PrivilegesHelper::confirmWithException(Privilege::FavoritePost); PrivilegesHelper::confirmWithException(Privilege::FavoritePost, PrivilegesHelper::getIdentitySubPrivilege($post->getUploader()));
if (InputHelper::get('submit')) if (InputHelper::get('submit'))
{ {
@ -379,7 +379,7 @@ class PostController
public function scoreAction($id, $score) public function scoreAction($id, $score)
{ {
$post = PostModel::findByIdOrName($id); $post = PostModel::findByIdOrName($id);
PrivilegesHelper::confirmWithException(Privilege::ScorePost); PrivilegesHelper::confirmWithException(Privilege::ScorePost, PrivilegesHelper::getIdentitySubPrivilege($post->getUploader()));
if (InputHelper::get('submit')) if (InputHelper::get('submit'))
{ {
@ -399,7 +399,7 @@ class PostController
public function featureAction($id) public function featureAction($id)
{ {
$post = PostModel::findByIdOrName($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::FeaturedPostId, $post->id);
PropertyModel::set(PropertyModel::FeaturedPostDate, time()); PropertyModel::set(PropertyModel::FeaturedPostDate, time());
PropertyModel::set(PropertyModel::FeaturedPostUserName, $this->context->user->name); PropertyModel::set(PropertyModel::FeaturedPostUserName, $this->context->user->name);

View file

@ -140,7 +140,7 @@ class UserController
public function flagAction($name) public function flagAction($name)
{ {
$user = UserModel::findByNameOrEmail($name); $user = UserModel::findByNameOrEmail($name);
PrivilegesHelper::confirmWithException(Privilege::FlagUser); PrivilegesHelper::confirmWithException(Privilege::FlagUser, PrivilegesHelper::getIdentitySubPrivilege($user));
if (InputHelper::get('submit')) if (InputHelper::get('submit'))
{ {

View file

@ -130,7 +130,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
<span class="value"> <span class="value">
<?php echo $this->context->transport->post->score ?> <?php echo $this->context->transport->post->score ?>
<?php if (PrivilegesHelper::confirm(Privilege::ScorePost)): ?> <?php if (PrivilegesHelper::confirm(Privilege::ScorePost, PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->post->getUploader()))): ?>
&nbsp;[ &nbsp;[
<?php $scoreLink = function($score) { return \Chibi\UrlHelper::route('post', 'score', ['id' => $this->context->transport->post->id, 'score' => $score]); } ?> <?php $scoreLink = function($score) { return \Chibi\UrlHelper::route('post', 'score', ['id' => $this->context->transport->post->id, 'score' => $score]); } ?>
@ -173,7 +173,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
</div> </div>
<?php endif ?> <?php endif ?>
<?php if (PrivilegesHelper::confirm(Privilege::FavoritePost)): ?> <?php if (PrivilegesHelper::confirm(Privilege::FavoritePost, PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->post->getUploader()))): ?>
<div class="hl-option"> <div class="hl-option">
<?php if (!$this->context->favorite): ?> <?php if (!$this->context->favorite): ?>
<a class="add-fav icon simple-action" href="<?php echo \Chibi\UrlHelper::route('post', 'add-favorite', ['id' => $this->context->transport->post->id]) ?>"> <a class="add-fav icon simple-action" href="<?php echo \Chibi\UrlHelper::route('post', 'add-favorite', ['id' => $this->context->transport->post->id]) ?>">
@ -232,7 +232,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
<?php <?php
$options = []; $options = [];
if (PrivilegesHelper::confirm(Privilege::FeaturePost)) if (PrivilegesHelper::confirm(Privilege::FeaturePost, PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->post->getUploader())))
{ {
$options []= $options []=
[ [
@ -244,7 +244,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
]; ];
} }
if (PrivilegesHelper::confirm(Privilege::FlagPost)) if (PrivilegesHelper::confirm(Privilege::FlagPost, PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->post->getUploader())))
{ {
if ($this->context->flagged) if ($this->context->flagged)
{ {

View file

@ -86,7 +86,7 @@ LayoutHelper::addStylesheet('user-view.css');
]; ];
} }
if (PrivilegesHelper::confirm(Privilege::FlagUser)) if (PrivilegesHelper::confirm(Privilege::FlagUser, PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->user)))
{ {
if ($this->context->flagged) if ($this->context->flagged)
{ {