Fixed privileges
This commit is contained in:
parent
0cfb7b821d
commit
4c458d8b20
9 changed files with 39 additions and 19 deletions
|
@ -25,6 +25,7 @@ needEmailActivationToRegister = 1
|
||||||
[security.privileges]
|
[security.privileges]
|
||||||
register = anonymous
|
register = anonymous
|
||||||
listUsers = regularUser, powerUser, moderator, administrator
|
listUsers = regularUser, powerUser, moderator, administrator
|
||||||
|
viewUsers = regularUser, powerUser, moderator, administrator
|
||||||
deleteOwnAccount = regularUser, powerUser, moderator, administrator
|
deleteOwnAccount = regularUser, powerUser, moderator, administrator
|
||||||
deleteAllAccounts = administrator
|
deleteAllAccounts = administrator
|
||||||
changeOwnName = regularUser, powerUser, moderator, administrator
|
changeOwnName = regularUser, powerUser, moderator, administrator
|
||||||
|
@ -40,9 +41,8 @@ changeAccessRank = administrator
|
||||||
viewAllEmailAddresses = moderator, administrator
|
viewAllEmailAddresses = moderator, administrator
|
||||||
ban = moderator, administrator
|
ban = moderator, administrator
|
||||||
|
|
||||||
listSafePosts = anonymous, regularUser, powerUser, moderator, administrator
|
listPosts = anonymous, regularUser, powerUser, moderator, administrator
|
||||||
listSketchyPosts = anonymous, regularUser, powerUser, moderator, administrator
|
viewPosts = anonymous, regularUser, powerUser, moderator, administrator
|
||||||
listUnsafePosts = anonymous, regularUser, powerUser, moderator, administrator
|
|
||||||
uploadPosts = regularUser, powerUser, moderator, administrator
|
uploadPosts = regularUser, powerUser, moderator, administrator
|
||||||
uploadPostsAnonymously = regularUser, powerUser, moderator, administrator
|
uploadPostsAnonymously = regularUser, powerUser, moderator, administrator
|
||||||
deletePosts = moderator, administrator
|
deletePosts = moderator, administrator
|
||||||
|
|
|
@ -5,6 +5,7 @@ App.Auth = function(_, jQuery, util, api, appState, promise) {
|
||||||
var privileges = {
|
var privileges = {
|
||||||
register: 'register',
|
register: 'register',
|
||||||
listUsers: 'listUsers',
|
listUsers: 'listUsers',
|
||||||
|
viewUsers: 'viewUsers',
|
||||||
viewAllEmailAddresses: 'viewAllEmailAddresses',
|
viewAllEmailAddresses: 'viewAllEmailAddresses',
|
||||||
changeAccessRank: 'changeAccessRank',
|
changeAccessRank: 'changeAccessRank',
|
||||||
changeOwnAvatarStyle: 'changeOwnAvatarStyle',
|
changeOwnAvatarStyle: 'changeOwnAvatarStyle',
|
||||||
|
@ -19,9 +20,8 @@ App.Auth = function(_, jQuery, util, api, appState, promise) {
|
||||||
deleteAllAccounts: 'deleteAllAccounts',
|
deleteAllAccounts: 'deleteAllAccounts',
|
||||||
ban: 'ban',
|
ban: 'ban',
|
||||||
|
|
||||||
listSafePosts: 'listSafePosts',
|
listPosts: 'listPosts',
|
||||||
listSketchyPosts: 'listSketchyPosts',
|
viewPosts: 'viewPosts',
|
||||||
listUnsafePosts: 'listUnsafePosts',
|
|
||||||
uploadPosts: 'uploadPosts',
|
uploadPosts: 'uploadPosts',
|
||||||
uploadPostsAnonymously: 'uploadPostsAnonymously',
|
uploadPostsAnonymously: 'uploadPostsAnonymously',
|
||||||
deletePosts: 'deletePosts',
|
deletePosts: 'deletePosts',
|
||||||
|
|
|
@ -7,6 +7,7 @@ App.Presenters.HomePresenter = function(
|
||||||
util,
|
util,
|
||||||
promise,
|
promise,
|
||||||
api,
|
api,
|
||||||
|
auth,
|
||||||
topNavigationPresenter,
|
topNavigationPresenter,
|
||||||
messagePresenter) {
|
messagePresenter) {
|
||||||
|
|
||||||
|
@ -50,6 +51,8 @@ App.Presenters.HomePresenter = function(
|
||||||
postContentTemplate: postContentTemplate,
|
postContentTemplate: postContentTemplate,
|
||||||
globals: globals,
|
globals: globals,
|
||||||
title: topNavigationPresenter.getBaseTitle(),
|
title: topNavigationPresenter.getBaseTitle(),
|
||||||
|
canViewUsers: auth.hasPrivilege(auth.privileges.viewUsers),
|
||||||
|
canViewPosts: auth.hasPrivilege(auth.privileges.viewPosts),
|
||||||
formatRelativeTime: util.formatRelativeTime,
|
formatRelativeTime: util.formatRelativeTime,
|
||||||
formatFileSize: util.formatFileSize,
|
formatFileSize: util.formatFileSize,
|
||||||
}));
|
}));
|
||||||
|
@ -62,4 +65,4 @@ App.Presenters.HomePresenter = function(
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
App.DI.register('homePresenter', ['_', 'jQuery', 'util', 'promise', 'api', 'topNavigationPresenter', 'messagePresenter'], App.Presenters.HomePresenter);
|
App.DI.register('homePresenter', ['_', 'jQuery', 'util', 'promise', 'api', 'auth', 'topNavigationPresenter', 'messagePresenter'], App.Presenters.HomePresenter);
|
||||||
|
|
|
@ -79,7 +79,7 @@ App.Presenters.PostPresenter = function(
|
||||||
topNavigationPresenter.changeTitle('@' + post.id);
|
topNavigationPresenter.changeTitle('@' + post.id);
|
||||||
render();
|
render();
|
||||||
loaded();
|
loaded();
|
||||||
});
|
}).fail(loaded);
|
||||||
}
|
}
|
||||||
|
|
||||||
function refreshPost() {
|
function refreshPost() {
|
||||||
|
@ -344,6 +344,9 @@ App.Presenters.PostPresenter = function(
|
||||||
}
|
}
|
||||||
|
|
||||||
function showGenericError(response) {
|
function showGenericError(response) {
|
||||||
|
if ($messages === $el) {
|
||||||
|
$el.empty();
|
||||||
|
}
|
||||||
messagePresenter.showError($messages, response.json && response.json.error || response);
|
messagePresenter.showError($messages, response.json && response.json.error || response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,9 +38,7 @@ App.Presenters.TopNavigationPresenter = function(
|
||||||
loggedIn: auth.isLoggedIn(),
|
loggedIn: auth.isLoggedIn(),
|
||||||
user: auth.getCurrentUser(),
|
user: auth.getCurrentUser(),
|
||||||
canListUsers: auth.hasPrivilege(auth.privileges.listUsers),
|
canListUsers: auth.hasPrivilege(auth.privileges.listUsers),
|
||||||
canListPosts: auth.hasPrivilege(auth.privileges.listSafePosts) ||
|
canListPosts: auth.hasPrivilege(auth.privileges.listPosts),
|
||||||
auth.hasPrivilege(auth.privileges.listSketchyPosts) ||
|
|
||||||
auth.hasPrivilege(auth.privileges.listUnsafePosts),
|
|
||||||
canListTags: auth.hasPrivilege(auth.privileges.listTags),
|
canListTags: auth.hasPrivilege(auth.privileges.listTags),
|
||||||
canUploadPosts: auth.hasPrivilege(auth.privileges.uploadPosts),
|
canUploadPosts: auth.hasPrivilege(auth.privileges.uploadPosts),
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -10,9 +10,17 @@
|
||||||
<div class="post-footer">
|
<div class="post-footer">
|
||||||
|
|
||||||
<span class="left">
|
<span class="left">
|
||||||
<a href="#/post/<%= post.id %>">
|
<% var showLink = canViewPosts %>
|
||||||
<%= post.idMarkdown %>
|
|
||||||
</a>
|
<% if (showLink) { %>
|
||||||
|
<a href="#/post/<%= post.id %>">
|
||||||
|
<% } %>
|
||||||
|
|
||||||
|
<%= post.idMarkdown %>
|
||||||
|
|
||||||
|
<% if (showLink) { %>
|
||||||
|
</a>
|
||||||
|
<% } %>
|
||||||
|
|
||||||
uploaded
|
uploaded
|
||||||
<%= formatRelativeTime(post.uploadTime) %>
|
<%= formatRelativeTime(post.uploadTime) %>
|
||||||
|
@ -21,7 +29,9 @@
|
||||||
<span class="right">
|
<span class="right">
|
||||||
featured by
|
featured by
|
||||||
|
|
||||||
<% if (post.user.name) { %>
|
<% var showLink = canViewUsers && post.user.name %>
|
||||||
|
|
||||||
|
<% if (showLink) { %>
|
||||||
<a href="#/user/<%= post.user.name %>">
|
<a href="#/user/<%= post.user.name %>">
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
||||||
|
@ -31,7 +41,7 @@
|
||||||
|
|
||||||
<%= post.user.name || 'Anonymous user' %>
|
<%= post.user.name || 'Anonymous user' %>
|
||||||
|
|
||||||
<% if (post.user.name) { %>
|
<% if (showLink) { %>
|
||||||
</a>
|
</a>
|
||||||
<% } %>
|
<% } %>
|
||||||
</span>
|
</span>
|
||||||
|
|
|
@ -43,18 +43,23 @@ final class PostController extends AbstractController
|
||||||
|
|
||||||
public function getByNameOrId($postNameOrId)
|
public function getByNameOrId($postNameOrId)
|
||||||
{
|
{
|
||||||
|
if ($postNameOrId !== 'featured')
|
||||||
|
$this->privilegeService->assertPrivilege(\Szurubooru\Privilege::VIEW_POSTS);
|
||||||
|
|
||||||
$post = $this->getByNameOrIdWithoutProxy($postNameOrId);
|
$post = $this->getByNameOrIdWithoutProxy($postNameOrId);
|
||||||
return $this->postViewProxy->fromEntity($post, $this->getFullFetchConfig());
|
return $this->postViewProxy->fromEntity($post, $this->getFullFetchConfig());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getHistory($postNameOrId)
|
public function getHistory($postNameOrId)
|
||||||
{
|
{
|
||||||
|
$this->privilegeService->assertPrivilege(\Szurubooru\Privilege::VIEW_HISTORY);
|
||||||
$post = $this->getByNameOrIdWithoutProxy($postNameOrId);
|
$post = $this->getByNameOrIdWithoutProxy($postNameOrId);
|
||||||
return ['data' => $this->snapshotViewProxy->fromArray($this->postService->getHistory($post))];
|
return ['data' => $this->snapshotViewProxy->fromArray($this->postService->getHistory($post))];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFiltered()
|
public function getFiltered()
|
||||||
{
|
{
|
||||||
|
$this->privilegeService->assertPrivilege(\Szurubooru\Privilege::LIST_POSTS);
|
||||||
$filter = $this->postSearchParser->createFilterFromInputReader($this->inputReader);
|
$filter = $this->postSearchParser->createFilterFromInputReader($this->inputReader);
|
||||||
$filter->setPageSize($this->config->posts->postsPerPage);
|
$filter->setPageSize($this->config->posts->postsPerPage);
|
||||||
$result = $this->postService->getFiltered($filter);
|
$result = $this->postService->getFiltered($filter);
|
||||||
|
|
|
@ -44,6 +44,7 @@ final class UserController extends AbstractController
|
||||||
|
|
||||||
public function getByNameOrEmail($userNameOrEmail)
|
public function getByNameOrEmail($userNameOrEmail)
|
||||||
{
|
{
|
||||||
|
$this->privilegeService->assertPrivilege(\Szurubooru\Privilege::VIEW_USERS);
|
||||||
$user = $this->userService->getByNameOrEmail($userNameOrEmail);
|
$user = $this->userService->getByNameOrEmail($userNameOrEmail);
|
||||||
return $this->userViewProxy->fromEntity($user);
|
return $this->userViewProxy->fromEntity($user);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ class Privilege
|
||||||
{
|
{
|
||||||
const REGISTER = 'register';
|
const REGISTER = 'register';
|
||||||
const LIST_USERS = 'listUsers';
|
const LIST_USERS = 'listUsers';
|
||||||
|
const VIEW_USERS = 'viewUsers';
|
||||||
const VIEW_ALL_EMAIL_ADDRESSES = 'viewAllEmailAddresses';
|
const VIEW_ALL_EMAIL_ADDRESSES = 'viewAllEmailAddresses';
|
||||||
const CHANGE_ACCESS_RANK = 'changeAccessRank';
|
const CHANGE_ACCESS_RANK = 'changeAccessRank';
|
||||||
const CHANGE_OWN_AVATAR_STYLE = 'changeOwnAvatarStyle';
|
const CHANGE_OWN_AVATAR_STYLE = 'changeOwnAvatarStyle';
|
||||||
|
@ -19,9 +20,8 @@ class Privilege
|
||||||
const DELETE_ALL_ACCOUNTS = 'deleteAllAccounts';
|
const DELETE_ALL_ACCOUNTS = 'deleteAllAccounts';
|
||||||
const BAN = 'ban';
|
const BAN = 'ban';
|
||||||
|
|
||||||
const LIST_SAFE_POSTS = 'listSafePosts';
|
const LIST_POSTS = 'listPosts';
|
||||||
const LIST_SKETCHY_POSTS = 'listSketchyPosts';
|
const VIEW_POSTS = 'viewPosts';
|
||||||
const LIST_UNSAFE_POSTS = 'listUnsafePosts';
|
|
||||||
const UPLOAD_POSTS = 'uploadPosts';
|
const UPLOAD_POSTS = 'uploadPosts';
|
||||||
const UPLOAD_POSTS_ANONYMOUSLY = 'uploadPostsAnonymously';
|
const UPLOAD_POSTS_ANONYMOUSLY = 'uploadPostsAnonymously';
|
||||||
const DELETE_POSTS = 'deletePosts';
|
const DELETE_POSTS = 'deletePosts';
|
||||||
|
|
Loading…
Reference in a new issue