This repository has been archived on 2024-09-05. You can view files and clone it, but cannot push or open issues or pull requests.
shimmie2/core/userclass.php

194 lines
4.5 KiB
PHP
Raw Normal View History

2012-02-14 21:11:23 +00:00
<?php
/**
2015-08-02 19:39:41 +00:00
* @global UserClass[] $_shm_user_classes
*/
2015-08-02 19:39:41 +00:00
global $_shm_user_classes;
$_shm_user_classes = array();
2012-02-14 21:11:23 +00:00
2014-04-29 05:33:03 +00:00
/**
* Class UserClass
*/
2012-02-14 21:11:23 +00:00
class UserClass {
/**
* @var null|string
*/
public $name = null;
/**
2014-04-27 23:29:36 +00:00
* @var \UserClass|null
*/
public $parent = null;
/**
* @var array
*/
public $abilities = array();
2012-02-14 21:11:23 +00:00
2017-09-19 17:55:43 +00:00
public function __construct(string $name, string $parent=null, array $abilities=array()) {
2015-08-02 19:39:41 +00:00
global $_shm_user_classes;
2012-03-19 11:27:01 +00:00
2012-02-14 21:11:23 +00:00
$this->name = $name;
$this->abilities = $abilities;
2012-03-19 11:27:01 +00:00
2012-03-19 11:33:06 +00:00
if(!is_null($parent)) {
2015-08-02 19:39:41 +00:00
$this->parent = $_shm_user_classes[$parent];
2012-03-19 11:33:06 +00:00
}
2015-08-02 19:39:41 +00:00
$_shm_user_classes[$name] = $this;
2012-02-14 21:11:23 +00:00
}
/**
* Determine if this class of user can perform an action or has ability.
*
* @throws SCoreException
*/
2017-09-19 17:55:43 +00:00
public function can(string $ability): bool {
2012-02-14 21:11:23 +00:00
if(array_key_exists($ability, $this->abilities)) {
$val = $this->abilities[$ability];
2012-03-19 11:27:01 +00:00
return $val;
2012-02-14 21:11:23 +00:00
}
else if(!is_null($this->parent)) {
return $this->parent->can($ability);
}
else {
2015-08-02 19:39:41 +00:00
global $_shm_user_classes;
2012-03-31 16:06:53 +00:00
$min_dist = 9999;
$min_ability = null;
2015-08-02 19:39:41 +00:00
foreach($_shm_user_classes['base']->abilities as $a => $cando) {
2012-03-31 16:06:53 +00:00
$v = levenshtein($ability, $a);
if($v < $min_dist) {
$min_dist = $v;
$min_ability = $a;
}
}
throw new SCoreException("Unknown ability '".html_escape($ability)."'. Did the developer mean '".html_escape($min_ability)."'?");
2012-02-14 21:11:23 +00:00
}
}
}
2012-03-12 17:30:33 +00:00
// action_object_attribute
// action = create / view / edit / delete
// object = image / user / tag / setting
2012-03-19 11:27:01 +00:00
new UserClass("base", null, array(
2012-02-22 21:08:57 +00:00
"change_setting" => False, # modify web-level settings, eg the config table
2012-03-30 17:03:55 +00:00
"override_config" => False, # modify sys-level settings, eg shimmie.conf.php
2012-02-22 21:08:57 +00:00
"big_search" => False, # search for more than 3 tags at once (speed mode only)
2012-03-14 19:24:10 +00:00
"manage_extension_list" => False,
"manage_alias_list" => False,
"mass_tag_edit" => False,
2012-02-14 21:11:23 +00:00
"view_ip" => False, # view IP addresses associated with things
"ban_ip" => False,
2012-03-14 19:24:10 +00:00
2015-07-12 21:14:57 +00:00
"edit_user_name" => False,
2012-03-12 17:29:03 +00:00
"edit_user_password" => False,
"edit_user_info" => False, # email address, etc
"edit_user_class" => False,
2012-02-14 21:11:23 +00:00
"delete_user" => False,
2012-03-14 19:24:10 +00:00
"create_comment" => False,
2012-02-14 21:11:23 +00:00
"delete_comment" => False,
"bypass_comment_checks" => False, # spam etc
2012-03-14 19:24:10 +00:00
2012-02-14 21:11:23 +00:00
"replace_image" => False,
2012-03-19 12:59:02 +00:00
"create_image" => False,
2012-02-14 21:11:23 +00:00
"edit_image_tag" => False,
"edit_image_source" => False,
"edit_image_owner" => False,
2012-03-14 19:24:10 +00:00
"edit_image_lock" => False,
2012-03-31 11:33:55 +00:00
"bulk_edit_image_tag" => False,
2012-03-31 15:31:10 +00:00
"bulk_edit_image_source" => False,
2012-03-14 19:24:10 +00:00
"delete_image" => False,
2012-03-30 19:54:33 +00:00
"ban_image" => False,
"view_eventlog" => False,
2012-03-31 11:28:34 +00:00
"ignore_downtime" => False,
2012-03-30 19:54:33 +00:00
2012-03-14 19:24:10 +00:00
"create_image_report" => False,
2012-02-22 21:08:57 +00:00
"view_image_report" => False, # deal with reported images
2012-03-14 19:24:10 +00:00
2012-03-19 13:21:59 +00:00
"edit_wiki_page" => False,
"delete_wiki_page" => False,
"manage_blocks" => False,
2012-03-30 19:54:33 +00:00
"manage_admintools" => False,
2012-03-31 11:28:34 +00:00
"view_other_pms" => False,
"edit_feature" => False,
"bulk_edit_vote" => False,
"edit_other_vote" => False,
2012-03-31 14:48:02 +00:00
"view_sysinfo" => False,
2012-03-31 11:28:34 +00:00
"hellbanned" => False,
"view_hellbanned" => False,
2012-02-22 21:08:57 +00:00
"protected" => False, # only admins can modify protected users (stops a moderator changing an admin's password)
2012-02-14 21:11:23 +00:00
));
2012-03-19 11:27:01 +00:00
new UserClass("anonymous", "base", array(
2012-02-14 21:11:23 +00:00
));
2012-03-19 11:27:01 +00:00
new UserClass("user", "base", array(
2012-02-14 21:11:23 +00:00
"big_search" => True,
2012-03-19 12:59:02 +00:00
"create_image" => True,
"create_comment" => True,
2012-02-14 21:11:23 +00:00
"edit_image_tag" => True,
"edit_image_source" => True,
2012-03-14 19:24:10 +00:00
"create_image_report" => True,
2012-02-14 21:11:23 +00:00
));
2012-03-19 11:27:01 +00:00
new UserClass("admin", "base", array(
2012-02-14 21:11:23 +00:00
"change_setting" => True,
"override_config" => True,
"big_search" => True,
2012-03-14 19:24:10 +00:00
"edit_image_lock" => True,
2012-02-14 21:11:23 +00:00
"view_ip" => True,
"ban_ip" => True,
2015-07-12 21:14:57 +00:00
"edit_user_name" => True,
2012-03-12 17:29:03 +00:00
"edit_user_password" => True,
"edit_user_info" => True,
"edit_user_class" => True,
2012-02-14 21:11:23 +00:00
"delete_user" => True,
2012-03-19 12:59:02 +00:00
"create_image" => True,
2012-02-14 21:11:23 +00:00
"delete_image" => True,
2012-03-30 19:54:33 +00:00
"ban_image" => True,
"create_comment" => True,
2012-02-14 21:11:23 +00:00
"delete_comment" => True,
"bypass_comment_checks" => True,
2012-02-14 21:11:23 +00:00
"replace_image" => True,
"manage_extension_list" => True,
"manage_alias_list" => True,
"edit_image_tag" => True,
"edit_image_source" => True,
"edit_image_owner" => True,
2012-03-31 11:33:55 +00:00
"bulk_edit_image_tag" => True,
2012-03-31 15:31:10 +00:00
"bulk_edit_image_source" => True,
2012-02-14 21:11:23 +00:00
"mass_tag_edit" => True,
2012-03-14 19:24:10 +00:00
"create_image_report" => True,
2012-02-14 21:11:23 +00:00
"view_image_report" => True,
2012-03-19 13:21:59 +00:00
"edit_wiki_page" => True,
"delete_wiki_page" => True,
2012-03-30 19:54:33 +00:00
"view_eventlog" => True,
"manage_blocks" => True,
2012-03-30 19:54:33 +00:00
"manage_admintools" => True,
2012-03-31 11:28:34 +00:00
"ignore_downtime" => True,
"view_other_pms" => True,
"edit_feature" => True,
"bulk_edit_vote" => True,
"edit_other_vote" => True,
2012-03-31 14:48:02 +00:00
"view_sysinfo" => True,
"view_hellbanned" => True,
"protected" => True,
2012-02-14 21:11:23 +00:00
));
new UserClass("hellbanned", "user", array(
"hellbanned" => True,
));
@include_once "data/config/user-classes.conf.php";