Merge pull request #4471 from annando/parent-uid

Frontend to set the parent-uid field
This commit is contained in:
Hypolite Petovan 2018-02-18 11:48:39 -05:00 committed by GitHub
commit 281734d5dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 76 additions and 22 deletions

View File

@ -14,6 +14,24 @@ function delegate_init(App $a)
return settings_init($a); return settings_init($a);
} }
function delegate_post(App $a)
{
if (!local_user()) {
return;
}
if (count($a->user) && x($a->user, 'uid') && $a->user['uid'] != local_user()) {
notice(L10n::t('Permission denied.') . EOL);
return;
}
check_form_security_token_redirectOnErr('/delegate', 'delegate');
$parent_uid = defaults($_POST, 'parent_user', 0);
dba::update('user', ['parent-uid' => $parent_uid], ['uid' => local_user()]);
}
function delegate_content(App $a) function delegate_content(App $a)
{ {
if (!local_user()) { if (!local_user()) {
@ -81,6 +99,7 @@ function delegate_content(App $a)
} }
// find every contact who might be a candidate for delegation // find every contact who might be a candidate for delegation
$potentials = [];
$r = q("SELECT `nurl` $r = q("SELECT `nurl`
FROM `contact` FROM `contact`
@ -92,34 +111,56 @@ function delegate_content(App $a)
intval(local_user()), intval(local_user()),
dbesc(NETWORK_DFRN) dbesc(NETWORK_DFRN)
); );
if (!DBM::is_result($r)) {
notice(L10n::t('No potential page delegates located.') . EOL);
return;
}
$nicknames = [];
foreach ($r as $rr) {
$nicknames[] = "'" . dbesc(basename($rr['nurl'])) . "'";
}
$potentials = [];
$nicks = implode(',', $nicknames);
// get user records for all potential page delegates who are not already delegates or managers
$r = q("SELECT `uid`, `username`, `nickname` FROM `user` WHERE `nickname` IN ($nicks)");
if (DBM::is_result($r)) { if (DBM::is_result($r)) {
$nicknames = [];
foreach ($r as $rr) { foreach ($r as $rr) {
if (!in_array($rr['uid'], $uids)) { $nicknames[] = "'" . dbesc(basename($rr['nurl'])) . "'";
$potentials[] = $rr; }
$nicks = implode(',', $nicknames);
// get user records for all potential page delegates who are not already delegates or managers
$r = q("SELECT `uid`, `username`, `nickname` FROM `user` WHERE `nickname` IN ($nicks)");
if (DBM::is_result($r)) {
foreach ($r as $rr) {
if (!in_array($rr['uid'], $uids)) {
$potentials[] = $rr;
}
} }
} }
} }
settings_init($a); settings_init($a);
$user = dba::selectFirst('user', ['parent-uid', 'email'], ['uid' => local_user()]);
$parent_user = null;
if (DBM::is_result($user)) {
if (!dba::exists('user', ['parent-uid' => local_user()])) {
$parent_uid = $user['parent-uid'];
$parents = [0 => L10n::t('No parent user')];
$fields = ['uid', 'username', 'nickname'];
$condition = ['email' => $user['email'], 'verified' => true, 'blocked' => false, 'parent-uid' => 0];
$parent_users = dba::select('user', $fields, $condition);
while ($parent = dba::fetch($parent_users)) {
if ($parent['uid'] != local_user()) {
$parents[$parent['uid']] = sprintf('%s (%s)', $parent['username'], $parent['nickname']);
}
}
$parent_user = ['parent_user', '', $parent_uid, '', $parents];
}
}
$o = replace_macros(get_markup_template('delegate.tpl'), [ $o = replace_macros(get_markup_template('delegate.tpl'), [
'$form_security_token' => get_form_security_token('delegate'),
'$parent_header' => L10n::t('Parent User'),
'$parent_user' => $parent_user,
'$parent_desc' => L10n::t('Parent users have total control about this account, including the account settings. Please double check whom you give this access.'),
'$submit' => L10n::t('Save Settings'),
'$header' => L10n::t('Delegate Page Management'), '$header' => L10n::t('Delegate Page Management'),
'$delegates_header' => L10n::t('Delegates'),
'$base' => System::baseUrl(), '$base' => System::baseUrl(),
'$desc' => L10n::t('Delegates are able to manage all aspects of this account/page except for basic account settings. Please do not delegate your personal account to anybody that you do not trust completely.'), '$desc' => L10n::t('Delegates are able to manage all aspects of this account/page except for basic account settings. Please do not delegate your personal account to anybody that you do not trust completely.'),
'$head_managers' => L10n::t('Existing Page Managers'), '$head_managers' => L10n::t('Existing Page Managers'),

View File

@ -1,10 +1,23 @@
<h3>{{$header}}</h3> <h3>{{$header}}</h3>
{{if $parent_user}}
<h4>{{$parent_header}}</h4>
<div id="delegate-parent-desc" class="delegate-parent-desc">{{$parent_desc}}</div>
<div id="delegate-parent" class="delegate-parent">
<form action="{{$baseurl}}/delegate" method="post">
<input type='hidden' name='form_security_token' value='{{$form_security_token}}'>
{{include file="field_select.tpl" field=$parent_user}}
<div class="submit"><input type="submit" name="delegate" value="{{$submit|escape:'html'}}" /></div>
</form>
</div>
{{/if}}
<h4>{{$delegates_header}}</h4>
<div id="delegate-desc" class="delegate-desc">{{$desc}}</div> <div id="delegate-desc" class="delegate-desc">{{$desc}}</div>
{{if $managers}} {{if $managers}}
<h3>{{$head_managers}}</h3> <h4>{{$head_managers}}</h4>
{{foreach $managers as $x}} {{foreach $managers as $x}}
@ -20,7 +33,7 @@
{{/if}} {{/if}}
<h3>{{$head_delegates}}</h3> <h4>{{$head_delegates}}</h4>
{{if $delegates}} {{if $delegates}}
{{foreach $delegates as $x}} {{foreach $delegates as $x}}
@ -39,7 +52,7 @@
<hr /> <hr />
<h3>{{$head_potentials}}</h3> <h4>{{$head_potentials}}</h4>
{{if $potentials}} {{if $potentials}}
{{foreach $potentials as $x}} {{foreach $potentials as $x}}