more shit
This commit is contained in:
parent
8b6bb48231
commit
83632168d4
16 changed files with 98 additions and 193 deletions
|
@ -9,7 +9,6 @@ namespace Sakura\BBCode\Tags;
|
||||||
use Sakura\BBCode\TagBase;
|
use Sakura\BBCode\TagBase;
|
||||||
use Sakura\Forum\Forum;
|
use Sakura\Forum\Forum;
|
||||||
use Sakura\Forum\Post;
|
use Sakura\Forum\Post;
|
||||||
use Sakura\Perms\Forum as ForumPerms;
|
|
||||||
use Sakura\User;
|
use Sakura\User;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -36,7 +35,7 @@ class NamedQuote extends TagBase
|
||||||
$post = new Post(intval($matches[2]));
|
$post = new Post(intval($matches[2]));
|
||||||
$forum = new Forum($post->forum);
|
$forum = new Forum($post->forum);
|
||||||
|
|
||||||
if ($post->id !== 0 && $forum->permission(ForumPerms::VIEW, $poster->id)) {
|
if ($post->id !== 0 && $forum->perms->view) {
|
||||||
$link = route('forums.post', $post->id);
|
$link = route('forums.post', $post->id);
|
||||||
|
|
||||||
$quoting = "<a href='{$link}' style='color: {$post->poster->colour}' class='bbcode__quote-post'>{$post->poster->username}</a>";
|
$quoting = "<a href='{$link}' style='color: {$post->poster->colour}' class='bbcode__quote-post'>{$post->poster->username}</a>";
|
||||||
|
|
|
@ -238,7 +238,6 @@ class SetupCommand extends Command
|
||||||
[
|
[
|
||||||
'forum_id' => 1,
|
'forum_id' => 1,
|
||||||
'rank_id' => config('rank.regular'),
|
'rank_id' => config('rank.regular'),
|
||||||
'forum_perms' => '00000011111',
|
|
||||||
'perm_view' => true,
|
'perm_view' => true,
|
||||||
'perm_reply' => true,
|
'perm_reply' => true,
|
||||||
'perm_topic_create' => true,
|
'perm_topic_create' => true,
|
||||||
|
|
|
@ -14,7 +14,6 @@ use Sakura\DB;
|
||||||
use Sakura\Forum\Forum;
|
use Sakura\Forum\Forum;
|
||||||
use Sakura\Forum\Post;
|
use Sakura\Forum\Post;
|
||||||
use Sakura\Forum\Topic;
|
use Sakura\Forum\Topic;
|
||||||
use Sakura\Perms\Forum as ForumPerms;
|
|
||||||
use Sakura\User;
|
use Sakura\User;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -45,7 +44,7 @@ class ForumController extends Controller
|
||||||
$forum = new Forum($topic->forum);
|
$forum = new Forum($topic->forum);
|
||||||
|
|
||||||
// Check if we have permission to view it
|
// Check if we have permission to view it
|
||||||
if (!$forum->permission(ForumPerms::VIEW, CurrentSession::$user->id)) {
|
if (!$forum->perms->view) {
|
||||||
$fetch = DB::table('posts')
|
$fetch = DB::table('posts')
|
||||||
->groupBy('topic_id')
|
->groupBy('topic_id')
|
||||||
->orderByRaw('COUNT(*) DESC')
|
->orderByRaw('COUNT(*) DESC')
|
||||||
|
@ -75,7 +74,7 @@ class ForumController extends Controller
|
||||||
$forum = new Forum($post->forum);
|
$forum = new Forum($post->forum);
|
||||||
|
|
||||||
// Check if we have permission to view it
|
// Check if we have permission to view it
|
||||||
if (!$forum->permission(ForumPerms::VIEW, CurrentSession::$user->id)) {
|
if (!$forum->perms->view) {
|
||||||
$fetch = DB::table('posts')
|
$fetch = DB::table('posts')
|
||||||
->orderBy('post_id', 'desc')
|
->orderBy('post_id', 'desc')
|
||||||
->skip(11 + $_n)
|
->skip(11 + $_n)
|
||||||
|
@ -124,7 +123,7 @@ class ForumController extends Controller
|
||||||
|
|
||||||
// Check if the forum exists
|
// Check if the forum exists
|
||||||
if ($forum->id < 0
|
if ($forum->id < 0
|
||||||
|| !$forum->permission(ForumPerms::VIEW, CurrentSession::$user->id)) {
|
|| !$forum->perms->view) {
|
||||||
throw new HttpRouteNotFoundException();
|
throw new HttpRouteNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,7 +151,7 @@ class ForumController extends Controller
|
||||||
|
|
||||||
// Check if the forum exists
|
// Check if the forum exists
|
||||||
if ($forum->id < 1
|
if ($forum->id < 1
|
||||||
|| !$forum->permission(ForumPerms::VIEW, CurrentSession::$user->id)) {
|
|| !$forum->perms->view) {
|
||||||
throw new HttpRouteNotFoundException();
|
throw new HttpRouteNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,6 @@ use Sakura\DB;
|
||||||
use Sakura\Forum\Forum;
|
use Sakura\Forum\Forum;
|
||||||
use Sakura\Forum\Post;
|
use Sakura\Forum\Post;
|
||||||
use Sakura\Forum\Topic;
|
use Sakura\Forum\Topic;
|
||||||
use Sakura\Perms;
|
|
||||||
use Sakura\Perms\Forum as ForumPerms;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Topic controller.
|
* Topic controller.
|
||||||
|
@ -37,7 +35,7 @@ class PostController extends Controller
|
||||||
// Check if the forum exists
|
// Check if the forum exists
|
||||||
if ($post->id === 0
|
if ($post->id === 0
|
||||||
|| $topic->id === 0
|
|| $topic->id === 0
|
||||||
|| !$forum->permission(ForumPerms::VIEW, CurrentSession::$user->id)) {
|
|| !$forum->perms->view) {
|
||||||
throw new HttpRouteNotFoundException();
|
throw new HttpRouteNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,7 +72,7 @@ class PostController extends Controller
|
||||||
// Check if the forum exists
|
// Check if the forum exists
|
||||||
if ($post->id === 0
|
if ($post->id === 0
|
||||||
|| $topic->id === 0
|
|| $topic->id === 0
|
||||||
|| !$forum->permission(ForumPerms::VIEW, CurrentSession::$user->id)) {
|
|| !$forum->perms->view) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,15 +96,15 @@ class PostController extends Controller
|
||||||
// Check permissions
|
// Check permissions
|
||||||
$noAccess = $post->id === 0
|
$noAccess = $post->id === 0
|
||||||
|| $topic->id === 0
|
|| $topic->id === 0
|
||||||
|| !$forum->permission(ForumPerms::VIEW, CurrentSession::$user->id);
|
|| !$forum->perms->view;
|
||||||
|
|
||||||
$noEdit = (
|
$noEdit = (
|
||||||
$post->poster->id === CurrentSession::$user->id
|
$post->poster->id === CurrentSession::$user->id
|
||||||
? !CurrentSession::$user->permission(ForumPerms::EDIT_OWN, Perms::FORUM)
|
? !$forum->perms->edit
|
||||||
: !$forum->permission(ForumPerms::EDIT_ANY, CurrentSession::$user->id)
|
: !$forum->perms->editAny
|
||||||
) || (
|
) || (
|
||||||
$topic->status === 1
|
$topic->status === 1
|
||||||
&& !$forum->permission(ForumPerms::LOCK, CurrentSession::$user->id)
|
&& !$forum->perms->changeStatus
|
||||||
);
|
);
|
||||||
|
|
||||||
// Check if the forum exists
|
// Check if the forum exists
|
||||||
|
@ -195,15 +193,20 @@ class PostController extends Controller
|
||||||
// Check permissions
|
// Check permissions
|
||||||
$noAccess = $post->id === 0
|
$noAccess = $post->id === 0
|
||||||
|| $topic->id === 0
|
|| $topic->id === 0
|
||||||
|| !$forum->permission(ForumPerms::VIEW, CurrentSession::$user->id);
|
|| !$forum->perms->view;
|
||||||
|
|
||||||
|
$replies = $topic->replyCount();
|
||||||
|
|
||||||
$noDelete = (
|
$noDelete = (
|
||||||
$post->poster->id === CurrentSession::$user->id
|
$post->poster->id === CurrentSession::$user->id
|
||||||
? !CurrentSession::$user->permission(ForumPerms::DELETE_OWN, Perms::FORUM)
|
? !$forum->perms->delete
|
||||||
: !$forum->permission(ForumPerms::DELETE_ANY, CurrentSession::$user->id)
|
: !$forum->perms->deleteAny
|
||||||
) || (
|
) || (
|
||||||
$topic->status === 1
|
$topic->status === 1
|
||||||
&& !$forum->permission(ForumPerms::LOCK, CurrentSession::$user->id)
|
&& !$forum->perms->changeStatus
|
||||||
|
) || (
|
||||||
|
$replies === 1 &&
|
||||||
|
!$forum->perms->topicDelete
|
||||||
);
|
);
|
||||||
|
|
||||||
// Check if the forum exists
|
// Check if the forum exists
|
||||||
|
@ -212,7 +215,7 @@ class PostController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the topic only has 1 post
|
// Check if the topic only has 1 post
|
||||||
if ($topic->replyCount() === 1) {
|
if ($replies === 1) {
|
||||||
// Delete the entire topic
|
// Delete the entire topic
|
||||||
$topic->delete();
|
$topic->delete();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -12,7 +12,6 @@ use Sakura\CurrentSession;
|
||||||
use Sakura\Forum\Forum;
|
use Sakura\Forum\Forum;
|
||||||
use Sakura\Forum\Post;
|
use Sakura\Forum\Post;
|
||||||
use Sakura\Forum\Topic;
|
use Sakura\Forum\Topic;
|
||||||
use Sakura\Perms\Forum as ForumPerms;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Topic controller.
|
* Topic controller.
|
||||||
|
@ -34,7 +33,7 @@ class TopicController extends Controller
|
||||||
|
|
||||||
// Check if the forum exists
|
// Check if the forum exists
|
||||||
if ($topic->id === 0
|
if ($topic->id === 0
|
||||||
|| !$forum->permission(ForumPerms::VIEW, CurrentSession::$user->id)) {
|
|| !$forum->perms->view) {
|
||||||
throw new HttpRouteNotFoundException;
|
throw new HttpRouteNotFoundException;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +55,7 @@ class TopicController extends Controller
|
||||||
$forum = new Forum($topic->forum);
|
$forum = new Forum($topic->forum);
|
||||||
|
|
||||||
if ($topic->id !== 0
|
if ($topic->id !== 0
|
||||||
|| $forum->permission(ForumPerms::VIEW, CurrentSession::$user->id)
|
|| $forum->perms->view
|
||||||
|| session_check()) {
|
|| session_check()) {
|
||||||
return compact('topic', 'forum');
|
return compact('topic', 'forum');
|
||||||
}
|
}
|
||||||
|
@ -74,7 +73,7 @@ class TopicController extends Controller
|
||||||
{
|
{
|
||||||
extract($this->modBase($id));
|
extract($this->modBase($id));
|
||||||
|
|
||||||
if (!$forum->permission(ForumPerms::STICKY, CurrentSession::$user->id)) {
|
if (!$forum->perms->changeType) {
|
||||||
throw new HttpMethodNotAllowedException;
|
throw new HttpMethodNotAllowedException;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,7 +93,7 @@ class TopicController extends Controller
|
||||||
{
|
{
|
||||||
extract($this->modBase($id));
|
extract($this->modBase($id));
|
||||||
|
|
||||||
if (!$forum->permission(ForumPerms::ANNOUNCEMENT, CurrentSession::$user->id)) {
|
if (!$forum->perms->changeType) {
|
||||||
throw new HttpMethodNotAllowedException;
|
throw new HttpMethodNotAllowedException;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,7 +113,7 @@ class TopicController extends Controller
|
||||||
{
|
{
|
||||||
extract($this->modBase($id));
|
extract($this->modBase($id));
|
||||||
|
|
||||||
if (!$forum->permission(ForumPerms::LOCK, CurrentSession::$user->id)) {
|
if (!$forum->perms->changeStatus) {
|
||||||
throw new HttpMethodNotAllowedException;
|
throw new HttpMethodNotAllowedException;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,10 +136,10 @@ class TopicController extends Controller
|
||||||
$trash = intval(config('forum.trash'));
|
$trash = intval(config('forum.trash'));
|
||||||
|
|
||||||
if ($topic->forum === $trash
|
if ($topic->forum === $trash
|
||||||
&& $forum->permission(ForumPerms::DELETE_ANY, CurrentSession::$user->id)) {
|
&& $forum->perms->deleteAny) {
|
||||||
$redirect = route('forums.forum', $trash);
|
$redirect = route('forums.forum', $trash);
|
||||||
$topic->delete();
|
$topic->delete();
|
||||||
} elseif ($forum->permission(ForumPerms::MOVE, CurrentSession::$user->id)) {
|
} elseif ($forum->perms->topicMove) {
|
||||||
$redirect = route('forums.topic', $topic->id);
|
$redirect = route('forums.topic', $topic->id);
|
||||||
$topic->move($trash);
|
$topic->move($trash);
|
||||||
} else {
|
} else {
|
||||||
|
@ -160,7 +159,7 @@ class TopicController extends Controller
|
||||||
{
|
{
|
||||||
extract($this->modBase($id));
|
extract($this->modBase($id));
|
||||||
|
|
||||||
if (!$forum->permission(ForumPerms::MOVE, CurrentSession::$user->id)) {
|
if (!$forum->perms->topicMove) {
|
||||||
throw new HttpMethodNotAllowedException;
|
throw new HttpMethodNotAllowedException;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,9 +181,9 @@ class TopicController extends Controller
|
||||||
extract($this->modBase($id));
|
extract($this->modBase($id));
|
||||||
$dest_forum = new Forum($_REQUEST['forum_id'] ?? 0);
|
$dest_forum = new Forum($_REQUEST['forum_id'] ?? 0);
|
||||||
|
|
||||||
if (!$forum->permission(ForumPerms::MOVE, CurrentSession::$user->id)
|
if (!$forum->perms->topicMove
|
||||||
|| $dest_forum->id === 0
|
|| $dest_forum->id === 0
|
||||||
|| $dest_forum->permission(ForumPerms::VIEW, CurrentSession::$user->id)) {
|
|| $dest_forum->perms->view) {
|
||||||
throw new HttpMethodNotAllowedException;
|
throw new HttpMethodNotAllowedException;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -211,7 +210,7 @@ class TopicController extends Controller
|
||||||
// Check if the topic exists
|
// Check if the topic exists
|
||||||
if ($topic->id === 0
|
if ($topic->id === 0
|
||||||
|| $forum->type !== 0
|
|| $forum->type !== 0
|
||||||
|| !$forum->permission(ForumPerms::VIEW, CurrentSession::$user->id)) {
|
|| !$forum->perms->view) {
|
||||||
$message = "This post doesn't exist or you don't have access to it!";
|
$message = "This post doesn't exist or you don't have access to it!";
|
||||||
$redirect = route('forums.index');
|
$redirect = route('forums.index');
|
||||||
|
|
||||||
|
@ -219,10 +218,10 @@ class TopicController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the topic exists
|
// Check if the topic exists
|
||||||
if (!$forum->permission(ForumPerms::REPLY, CurrentSession::$user->id)
|
if (!$forum->perms->reply
|
||||||
|| (
|
|| (
|
||||||
$topic->status === 1
|
$topic->status === 1
|
||||||
&& !$forum->permission(ForumPerms::LOCK, CurrentSession::$user->id)
|
&& !$forum->perms->changeStatus
|
||||||
)) {
|
)) {
|
||||||
$message = "You are not allowed to post in this topic!";
|
$message = "You are not allowed to post in this topic!";
|
||||||
$redirect = route('forums.topic', $topic->id);
|
$redirect = route('forums.topic', $topic->id);
|
||||||
|
@ -292,9 +291,9 @@ class TopicController extends Controller
|
||||||
// Check if the forum exists
|
// Check if the forum exists
|
||||||
if ($forum->id === 0
|
if ($forum->id === 0
|
||||||
|| $forum->type !== 0
|
|| $forum->type !== 0
|
||||||
|| !$forum->permission(ForumPerms::VIEW, CurrentSession::$user->id)
|
|| !$forum->perms->view
|
||||||
|| !$forum->permission(ForumPerms::REPLY, CurrentSession::$user->id)
|
|| !$forum->perms->reply
|
||||||
|| !$forum->permission(ForumPerms::CREATE_THREADS, CurrentSession::$user->id)) {
|
|| !$forum->perms->topicCreate) {
|
||||||
$message = "This forum doesn't exist or you don't have access to it!";
|
$message = "This forum doesn't exist or you don't have access to it!";
|
||||||
$redirect = route('forums.index');
|
$redirect = route('forums.index');
|
||||||
|
|
||||||
|
|
|
@ -122,18 +122,6 @@ class Forum
|
||||||
$this->perms = new ForumPerms($this, CurrentSession::$user);
|
$this->perms = new ForumPerms($this, CurrentSession::$user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checking a permission flag.
|
|
||||||
* @param int $flag
|
|
||||||
* @param int $user
|
|
||||||
* @param bool $raw
|
|
||||||
* @return bool|int
|
|
||||||
*/
|
|
||||||
public function permission($flag, $user, $raw = false)
|
|
||||||
{
|
|
||||||
return $raw ? 1024 : true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets all subforums of this forum.
|
* Gets all subforums of this forum.
|
||||||
* @return array
|
* @return array
|
||||||
|
@ -157,12 +145,9 @@ class Forum
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->forumsCache = $forums;
|
$this->forumsCache = $forums;
|
||||||
} else {
|
|
||||||
$forums = $this->forumsCache;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the forum objects
|
return $this->forumsCache;
|
||||||
return $forums;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
namespace Sakura\Forum;
|
namespace Sakura\Forum;
|
||||||
|
|
||||||
|
use Sakura\DB;
|
||||||
use Sakura\User;
|
use Sakura\User;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -15,14 +16,16 @@ use Sakura\User;
|
||||||
*/
|
*/
|
||||||
class ForumPerms
|
class ForumPerms
|
||||||
{
|
{
|
||||||
private $forum = [];
|
private $forums = [];
|
||||||
private $user = 0;
|
private $user = 0;
|
||||||
private $ranks = [];
|
private $ranks = [];
|
||||||
private $cache = [];
|
private $cache = [];
|
||||||
|
|
||||||
public function __construct(Forum $forum, User $user)
|
public function __construct(Forum $forum, User $user)
|
||||||
{
|
{
|
||||||
//
|
$this->forums = [0, $forum->id, $forum->category];
|
||||||
|
$this->user = $user->id;
|
||||||
|
$this->ranks = array_keys($user->ranks);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __get($name)
|
public function __get($name)
|
||||||
|
@ -31,7 +34,7 @@ class ForumPerms
|
||||||
$column = 'perm_' . camel_to_snake($name);
|
$column = 'perm_' . camel_to_snake($name);
|
||||||
|
|
||||||
$result = array_column(DB::table('forum_perms')
|
$result = array_column(DB::table('forum_perms')
|
||||||
->whereIn('forum_id', $this->forum)
|
->whereIn('forum_id', $this->forums)
|
||||||
->where(function ($query) {
|
->where(function ($query) {
|
||||||
$query->whereIn('rank_id', $this->ranks)
|
$query->whereIn('rank_id', $this->ranks)
|
||||||
->orWhere('user_id', $this->user);
|
->orWhere('user_id', $this->user);
|
||||||
|
|
|
@ -1,70 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* Holds the forum permission flags.
|
|
||||||
* @package Sakura
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Sakura\Perms;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* All forum permission flags.
|
|
||||||
* @package Sakura
|
|
||||||
* @author Julian van de Groep <me@flash.moe>
|
|
||||||
*/
|
|
||||||
class Forum
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Can this user view/read this forum?
|
|
||||||
*/
|
|
||||||
const VIEW = 1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Can this user post/reply in this forum?
|
|
||||||
*/
|
|
||||||
const REPLY = 2;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Can this user create topics in this forum?
|
|
||||||
*/
|
|
||||||
const CREATE_THREADS = 4;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Can this user edit their own posts?
|
|
||||||
*/
|
|
||||||
const EDIT_OWN = 8;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Can this user delete their own posts?
|
|
||||||
*/
|
|
||||||
const DELETE_OWN = 16;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Can this user change topics to the sticky type?
|
|
||||||
*/
|
|
||||||
const STICKY = 32;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Can this user change topics to the announcement type?
|
|
||||||
*/
|
|
||||||
const ANNOUNCEMENT = 64;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Can this user edit any post in this forum?
|
|
||||||
*/
|
|
||||||
const EDIT_ANY = 128;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Can this user delete any post in this forum?
|
|
||||||
*/
|
|
||||||
const DELETE_ANY = 256;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Can this user toggle the locked status on topics in this forum?
|
|
||||||
*/
|
|
||||||
const LOCK = 512;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Can this user move topics to other forums from/to this forum?
|
|
||||||
*/
|
|
||||||
const MOVE = 1024;
|
|
||||||
}
|
|
24
app/Rank.php
24
app/Rank.php
|
@ -6,8 +6,6 @@
|
||||||
|
|
||||||
namespace Sakura;
|
namespace Sakura;
|
||||||
|
|
||||||
use Sakura\Perms;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serves Rank data.
|
* Serves Rank data.
|
||||||
* @package Sakura
|
* @package Sakura
|
||||||
|
@ -63,12 +61,6 @@ class Rank
|
||||||
*/
|
*/
|
||||||
private $hidden = true;
|
private $hidden = true;
|
||||||
|
|
||||||
/**
|
|
||||||
* Permission container.
|
|
||||||
* @var Perms
|
|
||||||
*/
|
|
||||||
private $permissions;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instance cache container.
|
* Instance cache container.
|
||||||
* @var array
|
* @var array
|
||||||
|
@ -136,22 +128,6 @@ class Rank
|
||||||
return $this->hidden;
|
return $this->hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Check permissions.
|
|
||||||
* @param int $flag
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function permission($flag)
|
|
||||||
{
|
|
||||||
// Set default permission value
|
|
||||||
$perm = 0;
|
|
||||||
|
|
||||||
// Bitwise OR it with the permissions for this forum
|
|
||||||
$perm = $perm | $this->permissions->rank($this->id);
|
|
||||||
|
|
||||||
return $this->permissions->check($flag, $perm);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns all users that are part of this rank.
|
* Returns all users that are part of this rank.
|
||||||
* @param bool $justIds
|
* @param bool $justIds
|
||||||
|
|
21
app/User.php
21
app/User.php
|
@ -11,7 +11,6 @@ use LastFmApi\Api\AuthApi;
|
||||||
use LastFmApi\Api\UserApi;
|
use LastFmApi\Api\UserApi;
|
||||||
use LastFmApi\Exception\LastFmApiExeption;
|
use LastFmApi\Exception\LastFmApiExeption;
|
||||||
use Sakura\Exceptions\NetAddressTypeException;
|
use Sakura\Exceptions\NetAddressTypeException;
|
||||||
use Sakura\Perms;
|
|
||||||
use stdClass;
|
use stdClass;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -818,26 +817,6 @@ class User
|
||||||
return $objects;
|
return $objects;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if the user has a certaing permission flag.
|
|
||||||
* @param int $flag
|
|
||||||
* @param string $mode
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function permission($flag, $mode = null)
|
|
||||||
{
|
|
||||||
// Set mode
|
|
||||||
$this->permissions->mode($mode ? $mode : Perms::SITE);
|
|
||||||
|
|
||||||
// Set default permission value
|
|
||||||
$perm = 0;
|
|
||||||
|
|
||||||
// Bitwise OR it with the permissions for this forum
|
|
||||||
$perm = $this->permissions->user($this->id);
|
|
||||||
|
|
||||||
return $this->permissions->check($flag, $perm);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the comments from the user's profile.
|
* Get the comments from the user's profile.
|
||||||
* @return array
|
* @return array
|
||||||
|
|
|
@ -24,6 +24,9 @@ class RestructurePermissions extends Migration
|
||||||
->default(0);
|
->default(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$schema->drop('forum_permissions');
|
||||||
|
$schema->drop('permissions');
|
||||||
|
|
||||||
$schema->create('perms', function (Blueprint $table) {
|
$schema->create('perms', function (Blueprint $table) {
|
||||||
$table->integer('user_id')->default(0);
|
$table->integer('user_id')->default(0);
|
||||||
$table->integer('rank_id')->default(0);
|
$table->integer('rank_id')->default(0);
|
||||||
|
@ -88,8 +91,41 @@ class RestructurePermissions extends Migration
|
||||||
public function down()
|
public function down()
|
||||||
{
|
{
|
||||||
$schema = DB::getSchemaBuilder();
|
$schema = DB::getSchemaBuilder();
|
||||||
|
|
||||||
$schema->drop('forum_perms');
|
$schema->drop('forum_perms');
|
||||||
$schema->drop('perms');
|
$schema->drop('perms');
|
||||||
|
|
||||||
|
$schema->create('permissions', function (Blueprint $table) {
|
||||||
|
$table->integer('rank_id')
|
||||||
|
->unsigned()
|
||||||
|
->default(0);
|
||||||
|
|
||||||
|
$table->integer('user_id')
|
||||||
|
->unsigned()
|
||||||
|
->default(0);
|
||||||
|
|
||||||
|
$table->string('permissions_site', 255)
|
||||||
|
->default(0);
|
||||||
|
|
||||||
|
$table->string('permissions_manage', 255)
|
||||||
|
->default(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
$schema->create('forum_permissions', function (Blueprint $table) {
|
||||||
|
$table->integer('forum_id')
|
||||||
|
->unsigned();
|
||||||
|
|
||||||
|
$table->integer('rank_id')
|
||||||
|
->unsigned()
|
||||||
|
->default(0);
|
||||||
|
|
||||||
|
$table->integer('user_id')
|
||||||
|
->unsigned()
|
||||||
|
->default(0);
|
||||||
|
|
||||||
|
$table->string('forum_perms', 255);
|
||||||
|
});
|
||||||
|
|
||||||
$schema->table('users', function (Blueprint $table) {
|
$schema->table('users', function (Blueprint $table) {
|
||||||
$table->dropColumn([
|
$table->dropColumn([
|
||||||
'user_activated',
|
'user_activated',
|
||||||
|
|
|
@ -55,8 +55,8 @@ namespace Sakura
|
||||||
element.parentNode.removeChild(element);
|
element.parentNode.removeChild(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Class(className: string): NodeListOf<HTMLElement> {
|
public static Class(className: string): HTMLCollectionOf<HTMLElement> {
|
||||||
return <NodeListOf<HTMLElement>>document.getElementsByClassName(className);
|
return <HTMLCollectionOf<HTMLElement>>document.getElementsByClassName(className);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Prepend(target: HTMLElement, element: HTMLElement | Text, before: HTMLElement | Node = null): void {
|
public static Prepend(target: HTMLElement, element: HTMLElement | Text, before: HTMLElement | Node = null): void {
|
||||||
|
|
|
@ -28,7 +28,7 @@ namespace Sakura
|
||||||
return none;
|
return none;
|
||||||
}
|
}
|
||||||
|
|
||||||
var times: Object = {
|
var times: any = {
|
||||||
31536000: ['year', 'a'],
|
31536000: ['year', 'a'],
|
||||||
2592000: ['month', 'a'],
|
2592000: ['month', 'a'],
|
||||||
604800: ['week', 'a'],
|
604800: ['week', 'a'],
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
<div class="head">{{ title }}</div>
|
<div class="head">{{ title }}</div>
|
||||||
<div class="forumList">
|
<div class="forumList">
|
||||||
{% for forum in forum.forums %}
|
{% for forum in forum.forums %}
|
||||||
|
{{ forum.perms.view ? 'yay' : 'no'}}
|
||||||
{% if forum.type == 1 %}
|
{% if forum.type == 1 %}
|
||||||
{% if forum.forums|length and forum.permission(constant('Sakura\\Perms\\Forum::VIEW'), user.id) %}
|
{% if forum.forums|length and forum.perms.view %}
|
||||||
<div class="forumCategory">
|
<div class="forumCategory">
|
||||||
{% if forum.type != 1 %}Subforums{% else %}<a href="{{ route('forums.forum', forum.id) }}" class="clean">{{ forum.name }}</a>{% endif %}
|
{% if forum.type != 1 %}Subforums{% else %}<a href="{{ route('forums.forum', forum.id) }}" class="clean">{{ forum.name }}</a>{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
{% if forum.permission(constant('Sakura\\Perms\\Forum::VIEW'), user.id) %}
|
{% if forum.perms.view %}
|
||||||
<div class="forumForum">
|
<div class="forumForum">
|
||||||
<div class="forumIcon {% if forum.unread(user.id) %}unread {% endif %}fa fa-3x {% if forum.icon %}{{ forum.icon }}{% else %}{% if forum.type == 2 %}fa-chevron-circle-right{% elseif forum.type == 1 %}fa-folder{% else %}fa-comments{% endif %}{% endif %}"></div>
|
<div class="forumIcon {% if forum.unread(user.id) %}unread {% endif %}fa fa-3x {% if forum.icon %}{{ forum.icon }}{% else %}{% if forum.type == 2 %}fa-chevron-circle-right{% elseif forum.type == 1 %}fa-folder{% else %}fa-comments{% endif %}{% endif %}"></div>
|
||||||
<div class="forumTitle">
|
<div class="forumTitle">
|
||||||
|
|
|
@ -5,35 +5,31 @@
|
||||||
{% set title %}{% if topic is defined %}{{ topic.title }}{% else %}Creating topic in {{ forum.name }}{% endif %}{% endset %}
|
{% set title %}{% if topic is defined %}{{ topic.title }}{% else %}Creating topic in {{ forum.name }}{% endif %}{% endset %}
|
||||||
|
|
||||||
{% if topic is defined %}
|
{% if topic is defined %}
|
||||||
{% if forum.permission(constant('Sakura\\Perms\\Forum::REPLY'), user.id)
|
{% if forum.perms.reply
|
||||||
and (
|
and (
|
||||||
topic.status != 1
|
topic.status != 1
|
||||||
or forum.permission(constant('Sakura\\Perms\\Forum::LOCK'), user.id)
|
or forum.perms.changeStatus
|
||||||
) %}
|
) %}
|
||||||
{% set forumReplyLink %}#reply{% endset %}
|
{% set forumReplyLink %}#reply{% endset %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if forum.permission(constant('Sakura\\Perms\\Forum::STICKY'), user.id)
|
{% if forum.perms.changeType
|
||||||
or forum.permission(constant('Sakura\\Perms\\Forum::ANNOUNCEMENT'), user.id)
|
or forum.perms.changeStatus
|
||||||
or forum.permission(constant('Sakura\\Perms\\Forum::LOCK'), user.id)
|
or forum.perms.topicMove
|
||||||
or forum.permission(constant('Sakura\\Perms\\Forum::MOVE'), user.id)
|
or forum.perms.deleteAny %}
|
||||||
or forum.permission(constant('Sakura\\Perms\\Forum::DELETE_ANY'), user.id) %}
|
|
||||||
{% set showMod = true %}
|
{% set showMod = true %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if forum.permission(constant('Sakura\\Perms\\Forum::STICKY'), user.id) %}
|
{% if forum.perms.changeType %}
|
||||||
{% set forumSticky = topic.type == 1 ? true : false %}
|
{% set forumSticky = topic.type == 1 ? true : false %}
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if forum.permission(constant('Sakura\\Perms\\Forum::ANNOUNCEMENT'), user.id) %}
|
|
||||||
{% set forumAnnounce = topic.type == 2 ? true : false %}
|
{% set forumAnnounce = topic.type == 2 ? true : false %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if forum.permission(constant('Sakura\\Perms\\Forum::LOCK'), user.id) %}
|
{% if forum.perms.changeStatus %}
|
||||||
{% set forumLock = topic.status == 1 ? true : false %}
|
{% set forumLock = topic.status == 1 ? true : false %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if forum.permission(constant('Sakura\\Perms\\Forum::MOVE'), user.id) %}
|
{% if forum.perms.topicMove %}
|
||||||
{% if topic.oldForum %}
|
{% if topic.oldForum %}
|
||||||
{% set forumRestore = true %}
|
{% set forumRestore = true %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -43,7 +39,7 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if forum.permission(constant('Sakura\\Perms\\Forum::DELETE_ANY'), user.id) %}
|
{% if forum.perms.deleteAny %}
|
||||||
{% if topic.forum == config('forum.trash') %}
|
{% if topic.forum == config('forum.trash') %}
|
||||||
{% set forumPrune = true %}
|
{% set forumPrune = true %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -116,10 +112,10 @@
|
||||||
<img src="/images/tenshi.png" alt="Tenshi"{% if not post.poster.isPremium %} style="opacity: 0;"{% endif %}> <img src="/images/flags/{{ post.poster.country|lower }}.png" alt="{{ post.poster.country(true) }}">{% if post.poster.id == (topic.posts|first).poster.id %} <img src="/images/op.png" alt="OP" title="Original Poster">{% endif %}
|
<img src="/images/tenshi.png" alt="Tenshi"{% if not post.poster.isPremium %} style="opacity: 0;"{% endif %}> <img src="/images/flags/{{ post.poster.country|lower }}.png" alt="{{ post.poster.country(true) }}">{% if post.poster.id == (topic.posts|first).poster.id %} <img src="/images/op.png" alt="OP" title="Original Poster">{% endif %}
|
||||||
{% if user.isActive %}
|
{% if user.isActive %}
|
||||||
<div class="actions">
|
<div class="actions">
|
||||||
{% if (user.id == post.poster.id and forum.permission(constant('Sakura\\Perms\\Forum::EDIT_OWN'), user.id)) or forum.permission(constant('Sakura\\Perms\\Forum::EDIT_ANY'), user.id) %}
|
{% if (user.id == post.poster.id and forum.perms.edit) or forum.perms.editAny %}
|
||||||
<a class="fa fa-pencil-square-o" title="Edit this post" href="javascript:void(0);" onclick="editPost({{ post.id }});"></a>
|
<a class="fa fa-pencil-square-o" title="Edit this post" href="javascript:void(0);" onclick="editPost({{ post.id }});"></a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if (user.id == post.poster.id and forum.permission(constant('Sakura\\Perms\\Forum::DELETE_OWN'), user.id)) or forum.permission(constant('Sakura\\Perms\\Forum::DELETE_ANY'), user.id) %}
|
{% if (user.id == post.poster.id and forum.perms.delete) or forum.perms.deleteAny %}
|
||||||
<a class="fa fa-trash" title="Delete this post" href="javascript:;" onclick="deletePost({{ post.id }})"></a>
|
<a class="fa fa-trash" title="Delete this post" href="javascript:;" onclick="deletePost({{ post.id }})"></a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if not (post.poster.activated or post.poster.restricted or user.id == post.poster.id) %}
|
{% if not (post.poster.activated or post.poster.restricted or user.id == post.poster.id) %}
|
||||||
|
|
Reference in a new issue