more shit

This commit is contained in:
flash 2016-11-02 19:58:51 +01:00
parent 8b6bb48231
commit 83632168d4
16 changed files with 98 additions and 193 deletions

View file

@ -9,7 +9,6 @@ namespace Sakura\BBCode\Tags;
use Sakura\BBCode\TagBase;
use Sakura\Forum\Forum;
use Sakura\Forum\Post;
use Sakura\Perms\Forum as ForumPerms;
use Sakura\User;
/**
@ -36,7 +35,7 @@ class NamedQuote extends TagBase
$post = new Post(intval($matches[2]));
$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);
$quoting = "<a href='{$link}' style='color: {$post->poster->colour}' class='bbcode__quote-post'>{$post->poster->username}</a>";

View file

@ -238,7 +238,6 @@ class SetupCommand extends Command
[
'forum_id' => 1,
'rank_id' => config('rank.regular'),
'forum_perms' => '00000011111',
'perm_view' => true,
'perm_reply' => true,
'perm_topic_create' => true,

View file

@ -14,7 +14,6 @@ use Sakura\DB;
use Sakura\Forum\Forum;
use Sakura\Forum\Post;
use Sakura\Forum\Topic;
use Sakura\Perms\Forum as ForumPerms;
use Sakura\User;
/**
@ -45,7 +44,7 @@ class ForumController extends Controller
$forum = new Forum($topic->forum);
// Check if we have permission to view it
if (!$forum->permission(ForumPerms::VIEW, CurrentSession::$user->id)) {
if (!$forum->perms->view) {
$fetch = DB::table('posts')
->groupBy('topic_id')
->orderByRaw('COUNT(*) DESC')
@ -75,7 +74,7 @@ class ForumController extends Controller
$forum = new Forum($post->forum);
// Check if we have permission to view it
if (!$forum->permission(ForumPerms::VIEW, CurrentSession::$user->id)) {
if (!$forum->perms->view) {
$fetch = DB::table('posts')
->orderBy('post_id', 'desc')
->skip(11 + $_n)
@ -124,7 +123,7 @@ class ForumController extends Controller
// Check if the forum exists
if ($forum->id < 0
|| !$forum->permission(ForumPerms::VIEW, CurrentSession::$user->id)) {
|| !$forum->perms->view) {
throw new HttpRouteNotFoundException();
}
@ -152,7 +151,7 @@ class ForumController extends Controller
// Check if the forum exists
if ($forum->id < 1
|| !$forum->permission(ForumPerms::VIEW, CurrentSession::$user->id)) {
|| !$forum->perms->view) {
throw new HttpRouteNotFoundException();
}

View file

@ -13,8 +13,6 @@ use Sakura\DB;
use Sakura\Forum\Forum;
use Sakura\Forum\Post;
use Sakura\Forum\Topic;
use Sakura\Perms;
use Sakura\Perms\Forum as ForumPerms;
/**
* Topic controller.
@ -37,7 +35,7 @@ class PostController extends Controller
// Check if the forum exists
if ($post->id === 0
|| $topic->id === 0
|| !$forum->permission(ForumPerms::VIEW, CurrentSession::$user->id)) {
|| !$forum->perms->view) {
throw new HttpRouteNotFoundException();
}
@ -74,7 +72,7 @@ class PostController extends Controller
// Check if the forum exists
if ($post->id === 0
|| $topic->id === 0
|| !$forum->permission(ForumPerms::VIEW, CurrentSession::$user->id)) {
|| !$forum->perms->view) {
return "";
}
@ -98,15 +96,15 @@ class PostController extends Controller
// Check permissions
$noAccess = $post->id === 0
|| $topic->id === 0
|| !$forum->permission(ForumPerms::VIEW, CurrentSession::$user->id);
|| !$forum->perms->view;
$noEdit = (
$post->poster->id === CurrentSession::$user->id
? !CurrentSession::$user->permission(ForumPerms::EDIT_OWN, Perms::FORUM)
: !$forum->permission(ForumPerms::EDIT_ANY, CurrentSession::$user->id)
? !$forum->perms->edit
: !$forum->perms->editAny
) || (
$topic->status === 1
&& !$forum->permission(ForumPerms::LOCK, CurrentSession::$user->id)
&& !$forum->perms->changeStatus
);
// Check if the forum exists
@ -195,15 +193,20 @@ class PostController extends Controller
// Check permissions
$noAccess = $post->id === 0
|| $topic->id === 0
|| !$forum->permission(ForumPerms::VIEW, CurrentSession::$user->id);
|| !$forum->perms->view;
$replies = $topic->replyCount();
$noDelete = (
$post->poster->id === CurrentSession::$user->id
? !CurrentSession::$user->permission(ForumPerms::DELETE_OWN, Perms::FORUM)
: !$forum->permission(ForumPerms::DELETE_ANY, CurrentSession::$user->id)
? !$forum->perms->delete
: !$forum->perms->deleteAny
) || (
$topic->status === 1
&& !$forum->permission(ForumPerms::LOCK, CurrentSession::$user->id)
&& !$forum->perms->changeStatus
) || (
$replies === 1 &&
!$forum->perms->topicDelete
);
// Check if the forum exists
@ -212,7 +215,7 @@ class PostController extends Controller
}
// Check if the topic only has 1 post
if ($topic->replyCount() === 1) {
if ($replies === 1) {
// Delete the entire topic
$topic->delete();
} else {

View file

@ -12,7 +12,6 @@ use Sakura\CurrentSession;
use Sakura\Forum\Forum;
use Sakura\Forum\Post;
use Sakura\Forum\Topic;
use Sakura\Perms\Forum as ForumPerms;
/**
* Topic controller.
@ -34,7 +33,7 @@ class TopicController extends Controller
// Check if the forum exists
if ($topic->id === 0
|| !$forum->permission(ForumPerms::VIEW, CurrentSession::$user->id)) {
|| !$forum->perms->view) {
throw new HttpRouteNotFoundException;
}
@ -56,7 +55,7 @@ class TopicController extends Controller
$forum = new Forum($topic->forum);
if ($topic->id !== 0
|| $forum->permission(ForumPerms::VIEW, CurrentSession::$user->id)
|| $forum->perms->view
|| session_check()) {
return compact('topic', 'forum');
}
@ -74,7 +73,7 @@ class TopicController extends Controller
{
extract($this->modBase($id));
if (!$forum->permission(ForumPerms::STICKY, CurrentSession::$user->id)) {
if (!$forum->perms->changeType) {
throw new HttpMethodNotAllowedException;
}
@ -94,7 +93,7 @@ class TopicController extends Controller
{
extract($this->modBase($id));
if (!$forum->permission(ForumPerms::ANNOUNCEMENT, CurrentSession::$user->id)) {
if (!$forum->perms->changeType) {
throw new HttpMethodNotAllowedException;
}
@ -114,7 +113,7 @@ class TopicController extends Controller
{
extract($this->modBase($id));
if (!$forum->permission(ForumPerms::LOCK, CurrentSession::$user->id)) {
if (!$forum->perms->changeStatus) {
throw new HttpMethodNotAllowedException;
}
@ -137,10 +136,10 @@ class TopicController extends Controller
$trash = intval(config('forum.trash'));
if ($topic->forum === $trash
&& $forum->permission(ForumPerms::DELETE_ANY, CurrentSession::$user->id)) {
&& $forum->perms->deleteAny) {
$redirect = route('forums.forum', $trash);
$topic->delete();
} elseif ($forum->permission(ForumPerms::MOVE, CurrentSession::$user->id)) {
} elseif ($forum->perms->topicMove) {
$redirect = route('forums.topic', $topic->id);
$topic->move($trash);
} else {
@ -160,7 +159,7 @@ class TopicController extends Controller
{
extract($this->modBase($id));
if (!$forum->permission(ForumPerms::MOVE, CurrentSession::$user->id)) {
if (!$forum->perms->topicMove) {
throw new HttpMethodNotAllowedException;
}
@ -182,9 +181,9 @@ class TopicController extends Controller
extract($this->modBase($id));
$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->permission(ForumPerms::VIEW, CurrentSession::$user->id)) {
|| $dest_forum->perms->view) {
throw new HttpMethodNotAllowedException;
}
@ -211,7 +210,7 @@ class TopicController extends Controller
// Check if the topic exists
if ($topic->id === 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!";
$redirect = route('forums.index');
@ -219,10 +218,10 @@ class TopicController extends Controller
}
// Check if the topic exists
if (!$forum->permission(ForumPerms::REPLY, CurrentSession::$user->id)
if (!$forum->perms->reply
|| (
$topic->status === 1
&& !$forum->permission(ForumPerms::LOCK, CurrentSession::$user->id)
&& !$forum->perms->changeStatus
)) {
$message = "You are not allowed to post in this topic!";
$redirect = route('forums.topic', $topic->id);
@ -292,9 +291,9 @@ class TopicController extends Controller
// Check if the forum exists
if ($forum->id === 0
|| $forum->type !== 0
|| !$forum->permission(ForumPerms::VIEW, CurrentSession::$user->id)
|| !$forum->permission(ForumPerms::REPLY, CurrentSession::$user->id)
|| !$forum->permission(ForumPerms::CREATE_THREADS, CurrentSession::$user->id)) {
|| !$forum->perms->view
|| !$forum->perms->reply
|| !$forum->perms->topicCreate) {
$message = "This forum doesn't exist or you don't have access to it!";
$redirect = route('forums.index');

View file

@ -122,18 +122,6 @@ class Forum
$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.
* @return array
@ -157,12 +145,9 @@ class Forum
}
$this->forumsCache = $forums;
} else {
$forums = $this->forumsCache;
}
// Return the forum objects
return $forums;
return $this->forumsCache;
}
/**

View file

@ -6,6 +6,7 @@
namespace Sakura\Forum;
use Sakura\DB;
use Sakura\User;
/**
@ -15,14 +16,16 @@ use Sakura\User;
*/
class ForumPerms
{
private $forum = [];
private $forums = [];
private $user = 0;
private $ranks = [];
private $cache = [];
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)
@ -31,7 +34,7 @@ class ForumPerms
$column = 'perm_' . camel_to_snake($name);
$result = array_column(DB::table('forum_perms')
->whereIn('forum_id', $this->forum)
->whereIn('forum_id', $this->forums)
->where(function ($query) {
$query->whereIn('rank_id', $this->ranks)
->orWhere('user_id', $this->user);

View file

@ -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;
}

View file

@ -6,8 +6,6 @@
namespace Sakura;
use Sakura\Perms;
/**
* Serves Rank data.
* @package Sakura
@ -63,12 +61,6 @@ class Rank
*/
private $hidden = true;
/**
* Permission container.
* @var Perms
*/
private $permissions;
/**
* Instance cache container.
* @var array
@ -136,22 +128,6 @@ class Rank
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.
* @param bool $justIds

View file

@ -11,7 +11,6 @@ use LastFmApi\Api\AuthApi;
use LastFmApi\Api\UserApi;
use LastFmApi\Exception\LastFmApiExeption;
use Sakura\Exceptions\NetAddressTypeException;
use Sakura\Perms;
use stdClass;
/**
@ -818,26 +817,6 @@ class User
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.
* @return array

View file

@ -24,6 +24,9 @@ class RestructurePermissions extends Migration
->default(0);
});
$schema->drop('forum_permissions');
$schema->drop('permissions');
$schema->create('perms', function (Blueprint $table) {
$table->integer('user_id')->default(0);
$table->integer('rank_id')->default(0);
@ -88,8 +91,41 @@ class RestructurePermissions extends Migration
public function down()
{
$schema = DB::getSchemaBuilder();
$schema->drop('forum_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) {
$table->dropColumn([
'user_activated',

View file

@ -55,8 +55,8 @@ namespace Sakura
element.parentNode.removeChild(element);
}
public static Class(className: string): NodeListOf<HTMLElement> {
return <NodeListOf<HTMLElement>>document.getElementsByClassName(className);
public static Class(className: string): HTMLCollectionOf<HTMLElement> {
return <HTMLCollectionOf<HTMLElement>>document.getElementsByClassName(className);
}
public static Prepend(target: HTMLElement, element: HTMLElement | Text, before: HTMLElement | Node = null): void {

View file

@ -28,7 +28,7 @@ namespace Sakura
return none;
}
var times: Object = {
var times: any = {
31536000: ['year', 'a'],
2592000: ['month', 'a'],
604800: ['week', 'a'],

View file

@ -1,8 +1,9 @@
<div class="head">{{ title }}</div>
<div class="forumList">
{% for forum in forum.forums %}
{{ forum.perms.view ? 'yay' : 'no'}}
{% 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">
{% if forum.type != 1 %}Subforums{% else %}<a href="{{ route('forums.forum', forum.id) }}" class="clean">{{ forum.name }}</a>{% endif %}
</div>

View file

@ -1,4 +1,4 @@
{% if forum.permission(constant('Sakura\\Perms\\Forum::VIEW'), user.id) %}
{% if forum.perms.view %}
<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="forumTitle">

View file

@ -5,35 +5,31 @@
{% set title %}{% if topic is defined %}{{ topic.title }}{% else %}Creating topic in {{ forum.name }}{% endif %}{% endset %}
{% if topic is defined %}
{% if forum.permission(constant('Sakura\\Perms\\Forum::REPLY'), user.id)
{% if forum.perms.reply
and (
topic.status != 1
or forum.permission(constant('Sakura\\Perms\\Forum::LOCK'), user.id)
or forum.perms.changeStatus
) %}
{% set forumReplyLink %}#reply{% endset %}
{% endif %}
{% if forum.permission(constant('Sakura\\Perms\\Forum::STICKY'), user.id)
or forum.permission(constant('Sakura\\Perms\\Forum::ANNOUNCEMENT'), user.id)
or forum.permission(constant('Sakura\\Perms\\Forum::LOCK'), user.id)
or forum.permission(constant('Sakura\\Perms\\Forum::MOVE'), user.id)
or forum.permission(constant('Sakura\\Perms\\Forum::DELETE_ANY'), user.id) %}
{% if forum.perms.changeType
or forum.perms.changeStatus
or forum.perms.topicMove
or forum.perms.deleteAny %}
{% set showMod = true %}
{% endif %}
{% if forum.permission(constant('Sakura\\Perms\\Forum::STICKY'), user.id) %}
{% if forum.perms.changeType %}
{% 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 %}
{% endif %}
{% if forum.permission(constant('Sakura\\Perms\\Forum::LOCK'), user.id) %}
{% if forum.perms.changeStatus %}
{% set forumLock = topic.status == 1 ? true : false %}
{% endif %}
{% if forum.permission(constant('Sakura\\Perms\\Forum::MOVE'), user.id) %}
{% if forum.perms.topicMove %}
{% if topic.oldForum %}
{% set forumRestore = true %}
{% endif %}
@ -43,7 +39,7 @@
{% endif %}
{% endif %}
{% if forum.permission(constant('Sakura\\Perms\\Forum::DELETE_ANY'), user.id) %}
{% if forum.perms.deleteAny %}
{% if topic.forum == config('forum.trash') %}
{% set forumPrune = true %}
{% 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 %}
{% if user.isActive %}
<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>
{% 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>
{% endif %}
{% if not (post.poster.activated or post.poster.restricted or user.id == post.poster.id) %}