Merge branch 'dev' of https://github.com/redmatrix/hubzilla into xdev_merge

This commit is contained in:
zotlabs 2017-05-22 03:51:58 -07:00
commit 1c8c7479b8
11 changed files with 276 additions and 73 deletions

View File

@ -1,14 +1,12 @@
<?php <?php
namespace Zotlabs\Access; namespace Zotlabs\Access;
use Zotlabs\Lib as Zlib; use Zotlabs\Lib as Zlib;
class Permissions { /**
* @brief Extensible permissions.
/** *
* Extensible permissions.
* To add new permissions, add to the list of $perms below, with a simple description. * To add new permissions, add to the list of $perms below, with a simple description.
* *
* Also visit PermissionRoles.php and add to the $ret['perms_connect'] property for any role * Also visit PermissionRoles.php and add to the $ret['perms_connect'] property for any role
@ -21,7 +19,7 @@ class Permissions {
* are the responsibility of the channel owner to manage. You just don't want to create any * are the responsibility of the channel owner to manage. You just don't want to create any
* suprises or break things so you have an opportunity to provide sane settings. * suprises or break things so you have an opportunity to provide sane settings.
* *
* Update the version here and in PermissionRoles * Update the version here and in PermissionRoles.
* *
* *
* Permissions with 'view' in the name are considered read permissions. Anything * Permissions with 'view' in the name are considered read permissions. Anything
@ -33,13 +31,22 @@ class Permissions {
* something different for a specific permission within the given role. * something different for a specific permission within the given role.
* *
*/ */
class Permissions {
static public function version() { static public function version() {
// This must match the version in PermissionRoles.php before permission updates can run. // This must match the version in PermissionRoles.php before permission updates can run.
return 2; return 2;
} }
/**
* @brief Return an array with Permissions.
*
* @hooks permissions_list
* * \e array \b permissions
* * \e string \b filter
* @param string $filter (optional) only passed to hook permission_list
* @return Associative array with permissions and short description.
*/
static public function Perms($filter = '') { static public function Perms($filter = '') {
$perms = [ $perms = [
@ -63,18 +70,27 @@ class Permissions {
'delegate' => t('Can administer my channel') 'delegate' => t('Can administer my channel')
]; ];
$x = array('permissions' => $perms, 'filter' => $filter); $x = [
call_hooks('permissions_list',$x); 'permissions' => $perms,
return($x['permissions']); 'filter' => $filter
];
call_hooks('permissions_list', $x);
return($x['permissions']);
} }
/**
* @brief Perms from the above list that are blocked from anonymous observers.
*
* e.g. you must be authenticated.
*
* @hooks write_perms
* * \e array \b permissions
* @return Associative array with permissions and short description.
*/
static public function BlockedAnonPerms() { static public function BlockedAnonPerms() {
// Perms from the above list that are blocked from anonymous observers. $res = [];
// e.g. you must be authenticated.
$res = array();
$perms = PermissionLimits::Std_limits(); $perms = PermissionLimits::Std_limits();
foreach($perms as $perm => $limit) { foreach($perms as $perm => $limit) {
if($limit != PERMS_PUBLIC) { if($limit != PERMS_PUBLIC) {
@ -82,17 +98,22 @@ class Permissions {
} }
} }
$x = array('permissions' => $res); $x = ['permissions' => $res];
call_hooks('write_perms',$x); call_hooks('write_perms', $x);
return($x['permissions']);
return($x['permissions']);
} }
// converts [ 0 => 'view_stream', ... ] /**
// to [ 'view_stream' => 1 ] * @brief Converts indexed perms array to associative perms array.
// for any permissions in $arr; *
// Undeclared permissions are set to 0 * Converts [ 0 => 'view_stream', ... ]
* to [ 'view_stream' => 1 ] for any permissions in $arr;
* Undeclared permissions which exist in Perms() are added and set to 0.
*
* @param array $arr
* @return array
*/
static public function FilledPerms($arr) { static public function FilledPerms($arr) {
if(is_null($arr)) { if(is_null($arr)) {
btlogger('FilledPerms: null'); btlogger('FilledPerms: null');
@ -101,15 +122,26 @@ class Permissions {
$everything = self::Perms(); $everything = self::Perms();
$ret = []; $ret = [];
foreach($everything as $k => $v) { foreach($everything as $k => $v) {
if(in_array($k,$arr)) if(in_array($k, $arr))
$ret[$k] = 1; $ret[$k] = 1;
else else
$ret[$k] = 0; $ret[$k] = 0;
} }
return $ret;
return $ret;
} }
/**
* @brief Convert perms array to indexed array.
*
* Converts [ 'view_stream' => 1 ] for any permissions in $arr
* to [ 0 => ['name' => 'view_stream', 'value' => 1], ... ]
*
* @param array $arr associative perms array 'view_stream' => 1
* @return Indexed array with elements that look like
* * \e string \b name the perm name (e.g. view_stream)
* * \e int \b value the value of the perm (e.g. 1)
*/
static public function OPerms($arr) { static public function OPerms($arr) {
$ret = []; $ret = [];
if($arr) { if($arr) {
@ -120,7 +152,12 @@ class Permissions {
return $ret; return $ret;
} }
/**
* @brief
*
* @param int $channel_id
* @return boolean|array
*/
static public function FilledAutoperms($channel_id) { static public function FilledAutoperms($channel_id) {
if(! intval(get_pconfig($channel_id,'system','autoperms'))) if(! intval(get_pconfig($channel_id,'system','autoperms')))
return false; return false;
@ -137,16 +174,33 @@ class Permissions {
return $arr; return $arr;
} }
static public function PermsCompare($p1,$p2) { /**
* @brief Compares that all Permissions from $p1 exist also in $p2.
*
* @param array $p1 The perms that have to exist in $p2
* @param array $p2 The perms to compare against
* @return boolean true if all perms from $p1 exist also in $p2
*/
static public function PermsCompare($p1, $p2) {
foreach($p1 as $k => $v) { foreach($p1 as $k => $v) {
if(! array_key_exists($k,$p2)) if(! array_key_exists($k, $p2))
return false; return false;
if($p1[$k] != $p2[$k]) if($p1[$k] != $p2[$k])
return false; return false;
} }
return true; return true;
} }
/**
* @brief
*
* @param int $channel_id A channel id
* @return associative array
* * \e array \b perms Permission array
* * \e int \b automatic 0 or 1
*/
static public function connect_perms($channel_id) { static public function connect_perms($channel_id) {

View File

@ -666,9 +666,6 @@ class Apps {
static public function app_decode($s) { static public function app_decode($s) {
$x = base64_decode(str_replace(array('<br />',"\r","\n",' '),array('','','',''),$s)); $x = base64_decode(str_replace(array('<br />',"\r","\n",' '),array('','','',''),$s));
return json_decode($x,true); return json_decode($x,true);

View File

@ -40,7 +40,7 @@ class Notifications extends \Zotlabs\Web\Controller {
$o .= replace_macros(get_markup_template('notifications.tpl'),array( $o .= replace_macros(get_markup_template('notifications.tpl'),array(
'$notif_header' => t('System Notifications'), '$notif_header' => t('System Notifications'),
'$notif_link_mark_seen' => t('Mark all system notifications seen'), '$notif_link_mark_seen' => t('Mark all seen'),
'$notif_content' => $notif_content, '$notif_content' => $notif_content,
'$notifications_available' => $notifications_available, '$notifications_available' => $notifications_available,
)); ));

View File

@ -452,7 +452,7 @@ function db_getfunc($f) {
function db_logger($s,$level = LOGGER_NORMAL,$syslog = LOG_INFO) { function db_logger($s,$level = LOGGER_NORMAL,$syslog = LOG_INFO) {
if(\DBA::$logging) if(\DBA::$logging || ! \DBA::$dba)
return; return;
$saved = \DBA::$dba->debug; $saved = \DBA::$dba->debug;

View File

@ -1158,7 +1158,6 @@ function list_smilies($default_only = false) {
$texts = array( $texts = array(
'&lt;3', '&lt;3',
'&lt;/3', '&lt;/3',
'&lt;\\3',
':-)', ':-)',
';-)', ';-)',
':-(', ':-(',
@ -1193,7 +1192,6 @@ function list_smilies($default_only = false) {
$icons = array( $icons = array(
'<img class="smiley" src="' . z_root() . '/images/emoticons/smiley-heart.gif" alt="&lt;3" />', '<img class="smiley" src="' . z_root() . '/images/emoticons/smiley-heart.gif" alt="&lt;3" />',
'<img class="smiley" src="' . z_root() . '/images/emoticons/smiley-brokenheart.gif" alt="&lt;/3" />', '<img class="smiley" src="' . z_root() . '/images/emoticons/smiley-brokenheart.gif" alt="&lt;/3" />',
'<img class="smiley" src="' . z_root() . '/images/emoticons/smiley-brokenheart.gif" alt="&lt;\\3" />',
'<img class="smiley" src="' . z_root() . '/images/emoticons/smiley-smile.gif" alt=":-)" />', '<img class="smiley" src="' . z_root() . '/images/emoticons/smiley-smile.gif" alt=":-)" />',
'<img class="smiley" src="' . z_root() . '/images/emoticons/smiley-wink.gif" alt=";-)" />', '<img class="smiley" src="' . z_root() . '/images/emoticons/smiley-wink.gif" alt=";-)" />',
'<img class="smiley" src="' . z_root() . '/images/emoticons/smiley-frown.gif" alt=":-(" />', '<img class="smiley" src="' . z_root() . '/images/emoticons/smiley-frown.gif" alt=":-(" />',

View File

@ -56,7 +56,7 @@ server {
ssl_certificate_key /etc/nginx/ssl/example.net.key; ssl_certificate_key /etc/nginx/ssl/example.net.key;
ssl_session_timeout 5m; ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-DSS-AES128-SHA256:DHE-DSS-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA:!DHE-RSA-AES128-GCM-SHA256:!DHE-RSA-AES256-GCM-SHA384:!DHE-RSA-AES128-SHA256:!DHE-RSA-AES256-SHA:!DHE-RSA-AES128-SHA:!DHE-RSA-AES256-SHA256:!DHE-RSA-CAMELLIA128-SHA:!DHE-RSA-CAMELLIA256-SHA; ssl_ciphers ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS;
ssl_prefer_server_ciphers on; ssl_prefer_server_ciphers on;
fastcgi_param HTTPS on; fastcgi_param HTTPS on;

View File

@ -2533,7 +2533,7 @@ function update_r1189() {
} }
function update_r1190() { function update_r1190() {
$r1 = q("alter table abook add abook_not_here int(11) not null default '0' "); $r1 = q("alter table abook add abook_not_here smallint not null default 0 ");
$r2 = q("create index abook_not_here on abook (abook_not_here)"); $r2 = q("create index abook_not_here on abook (abook_not_here)");

View File

@ -0,0 +1,148 @@
<?php
/*
* Copyright (c) 2017 Hubzilla
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Zotlabs\Tests\Unit\Access;
use Zotlabs\Tests\Unit\UnitTestCase;
use Zotlabs\Access\Permissions;
/**
* @brief Unit Test case for Permissions class.
*
* @covers Zotlabs\Access\Permissions
*/
class PermissionsTest extends UnitTestCase {
/**
* @dataProvider FilledPermsProvider
*/
public function testFilledPerms($permarr, $expected) {
$this->markTestIncomplete(
'Need to mock static function Permissions::Perms() ...'
);
//$this->assertEquals($expected, Permissions::FilledPerms($permarr));
/* $perms = $this->getMockBuilder(Permissions::class)
->setMethods(['Perms'])
->getMock();
$perms->expects($this->once())
->method('Perms');
// still calls the static self::Perms()
$perms->FilledPerms($permarr);
*/
}
public function FilledPermsProvider() {
return [
'empty' => [
[],
['perm1' => 0, 'perm2' => 0]
],
'valild' => [
[['perm1' => 1]],
['perm1' => 1, 'perm2' => 0]
]
];
}
/* public function testFilledPermsNull() {
// need to mock global function btlogger();
Permissions::FilledPerms(null);
}
*/
/**
* @dataProvider OPermsProvider
*
* @param array $permarr
* @param array $expected
*/
public function testOPerms($permarr, $expected) {
$this->assertEquals($expected, Permissions::OPerms($permarr));
}
/**
* @return Associative array with test values for OPerms()
* * \e array Array to test
* * \e array Expect array
*/
public function OPermsProvider() {
return [
'empty' => [
[],
[]
],
'valid' => [
['perm1' => 1, 'perm2' => 0],
[['name' => 'perm1', 'value' => 1], ['name' => 'perm2', 'value' => 0]]
],
'null array' => [
null,
[]
]
];
}
/**
* @dataProvider permsCompareProvider
*
* @param array $p1
* @param array $p2
* @param boolean $expectedresult
*/
public function testPermsCompare($p1, $p2, $expectedresult) {
$this->assertEquals($expectedresult, Permissions::PermsCompare($p1, $p2));
}
/**
* @return Associative array with test values for PermsCompare()
* * \e array 1st array
* * \e array 2nd array
* * \e boolean expected result for the test
*/
public function permsCompareProvider() {
return [
'equal' => [
['perm1' => 1, 'perm2' => 0],
['perm1' => 1, 'perm2' => 0],
true
],
'different values' => [
['perm1' => 1, 'perm2' => 0],
['perm1' => 0, 'perm2' => 1],
false
],
'different order' => [
['perm1' => 1, 'perm2' => 0],
['perm2' => 0, 'perm1' => 1],
true
],
'partial first in second' => [
['perm1' => 1],
['perm1' => 1, 'perm2' => 0],
true
],
'partial second in first' => [
['perm1' => 1, 'perm2' => 0],
['perm1' => 1],
false
]
];
}
}

View File

@ -32,3 +32,9 @@
margin-top: 18px; margin-top: 18px;
margin-left: 20px; margin-left: 20px;
} }
main {
max-width: 790px;
margin-left: auto;
margin-right: auto;
}

View File

@ -1,11 +1,11 @@
<div class="generic-content-wrapper-styled"> <div class="generic-content-wrapper">
<div class="section-title-wrapper clearfix">
<h1>{{$notif_header}}</h1> {{if $notifications_available}}
<a href="#" class="btn btn-outline-secondary btn-sm float-right" onclick="markRead('notify'); setTimeout(function() { window.location.href=window.location.href; },1500); return false;">{{$notif_link_mark_seen}}</a>
{{if $notifications_available}} {{/if}}
<a href="#" onclick="markRead('notify'); setTimeout(function() { window.location.href=window.location.href; },1500); return false;">{{$notif_link_mark_seen}}</a> <h2>{{$notif_header}}</h2>
{{/if}} </div>
<div class="notif-network-wrapper"> <div class="section-content-wrapper">
{{$notif_content}} {{$notif_content}}
</div> </div>
</div> </div>

View File

@ -1,3 +1,3 @@
<div class="notif-item"> <div class="mb-2 notif-item">
<a href="{{$item_link}}"><img src="{{$item_image}}" class="notif-image">{{$item_text}} <span class="notif-when">{{$item_when}}</span></a> <a href="{{$item_link}}"><img src="{{$item_image}}" class="menu-img-1">{{$item_text}} <span class="notif-when">{{$item_when}}</span></a>
</div> </div>