aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Lib/PermissionDescription.php
diff options
context:
space:
mode:
authorKlaus Weidenbach <Klaus.Weidenbach@gmx.net>2016-10-18 20:43:48 +0200
committerKlaus Weidenbach <Klaus.Weidenbach@gmx.net>2016-10-20 20:22:39 +0200
commitb71e148ceafd4153ff564b46de92c6859088d2f2 (patch)
treeb365dfeb4434d217063d75d7dc9d8c311c2a7e88 /Zotlabs/Lib/PermissionDescription.php
parent0d939b5ab0f205e92adfd3e268207f9058c09fa0 (diff)
downloadvolse-hubzilla-b71e148ceafd4153ff564b46de92c6859088d2f2.tar.gz
volse-hubzilla-b71e148ceafd4153ff564b46de92c6859088d2f2.tar.bz2
volse-hubzilla-b71e148ceafd4153ff564b46de92c6859088d2f2.zip
[BUGFIX] for fromStandalonePermission().
Not sure if this method is used anywhere, but it should not have worked correctly. This should correct it. Add a unit test for this class.
Diffstat (limited to 'Zotlabs/Lib/PermissionDescription.php')
-rw-r--r--Zotlabs/Lib/PermissionDescription.php54
1 files changed, 26 insertions, 28 deletions
diff --git a/Zotlabs/Lib/PermissionDescription.php b/Zotlabs/Lib/PermissionDescription.php
index b6c6dd29d..51d5f890d 100644
--- a/Zotlabs/Lib/PermissionDescription.php
+++ b/Zotlabs/Lib/PermissionDescription.php
@@ -12,22 +12,25 @@ require_once("include/text.php");
* permission settings for an item with an empty ACL.
* i.e the caption, icon, and tooltip for the no-ACL option in the ACL dialog.
*/
-class PermissionDescription {
+class PermissionDescription {
private $global_perm;
private $channel_perm;
private $fallback_description;
-
+
/**
* Constructor is private.
- * Use static methods fromGlobalPermission(), fromStandalonePermission(), or fromDescription()
- * to create instances.
+ * Use static methods fromGlobalPermission(), fromStandalonePermission(),
+ * or fromDescription() to create instances.
+ *
+ * @internal
+ * @param int $global_perm
+ * @param int $channel_perm
+ * @param string $description (optional) default empty
*/
private function __construct($global_perm, $channel_perm, $description = '') {
-
$this->global_perm = $global_perm;
$this->channel_perm = $channel_perm;
-
$this->fallback_description = ($description == '') ? t('Visible to your default audience') : $description;
}
@@ -43,23 +46,22 @@ class PermissionDescription {
return new PermissionDescription('', 0x80000, $description);
}
-
/**
* Use this method only if the interpretation of an empty ACL doesn't fall back to a global
* default permission. You should pass one of the constants from boot.php - PERMS_PUBLIC,
* PERMS_NETWORK etc.
- *
+ *
* @param integer $perm - a single enumerated constant permission - PERMS_PUBLIC, PERMS_NETWORK etc.
* @return a new instance of PermissionDescription
*/
public static function fromStandalonePermission($perm) {
$result = new PermissionDescription('', $perm);
-
- $checkPerm = $this->get_permission_description();
- if ($checkPerm == $this->fallback_description) {
+
+ $checkPerm = $result->get_permission_description();
+ if($checkPerm == $result->fallback_description) {
$result = null;
- logger('null PermissionDescription from unknown standalone permission: ' . $perm ,LOGGER_DEBUG, LOG_ERROR);
+ logger('null PermissionDescription from unknown standalone permission: ' . $perm, LOGGER_DEBUG, LOG_ERR);
}
return $result;
@@ -67,9 +69,9 @@ class PermissionDescription {
/**
* This is the preferred way to create a PermissionDescription, as it provides the most details.
- * Use this method if you know an empty ACL will result in one of the global default permissions
+ * Use this method if you know an empty ACL will result in one of the global default permissions
* being used, such as channel_r_stream (for which you would pass 'view_stream').
- *
+ *
* @param string $permname - a key for the global perms array from get_perms() in permissions.php,
* e.g. 'view_stream', 'view_profile', etc.
* @return a new instance of PermissionDescription
@@ -80,19 +82,19 @@ class PermissionDescription {
$global_perms = \Zotlabs\Access\Permissions::Perms();
- if (array_key_exists($permname, $global_perms)) {
+ if(array_key_exists($permname, $global_perms)) {
- $channelPerm = \Zotlabs\Access\PermissionLimits::Get(\App::$channel['channel_id'],$permname);
+ $channelPerm = \Zotlabs\Access\PermissionLimits::Get(\App::$channel['channel_id'], $permname);
$result = new PermissionDescription('', $channelPerm);
} else {
// The acl dialog can handle null arguments, but it shouldn't happen
- logger('null PermissionDescription from unknown global permission: ' . $permname ,LOGGER_DEBUG, LOG_ERROR);
+ logger('null PermissionDescription from unknown global permission: ' . $permname, LOGGER_DEBUG, LOG_ERR);
}
+
return $result;
}
-
/**
* Gets a localized description of the permission, or a generic message if the permission
* is unknown.
@@ -101,8 +103,7 @@ class PermissionDescription {
*/
public function get_permission_description() {
- switch($this->channel_perm) {
-
+ switch($this->channel_perm) {
case 0: return t('Only me');
case PERMS_PUBLIC: return t('Public');
case PERMS_NETWORK: return t('Anybody in the $Projectname network');
@@ -117,19 +118,18 @@ class PermissionDescription {
/**
* Returns an icon css class name if an appropriate one is available, e.g. "fa-globe" for Public,
- * otherwise returns empty string.
+ * otherwise returns empty string.
*
* @return string icon css class name (often FontAwesome)
*/
public function get_permission_icon() {
- switch($this->channel_perm) {
-
+ switch($this->channel_perm) {
case 0:/* only me */ return 'fa-eye-slash';
case PERMS_PUBLIC: return 'fa-globe';
case PERMS_NETWORK: return 'fa-share-alt-square'; // fa-share-alt-square is very similiar to the hubzilla logo, but we should create our own logo class to use
- case PERMS_SITE: return 'fa-sitemap';
- case PERMS_CONTACTS: return 'fa-group';
+ case PERMS_SITE: return 'fa-sitemap';
+ case PERMS_CONTACTS: return 'fa-group';
case PERMS_SPECIFIC: return 'fa-list';
case PERMS_AUTHED: return '';
case PERMS_PENDING: return '';
@@ -137,7 +137,6 @@ class PermissionDescription {
}
}
-
/**
* Returns a localized description of where the permission came from, if this is known.
* If it's not know, or if the permission is standalone and didn't come from a default
@@ -147,8 +146,7 @@ class PermissionDescription {
*/
public function get_permission_origin_description() {
- switch($this->global_perm) {
-
+ switch($this->global_perm) {
case PERMS_R_STREAM: return t('This is your default setting for the audience of your normal stream, and posts.');
case PERMS_R_PROFILE: return t('This is your default setting for who can view your default channel profile');
case PERMS_R_ABOOK: return t('This is your default setting for who can view your connections');