Skip to content

Commit f884880

Browse files
committed
Restaure groups g_moderator instead of User::can('mod.is_mod')
Easier queries as is, but may be changed again later
1 parent 17ac105 commit f884880

File tree

15 files changed

+43
-63
lines changed

15 files changed

+43
-63
lines changed

featherbb/Controller/Admin/Groups.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public function display($req, $res, $args)
2929
Container::get('hooks')->fire('controller.admin.groups.display');
3030

3131
$groups = $this->model->fetch_groups();
32+
var_dump($groups);
3233

3334
// Set default group
3435
if (Request::isPost()) {
@@ -118,7 +119,6 @@ public function addedit($req, $res, $args)
118119
'active_page' => 'admin',
119120
'admin_console' => true,
120121
'group' => $group,
121-
'groups' => $groups,
122122
'id' => $id,
123123
'group_list' => $this->model->get_group_list($groups, $group),
124124
)

featherbb/Controller/Admin/Users.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function display($req, $res, $args)
9393

9494
// Some helper variables for permissions
9595
$can_delete = $can_move = User::isAdmin();
96-
$can_ban = User::isAdmin() || (User::can('mod.is_mod') && User::can('mod.ban_users'));
96+
$can_ban = User::isAdmin() || (User::isAdminMod() && User::can('mod.ban_users'));
9797
$can_action = ($can_delete || $can_ban || $can_move) && $num_users > 0;
9898
View::addAsset('js', 'style/imports/common.js', array('type' => 'text/javascript'));
9999

featherbb/Controller/Forum.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function display($req, $res, $args)
3636

3737
// Sort out who the moderators are and if we are currently a moderator (or an admin)
3838
$mods_array = ($cur_forum['moderators'] != '') ? unserialize($cur_forum['moderators']) : array();
39-
$is_admmod = (User::isAdmin() || (User::can('mod.is_mod') && array_key_exists(User::get()->username, $mods_array))) ? true : false;
39+
$is_admmod = (User::isAdmin() || (User::isAdminMod() && array_key_exists(User::get()->username, $mods_array))) ? true : false;
4040

4141
$sort_by = $this->model->sort_forum_by($cur_forum['sort_by']);
4242

@@ -94,7 +94,7 @@ public function moderate($req, $res, $args)
9494
$moderators = $this->model->get_moderators($args['id']);
9595
$mods_array = ($moderators != '') ? unserialize($moderators) : array();
9696

