diff --git a/config.ini b/config.ini index 037af0f9..3905d9c3 100644 --- a/config.ini +++ b/config.ini @@ -86,6 +86,7 @@ deletePost.own=moderator deletePost.all=moderator featurePost=moderator scorePost=registered +flagPost=registered listUsers=registered viewUser=registered @@ -104,6 +105,7 @@ banUser.own=nobody banUser.all=admin deleteUser.own=registered deleteUser.all=nobody +flagUser=registered listComments=anonymous addComment=registered diff --git a/src/Controllers/PostController.php b/src/Controllers/PostController.php index 47c4321d..e75925d1 100644 --- a/src/Controllers/PostController.php +++ b/src/Controllers/PostController.php @@ -474,6 +474,31 @@ class PostController + /** + * @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 */ diff --git a/src/Controllers/UserController.php b/src/Controllers/UserController.php index 60704f29..4c97a35d 100644 --- a/src/Controllers/UserController.php +++ b/src/Controllers/UserController.php @@ -137,6 +137,32 @@ class UserController + /** + * @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 [^\/]+ @@ -145,15 +171,19 @@ class UserController { $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 [^\/]+ @@ -162,15 +192,19 @@ class UserController { $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 [^\/]+ diff --git a/src/Models/Privilege.php b/src/Models/Privilege.php index 2c4ae348..759a2c1d 100644 --- a/src/Models/Privilege.php +++ b/src/Models/Privilege.php @@ -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; @@ -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; diff --git a/src/Views/post-view.phtml b/src/Views/post-view.phtml index 29c03c49..19246ad2 100644 --- a/src/Views/post-view.phtml +++ b/src/Views/post-view.phtml @@ -247,6 +247,14 @@ + +