auto permissions (such as for forums or whatever) - untested but might just work

This commit is contained in:
friendica 2013-01-23 21:15:40 -08:00
parent c1a5c88720
commit 6e6b268e25
6 changed files with 183 additions and 115 deletions

View File

@ -86,9 +86,10 @@ function get_all_perms($uid,$observer,$internal_use = true) {
if($observer) { if($observer) {
if(! $abook_checked) { if(! $abook_checked) {
$x = q("select abook_my_perms, abook_flags from abook $x = q("select abook_my_perms, abook_flags from abook
where abook_channel = %d and abook_xchan = '%s' limit 1", where abook_channel = %d and abook_xchan = '%s' and not ( abook_flags & %d ) limit 1",
intval($uid), intval($uid),
dbesc($observer) dbesc($observer),
intval(ABOOK_FLAG_SELF)
); );
$abook_checked = true; $abook_checked = true;
} }
@ -210,9 +211,10 @@ function perm_is_allowed($uid,$observer,$permission) {
return false; return false;
if($observer) { if($observer) {
$x = q("select abook_my_perms, abook_flags from abook where abook_channel = %d and abook_xchan = '%s' limit 1", $x = q("select abook_my_perms, abook_flags from abook where abook_channel = %d and abook_xchan = '%s' and not ( abook_flags & %d ) limit 1",
intval($uid), intval($uid),
dbesc($observer) dbesc($observer),
intval(ABOOK_FLAG_SELF)
); );
// If they're blocked - they can't read or write // If they're blocked - they can't read or write

View File

@ -107,8 +107,8 @@ function connections_post(&$a) {
notice( t('Failed to update connnection record.') . EOL); notice( t('Failed to update connnection record.') . EOL);
if((x($a->data,'abook')) && $a->data['abook']['abook_my_perms'] != $abook_my_perms) { if((x($a->data,'abook')) && $a->data['abook']['abook_my_perms'] != $abook_my_perms
// FIXME - this message type is not yet handled in the notifier && (! ($a->data['abook']['abook_flags'] & ABOOK_FLAG_SELF))) {
proc_run('php', 'include/notifier.php', 'permission_update', $contact_id); proc_run('php', 'include/notifier.php', 'permission_update', $contact_id);
} }
@ -289,15 +289,18 @@ function connections_content(&$a) {
); );
$self = false;
if(! ($contact['abook_flags'] & ABOOK_FLAG_SELF)) {
$tab_tpl = get_markup_template('common_tabs.tpl'); $tab_tpl = get_markup_template('common_tabs.tpl');
$t = replace_macros($tab_tpl, array('$tabs'=>$tabs)); $t = replace_macros($tab_tpl, array('$tabs'=>$tabs));
}
else
$self = true;
$a->page['htmlhead'] .= replace_macros(get_markup_template('contact_head.tpl'), array( $a->page['htmlhead'] .= replace_macros(get_markup_template('contact_head.tpl'), array(
'$baseurl' => $a->get_baseurl(true), '$baseurl' => $a->get_baseurl(true),
'$editselect' => $editselect, '$editselect' => $editselect
)); ));
require_once('include/contact_selectors.php'); require_once('include/contact_selectors.php');
@ -329,11 +332,13 @@ function connections_content(&$a) {
$perms[] = array('perms_' . $k, $v[3], (($contact['abook_their_perms'] & $v[1]) ? "1" : ""),((($contact['abook_my_perms'] & $v[1]) || $existing[$k]) ? "1" : ""), $v[1], (($channel[$v[0]] == PERMS_SPECIFIC) ? '' : '1'), $v[4]); $perms[] = array('perms_' . $k, $v[3], (($contact['abook_their_perms'] & $v[1]) ? "1" : ""),((($contact['abook_my_perms'] & $v[1]) || $existing[$k]) ? "1" : ""), $v[1], (($channel[$v[0]] == PERMS_SPECIFIC) ? '' : '1'), $v[4]);
} }
$o .= replace_macros($tpl,array( $o .= replace_macros($tpl,array(
'$header' => sprintf( t('Connections: settings for %s'),$contact['xchan_name']), '$header' => (($self) ? t('Automatic Permissions Settings') : sprintf( t('Connections: settings for %s'),$contact['xchan_name'])),
'$addr' => $contact['xchan_addr'], '$addr' => $contact['xchan_addr'],
'$notself' => (($self) ? '' : '1'),
'$self' => (($self) ? '1' : ''),
'$autolbl' => t('When receiving a channel introduction, any permissions provided here will be applied to the new connnection automatically and the introduction approved. Leave this page if you do not wish to use this feature.'),
'$viewprof' => t('View Profile'), '$viewprof' => t('View Profile'),
'$lbl_slider' => t('Slide to adjust your degree of friendship'), '$lbl_slider' => t('Slide to adjust your degree of friendship'),
'$slide' => $slide, '$slide' => $slide,
@ -348,15 +353,17 @@ function connections_content(&$a) {
'$them' => t('Their Settings'), '$them' => t('Their Settings'),
'$me' => t('My Settings'), '$me' => t('My Settings'),
'$perms' => $perms, '$perms' => $perms,
'$forum' => t('Forum Members'),
'$full' => t('Full Sharing'), '$full' => t('Full Sharing'),
'$cautious' => t('Cautious Sharing'), '$cautious' => t('Cautious Sharing'),
'$follow' => t('Follow Only'), '$follow' => t('Follow Only'),
'$permlbl' => t('Permissions'),
'$advanced' => t('Advanced Permissions'), '$advanced' => t('Advanced Permissions'),
'$quick' => t('Quick Links'), '$quick' => t('Quick Links'),
'$common_link' => $a->get_baseurl(true) . '/common/loc/' . local_user() . '/' . $contact['id'], '$common_link' => $a->get_baseurl(true) . '/common/loc/' . local_user() . '/' . $contact['id'],
'$all_friends' => $all_friends, '$all_friends' => $all_friends,
'$relation_text' => $relation_text, '$relation_text' => $relation_text,
'$visit' => sprintf( t('Visit %s\'s profile [%s]'),$contact['xchan_name'],$contact['xchan_url']), '$visit' => sprintf( t('Visit %s\'s profile - %s'),$contact['xchan_name'],$contact['xchan_url']),
'$blockunblock' => t('Block/Unblock contact'), '$blockunblock' => t('Block/Unblock contact'),
'$ignorecont' => t('Ignore contact'), '$ignorecont' => t('Ignore contact'),
'$lblcrepair' => t("Repair URL settings"), '$lblcrepair' => t("Repair URL settings"),

View File

@ -14,16 +14,29 @@ function get_theme_config_file($theme){
return null; return null;
} }
function settings_init(&$a) { function settings_aside(&$a) {
// default is channel settings in the absence of other arguments // default is channel settings in the absence of other arguments
if(argc() == 1) { if(argc() == 1) {
// We are setting these values - don't use the argc(), argv() functions here
$a->argc = 2; $a->argc = 2;
$a->argv[] = 'channel'; $a->argv[] = 'channel';
} }
$abook_self_id = 0;
// Retrieve the 'self' address book entry for use in the auto-permissions link
if(local_user()) {
$abk = q("select abook_id from abook where abook_channel = %d and ( abook_flags & %d ) limit 1",
intval(local_user()),
intval(ABOOK_FLAG_SELF)
);
if($abk)
$abook_self_id = $abk[0]['abook_id'];
}
$tabs = array( $tabs = array(
array( array(
@ -74,6 +87,12 @@ function settings_init(&$a) {
// 'selected' => '' // 'selected' => ''
// ), // ),
array(
'label' => t('Automatic Permissions (Advanced)'),
'url' => $a->get_baseurl(true) . '/connections/' . $abook_self_id,
'selected' => ''
),
); );

View File

@ -26,6 +26,8 @@ function connectFullShare() {
$('#me_id_perms_view_profile').attr('checked','checked'); $('#me_id_perms_view_profile').attr('checked','checked');
$('#me_id_perms_view_photos').attr('checked','checked'); $('#me_id_perms_view_photos').attr('checked','checked');
$('#me_id_perms_view_contacts').attr('checked','checked'); $('#me_id_perms_view_contacts').attr('checked','checked');
$('#me_id_perms_view_storage').attr('checked','checked');
$('#me_id_perms_view_pages').attr('checked','checked');
$('#me_id_perms_send_stream').attr('checked','checked'); $('#me_id_perms_send_stream').attr('checked','checked');
$('#me_id_perms_post_wall').attr('checked','checked'); $('#me_id_perms_post_wall').attr('checked','checked');
$('#me_id_perms_post_comments').attr('checked','checked'); $('#me_id_perms_post_comments').attr('checked','checked');
@ -39,12 +41,28 @@ function connectCautiousShare() {
$('#me_id_perms_view_stream').attr('checked','checked'); $('#me_id_perms_view_stream').attr('checked','checked');
$('#me_id_perms_view_profile').attr('checked','checked'); $('#me_id_perms_view_profile').attr('checked','checked');
$('#me_id_perms_view_photos').attr('checked','checked'); $('#me_id_perms_view_photos').attr('checked','checked');
$('#me_id_perms_view_storage').attr('checked','checked');
$('#me_id_perms_view_pages').attr('checked','checked');
$('#me_id_perms_send_stream').attr('checked','checked'); $('#me_id_perms_send_stream').attr('checked','checked');
$('#me_id_perms_post_comments').attr('checked','checked'); $('#me_id_perms_post_comments').attr('checked','checked');
$('#me_id_perms_post_mail').attr('checked','checked'); $('#me_id_perms_post_mail').attr('checked','checked');
} }
function connectForum() {
$('#me_id_perms_view_stream').attr('checked','checked');
$('#me_id_perms_view_profile').attr('checked','checked');
$('#me_id_perms_view_photos').attr('checked','checked');
$('#me_id_perms_view_contacts').attr('checked','checked');
$('#me_id_perms_view_storage').attr('checked','checked');
$('#me_id_perms_view_pages').attr('checked','checked');
$('#me_id_perms_send_stream').attr('checked','checked');
$('#me_id_perms_post_comments').attr('checked','checked');
$('#me_id_perms_post_mail').attr('checked','checked');
$('#me_id_perms_tag_deliver').attr('checked','checked');
}
function connectFollowOnly() { function connectFollowOnly() {
$('#me_id_perms_send_stream').attr('checked','checked'); $('#me_id_perms_send_stream').attr('checked','checked');

View File

@ -3,20 +3,28 @@
<h3>$addr</h3> <h3>$addr</h3>
{{ if $notself }}
<div id="connection-flag-tabs"> <div id="connection-flag-tabs">
$tabs $tabs
</div> </div>
{{ endif }}
{{ if $self }}
<div id="autoperm-desc" class="descriptive-paragraph">$autolbl</div>
{{ endif }}
<div id="contact-edit-wrapper"> <div id="contact-edit-wrapper">
{{ if $notself }}
{{ if $slide }} {{ if $slide }}
<h3>$lbl_slider</h3> <h3>$lbl_slider</h3>
$slide $slide
{{ endif }}
{{ endif }} {{ endif }}
<h3>Permissions</h3> <h3>$permlbl</h3>
<form action="connections/$contact_id" method="post" > <form action="connections/$contact_id" method="post" >
<input type="hidden" name="contact_id" value="$contact_id"> <input type="hidden" name="contact_id" value="$contact_id">
@ -25,6 +33,9 @@ $slide
<br /> <br />
<b>$quick</b> <b>$quick</b>
<ul> <ul>
{{ if $self }}
<li><a href="#" onclick="connectForum(); return false;">$forum</a></li>
{{ endif }}
<li><a href="#" onclick="connectFullShare(); return false;">$full</a></li> <li><a href="#" onclick="connectFullShare(); return false;">$full</a></li>
<li><a href="#" onclick="connectCautiousShare(); return false;">$cautious</a></li> <li><a href="#" onclick="connectCautiousShare(); return false;">$cautious</a></li>
<li><a href="#" onclick="connectFollowOnly(); return false;">$follow</a></li> <li><a href="#" onclick="connectFollowOnly(); return false;">$follow</a></li>

View File

@ -3,20 +3,28 @@
<h3>{{$addr}}</h3> <h3>{{$addr}}</h3>
{{if $notself}}
<div id="connection-flag-tabs"> <div id="connection-flag-tabs">
{{$tabs}} {{$tabs}}
</div> </div>
{{/if}}
{{if $self}}
<div id="autoperm-desc" class="descriptive-paragraph">{{$autolbl}}</div>
{{/if}}
<div id="contact-edit-wrapper"> <div id="contact-edit-wrapper">
{{if $notself}}
{{if $slide}} {{if $slide}}
<h3>{{$lbl_slider}}</h3> <h3>{{$lbl_slider}}</h3>
{{$slide}} {{$slide}}
{{/if}}
{{/if}} {{/if}}
<h3>Permissions</h3> <h3>{{$permlbl}}</h3>
<form action="connections/{{$contact_id}}" method="post" > <form action="connections/{{$contact_id}}" method="post" >
<input type="hidden" name="contact_id" value="{{$contact_id}}"> <input type="hidden" name="contact_id" value="{{$contact_id}}">
@ -25,6 +33,9 @@
<br /> <br />
<b>{{$quick}}</b> <b>{{$quick}}</b>
<ul> <ul>
{{if $self}}
<li><a href="#" onclick="connectForum(); return false;">{{$forum}}</a></li>
{{/if}}
<li><a href="#" onclick="connectFullShare(); return false;">{{$full}}</a></li> <li><a href="#" onclick="connectFullShare(); return false;">{{$full}}</a></li>
<li><a href="#" onclick="connectCautiousShare(); return false;">{{$cautious}}</a></li> <li><a href="#" onclick="connectCautiousShare(); return false;">{{$cautious}}</a></li>
<li><a href="#" onclick="connectFollowOnly(); return false;">{{$follow}}</a></li> <li><a href="#" onclick="connectFollowOnly(); return false;">{{$follow}}</a></li>