Skip to content

Commit

Permalink
Closed #57
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcin Kurczewski committed Nov 17, 2013
1 parent da63c0f commit 3c41940
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 0 deletions.
2 changes: 2 additions & 0 deletions config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ deletePost.own=moderator
deletePost.all=moderator
featurePost=moderator
scorePost=registered
flagPost=registered

listUsers=registered
viewUser=registered
Expand All @@ -104,6 +105,7 @@ banUser.own=nobody
banUser.all=admin
deleteUser.own=registered
deleteUser.all=nobody
flagUser=registered

listComments=anonymous
addComment=registered
Expand Down
25 changes: 25 additions & 0 deletions src/Controllers/PostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,31 @@ public function editAction($id)



/**
* @route /post/{id}/flag
*/
public function flagAction($id)
{
$post = Model_Post::locate($id);
PrivilegesHelper::confirmWithException(Privilege::FlagPost);

if (InputHelper::get('submit'))
{
$key = '@' . $post->id;

if (!isset($_SESSION['flagged']))
$_SESSION['flagged'] = [];
if (in_array($key, $_SESSION['flagged']))
throw new SimpleException('You already flagged this post');
$_SESSION['flagged'] []= $key;

LogHelper::logEvent('post-flag', '**+{user} flagged @{post} for moderator attention**', ['post' => $post->id]);
StatusHelper::success();
}
}



/**
* @route /post/{id}/hide
*/
Expand Down
34 changes: 34 additions & 0 deletions src/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,32 @@ public function listAction($sortStyle, $page)



/**
* @route /user/{name}/flag
* @validate name [^\/]+
*/
public function flagAction($name)
{
$user = Model_User::locate($name);
PrivilegesHelper::confirmWithException(Privilege::FlagUser);

if (InputHelper::get('submit'))
{
$key = '+' . $user->name;

if (!isset($_SESSION['flagged']))
$_SESSION['flagged'] = [];
if (in_array($key, $_SESSION['flagged']))
throw new SimpleException('You already flagged this user');
$_SESSION['flagged'] []= $key;

LogHelper::logEvent('user-flag', '**+{user} flagged +{subject} for moderator attention**', ['subject' => $user->name]);
StatusHelper::success();
}
}



/**
* @route /user/{name}/ban
* @validate name [^\/]+
Expand All @@ -145,15 +171,19 @@ public function banAction($name)
{
$user = Model_User::locate($name);
PrivilegesHelper::confirmWithException(Privilege::BanUser, PrivilegesHelper::getIdentitySubPrivilege($user));

if (InputHelper::get('submit'))
{
$user->banned = true;
R::store($user);

LogHelper::logEvent('ban', '+{user} banned +{subject}', ['subject' => $user->name]);
StatusHelper::success();
}
}



/**
* @route /post/{name}/unban
* @validate name [^\/]+
Expand All @@ -162,15 +192,19 @@ public function unbanAction($name)
{
$user = Model_User::locate($name);
PrivilegesHelper::confirmWithException(Privilege::BanUser, PrivilegesHelper::getIdentitySubPrivilege($user));

if (InputHelper::get('submit'))
{
$user->banned = false;
R::store($user);

LogHelper::logEvent('unban', '+{user} unbanned +{subject}', ['subject' => $user->name]);
StatusHelper::success();
}
}



/**
* @route /post/{name}/accept-registration
* @validate name [^\/]+
Expand Down
2 changes: 2 additions & 0 deletions src/Models/Privilege.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Privilege extends Enum
const DeletePost = 10;
const FeaturePost = 25;
const ScorePost = 31;
const FlagPost = 34;

const ListUsers = 11;
const ViewUser = 12;
Expand All @@ -27,6 +28,7 @@ class Privilege extends Enum
const ChangeUserName = 18;
const ChangeUserSettings = 28;
const DeleteUser = 19;
const FlagUser = 35;

const ListComments = 20;
const AddComment = 23;
Expand Down
8 changes: 8 additions & 0 deletions src/Views/post-view.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,14 @@
</li>
<?php endif ?>

<?php if (PrivilegesHelper::confirm(Privilege::FlagPost)): ?>
<li class="flag">
<a class="simple-action" href="<?php echo \Chibi\UrlHelper::route('post', 'flag', ['id' => $this->context->transport->post->id]) ?>" data-confirm-text="Are you sure you want to flag this post?">
Flag for moderator attention
</a>
</li>
<?php endif ?>

<?php if (PrivilegesHelper::confirm(Privilege::DeletePost, PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->post->uploader))): ?>
<li class="delete">
<a class="simple-action" href="<?php echo \Chibi\UrlHelper::route('post', 'delete', ['id' => $this->context->transport->post->id]) ?>" data-confirm-text="Are you sure you want to delete this post?" data-redirect-url="<?php echo \Chibi\UrlHelper::route('post', 'list') ?>">
Expand Down
8 changes: 8 additions & 0 deletions src/Views/user-view.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@
</li>
<?php endif ?>

<?php if (PrivilegesHelper::confirm(Privilege::FlagUser)): ?>
<li class="flag">
<a class="simple-action" href="<?php echo \Chibi\UrlHelper::route('user', 'flag', ['name' => $this->context->transport->user->name]) ?>" data-confirm-text="Are you sure you want to flag this user?">
Flag for moderator attention
</a>
</li>
<?php endif ?>

<?php if (PrivilegesHelper::confirm(Privilege::BanUser, PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->user))): ?>
<?php if (!$this->context->transport->user->banned): ?>
<li class="ban">
Expand Down

0 comments on commit 3c41940

Please sign in to comment.