97-
if (User::get()->g_id != ForumEnv::get('FEATHER_ADMIN') && (!User::can('mod.is_mod') || !array_key_exists(User::get()->username, $mods_array))) {
97+
if (!User::isAdmin() && (!User::isAdminMod() || !array_key_exists(User::get()->username, $mods_array))) {
9898
throw new Error(__('No permission'), 403);
9999
}
100100

@@ -165,7 +165,7 @@ public function dealposts($req, $res, $args)
165165
$moderators = $this->model->get_moderators($args['id']);
166166
$mods_array = ($moderators != '') ? unserialize($moderators) : array();
167167

168-
if (User::get()->g_id != ForumEnv::get('FEATHER_ADMIN') && (!User::can('mod.is_mod') || !array_key_exists(User::get()->username, $mods_array))) {
168+
if (!User::isAdmin() && (!User::isAdminMod() || !array_key_exists(User::get()->username, $mods_array))) {
169169
throw new Error(__('No permission'), 403);
170170
}
171171

featherbb/Controller/Install.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ public function create_db(array $data)
217217

218218
Container::get('perms')->allowGroup(3, array('board.read', 'users.view', 'search.topics', 'search.users'));
219219
Container::get('perms')->allowGroup(4, array('board.read', 'users.view', 'search.topics', 'search.users', 'topic.reply', 'topic.post', 'topic.delete', 'post.delete', 'post.edit', 'post.links', 'email.send'));
220-
Container::get('perms')->allowGroup(2, array('board.read', 'users.view', 'user.set_title', 'search.topics', 'search.users', 'topic.reply', 'topic.post', 'topic.delete', 'post.delete', 'post.edit', 'post.links', 'email.send', 'mod.is_mod', 'mod.edit_users', 'mod.rename_users', 'mod.change_passwords', 'mod.promote_users', 'mod.ban_users'));
220+
Container::get('perms')->allowGroup(2, array('board.read', 'users.view', 'user.set_title', 'search.topics', 'search.users', 'topic.reply', 'topic.post', 'topic.delete', 'post.delete', 'post.edit', 'post.links', 'email.send', 'mod.edit_users', 'mod.rename_users', 'mod.change_passwords', 'mod.promote_users', 'mod.ban_users'));
221221
Container::get('perms')->allowGroup(1, array('*'));
222222
// Init preferences
223223
Container::get('prefs')->set(array(

featherbb/Controller/Post.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function newpost($req, $res, $args)
7171

7272
// Sort out who the moderators are and if we are currently a moderator (or an admin)
7373
$mods_array = ($cur_posting['moderators'] != '') ? unserialize($cur_posting['moderators']) : array();
74-
$is_admmod = (User::isAdmin() || (User::can('mod.is_mod') && array_key_exists(User::get()->username, $mods_array))) ? true : false;
74+
$is_admmod = (User::isAdmin() || (User::isAdminMod() && array_key_exists(User::get()->username, $mods_array))) ? true : false;
7575

7676
// Do we have permission to post?
7777
if ((($args['tid'] && (($cur_posting['post_replies'] == '' && !User::can('topic.reply')) || $cur_posting['post_replies'] == '0')) ||
@@ -208,7 +208,7 @@ public function delete($req, $res, $args)
208208

209209
// Sort out who the moderators are and if we are currently a moderator (or an admin)
210210
$mods_array = ($cur_post['moderators'] != '') ? unserialize($cur_post['moderators']) : array();
211-
$is_admmod = (User::isAdmin() || (User::can('mod.is_mod') && array_key_exists(User::get()->username, $mods_array))) ? true : false;
211+
$is_admmod = (User::isAdmin() || (User::isAdminMod() && array_key_exists(User::get()->username, $mods_array))) ? true : false;
212212

213213
$is_topic_post = ($args['id'] == $cur_post['first_post_id']) ? true : false;
214214

@@ -249,7 +249,7 @@ public function editpost($req, $res, $args)
249249

250250
// Sort out who the moderators are and if we are currently a moderator (or an admin)
251251
$mods_array = ($cur_post['moderators'] != '') ? unserialize($cur_post['moderators']) : array();
252-
$is_admmod = (User::isAdmin() || (User::can('mod.is_mod') && array_key_exists(User::get()->username, $mods_array))) ? true : false;
252+
$is_admmod = (User::isAdmin() || (User::isAdminMod() && array_key_exists(User::get()->username, $mods_array))) ? true : false;
253253

254254
$can_edit_subject = $args['id'] == $cur_post['first_post_id'];
255255

featherbb/Controller/Profile.php

Lines changed: 14 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use FeatherBB\Core\Error;
1313
use FeatherBB\Core\Url;
1414
use FeatherBB\Core\Utils;
15+
use FeatherBB\Core\Database as DB;
1516
use FeatherBB\Model\Delete;
1617

1718
class Profile
@@ -47,7 +48,7 @@ public function display($req, $res, $args)
4748

4849
return $this->model->update_mod_forums($args['id']);
4950
} elseif (Input::post('ban')) {
50-
if (User::get()->g_id != ForumEnv::get('FEATHER_ADMIN') && (!User::can('mod.is_mod') || !User::can('mod.ban_users'))) {
51+
if (!User::isAdmin() && (!User::isAdminMod() || !User::can('mod.ban_users'))) {
5152
throw new Error(__('No permission'), 403);
5253
}
5354

@@ -74,7 +75,7 @@ public function display($req, $res, $args)
7475

7576
if (User::get()->id != $args['id'] && // If we aren't the user (i.e. editing your own profile)
7677
(!User::isAdminMod() || // and we are not an admin or mod
77-
(User::get()->g_id != ForumEnv::get('FEATHER_ADMIN') && // or we aren't an admin and ...
78+
(!User::isAdmin() && // or we aren't an admin and ...
7879
(!User::can('mod.edit_users') || // mods aren't allowed to edit users
7980
$info['group_id'] == ForumEnv::get('FEATHER_ADMIN') || // or the user is an admin
8081
$info['is_moderator'])))) { // or the user is another mod
@@ -201,7 +202,7 @@ public function display($req, $res, $args)
201202

202203
} elseif ($args['section'] == 'admin') {
203204

204-
if (!User::isAdminMod() || (User::can('mod.is_mod') && !User::can('mod.ban_users'))) {
205+
if (!User::isAdminMod() || (User::isAdminMod() && !User::can('mod.ban_users'))) {
205206
throw new Error(__('Bad request'), 404);
206207
}
207208

@@ -239,30 +240,21 @@ public function action($req, $res, $args)
239240
}
240241
}
241242

243+
// Make sure user exists
244+
if (!DB::for_table('users')->find_one($args['id'])) {
245+
throw new Error(__('Bad request'), 404);
246+
}
247+
242248
if ($args['action'] == 'change_pass') {
243249
// Make sure we are allowed to change this user's password
244250
if (User::get()->id != $args['id']) {
245251
$args['id'] = Container::get('hooks')->fire('controller.profile.change_pass_key_not_id', $args['id']);
246252

247253
if (!User::isAdminMod()) { // A regular user trying to change another user's password?
248254
throw new Error(__('No permission'), 403);
249-
} elseif (User::can('mod.is_mod')) {
255+
} elseif (User::isAdminMod()) {
250256
// A moderator trying to change a user's password?
251-
$user['select'] = array('u.group_id', 'g.g_moderator');
252-
253-
$user = DB::for_table('users')
254-
->table_alias('u')
255-
->select_many($user['select'])
256-
->inner_join('groups', array('g.g_id', '=', 'u.group_id'), 'g')
257-
->where('u.id', $args['id']);
258-
$user = Container::get('hooks')->fireDB('controller.profile.change_pass_user_query', $user);
259-
$user = $user->find_one();
260-
261-
if (!$user) {
262-
throw new Error(__('Bad request'), 404);
263-
}
264-
265-
if (!User::can('mod.edit_users') || !User::can('mod.change_passwords') || $user['group_id'] == ForumEnv::get('FEATHER_ADMIN') || $user['g_moderator'] == '1') {
257+
if (!User::can('mod.edit_users') || !User::can('mod.change_passwords') || User::isAdminMod($args['id'])) {
266258
throw new Error(__('No permission'), 403);
267259
}
268260
}
@@ -287,23 +279,9 @@ public function action($req, $res, $args)
287279

288280
if (!User::isAdminMod()) { // A regular user trying to change another user's email?
289281
throw new Error(__('No permission'), 403);
290-
} elseif (User::can('mod.is_mod')) {
282+
} elseif (User::isAdminMod()) {
291283
// A moderator trying to change a user's email?
292-
$user['select'] = array('u.group_id', 'g.g_moderator');
293-
294-
$user = DB::for_table('users')
295-
->table_alias('u')
296-
->select_many($user['select'])
297-
->inner_join('groups', array('g.g_id', '=', 'u.group_id'), 'g')
298-
->where('u.id', $args['id']);
299-
$user = Container::get('hooks')->fireDB('controller.profile.change_email_not_id_query', $user);
300-
$user = $user->find_one();
301-
302-
if (!$user) {
303-
throw new Error(__('Bad request'), 404);
304-
}
305-
306-
if (!User::can('mod.edit_users') || !User::can('mod.change_passwords') || $user['group_id'] == ForumEnv::get('FEATHER_ADMIN') || $user['g_moderator'] == '1') {
284+
if (!User::can('mod.edit_users') || !User::can('mod.change_passwords') || User::isAdminMod($args['id'])) {
307285
throw new Error(__('No permission'), 403);
308286
}
309287
}
@@ -350,7 +328,7 @@ public function action($req, $res, $args)
350328

351329
return Router::redirect(Router::pathFor('profileSection', array('id' => $args['id'], 'section' => 'personality')), __('Avatar deleted redirect'));
352330
} elseif ($args['action'] == 'promote') {
353-
if (User::get()->g_id != ForumEnv::get('FEATHER_ADMIN') && (!User::can('mod.is_mod') || !User::can('mod.promote_users'))) {
331+
if (!User::isAdmin() && (!User::isAdminMod() || !User::can('mod.promote_users'))) {
354332
throw new Error(__('No permission'), 403);
355333
}
356334

featherbb/Controller/Topic.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function display($req, $res, $args)
4949

5050
// Sort out who the moderators are and if we are currently a moderator (or an admin)
5151
$mods_array = ($cur_topic['moderators'] != '') ? unserialize($cur_topic['moderators']) : array();
52-
$is_admmod = (User::isAdmin() || (User::can('mod.is_mod') && array_key_exists(User::get()->username, $mods_array))) ? true : false;
52+
$is_admmod = (User::isAdmin() || (User::isAdminMod() && array_key_exists(User::get()->username, $mods_array))) ? true : false;
5353

5454
// Can we or can we not post replies?
5555
$post_link = $this->model->get_post_link($args['id'], $cur_topic['closed'], $cur_topic['post_replies'], $is_admmod);
@@ -210,7 +210,7 @@ public function moderate($req, $res, $args)
210210
$moderators = $forumModel->get_moderators($args['fid']);
211211
$mods_array = ($moderators != '') ? unserialize($moderators) : array();
212212

213-
if (User::get()->g_id != ForumEnv::get('FEATHER_ADMIN') && (!User::can('mod.is_mod') || !array_key_exists(User::get()->username, $mods_array))) {
213+
if (!User::isAdmin() && (!User::isAdminMod() || !array_key_exists(User::get()->username, $mods_array))) {
214214
throw new Error(__('No permission'), 403);
215215
}
216216

featherbb/Core/Interfaces/User.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@ public static function getBasic($id = null)
3434
return Container::get('user');
3535
} else {
3636
// Load user from DB based on $id
37-
return DB::for_table('users')->select_many('id', 'group_id')->find_one($id);
37+
return DB::for_table('users')
38+
->table_alias('u')
39+
->inner_join('groups', array('u.group_id', '=', 'g.g_id'), 'g')
40+
->where('u.id', $id)
41+
->select_many('u.id', 'u.group_id', 'g.g_moderator')
42+
->find_one();
3843
}
3944
}
4045

@@ -80,6 +85,6 @@ public static function isAdmin($id = null)
8085
public static function isAdminMod($id = null)
8186
{
8287
$user = self::getBasic($id);
83-
return $user->group_id == ForumEnv::get('FEATHER_ADMIN') || Container::get('perms')->can($user, 'mod.is_mod');
88+
return $user->group_id == ForumEnv::get('FEATHER_ADMIN') || $user->g_moderator == '1';
8489
}
8590
}

featherbb/Model/Admin/Groups.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Groups
2020
public function fetch_groups()
2121
{
2222
// $result = DB::for_table('groups')->order_by('g_id')->find_many();
23-
$result = DB::for_table('groups')->select_many('g_id', 'g_user_title', 'g_title', 'g_promote_min_posts', 'g_promote_next_group')->order_by('g_id')->find_many();
23+
$result = DB::for_table('groups')->select_many('g_id', 'g_user_title', 'g_title', 'g_promote_min_posts', 'g_promote_next_group', 'g_moderator')->order_by('g_id')->find_many();
2424
Container::get('hooks')->fireDB('model.admin.groups.fetch_groups_query', $result);
2525
$groups = array();
2626
foreach ($result as $cur_group) {
@@ -177,7 +177,6 @@ public function add_edit_group($groups)
177177
'report.min_interval' => (int) $report_flood
178178
);
179179
$group_permissions = array(
180-
'mod.is_mod' => (int) $moderator,
181180
'mod.edit_users' => (int) $mod_edit_users,
182181
'mod.rename_users' => (int) $mod_rename_users,
183182
'mod.change_passwords' => (int) $mod_change_passwords,
@@ -222,7 +221,6 @@ public function add_edit_group($groups)
222221
Container::get('perms')->denyGroup($new_group_id, array_keys($denied_perms));
223222

224223
// Now lets copy the forum specific permissions from the group which this group is based on
225-
// TODO: Remove this when new perms are ready
226224
$select_forum_perms = array('forum_id', 'read_forum', 'post_replies', 'post_topics');
227225
$result = DB::for_table('forum_perms')->select_many($select_forum_perms)
228226
->where('group_id', Input::post('base_group'));

featherbb/Model/Profile.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ public function update_profile($id, $info, $section)
713713
$form['admin_note'] = Utils::trim(Input::post('admin_note'));
714714

715715
// Are we allowed to change usernames?
716-
if (User::isAdmin() || (User::can('mod.is_mod') && User::can('mod.rename_users'))) {
716+
if (User::isAdmin() || (User::isAdminMod() && User::can('mod.rename_users'))) {
717717
$form['username'] = Utils::trim(Input::post('req_username'));
718718

719719
if ($form['username'] != $info['old_username']) {
@@ -952,8 +952,7 @@ public function update_profile($id, $info, $section)
952952
// If the user is a moderator or an administrator we have to update the moderator lists
953953
$group_id = DB::for_table('users')
954954
->where('id', $id);
955-
// TODO: restore hook
956-
// $group_id = Container::get('hooks')->fireDB('model.profile.update_profile_group_id', $update_online);
955+
$group_id = Container::get('hooks')->fireDB('model.profile.update_profile_group_id', $group_id);
957956
$group_id = $group_id->find_one_col('group_id');
958957

959958
$group_mod = DB::for_table('groups')

0 commit comments

Comments
 (0)