Merge pull request #4471 from annando/parent-uid
Frontend to set the parent-uid field
This commit is contained in:
commit
281734d5dc
2 changed files with 76 additions and 22 deletions
|
@ -14,6 +14,24 @@ function delegate_init(App $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)
|
||||
{
|
||||
if (!local_user()) {
|
||||
|
@ -81,6 +99,7 @@ function delegate_content(App $a)
|
|||
}
|
||||
|
||||
// find every contact who might be a candidate for delegation
|
||||
$potentials = [];
|
||||
|
||||
$r = q("SELECT `nurl`
|
||||
FROM `contact`
|
||||
|
@ -92,18 +111,12 @@ function delegate_content(App $a)
|
|||
intval(local_user()),
|
||||
dbesc(NETWORK_DFRN)
|
||||
);
|
||||
if (!DBM::is_result($r)) {
|
||||
notice(L10n::t('No potential page delegates located.') . EOL);
|
||||
return;
|
||||
}
|
||||
|
||||
if (DBM::is_result($r)) {
|
||||
$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
|
||||
|
@ -115,11 +128,39 @@ function delegate_content(App $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'), [
|
||||
'$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'),
|
||||
'$delegates_header' => L10n::t('Delegates'),
|
||||
'$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.'),
|
||||
'$head_managers' => L10n::t('Existing Page Managers'),
|
||||
|
|
|
@ -1,10 +1,23 @@
|
|||
|
||||
<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>
|
||||
|
||||
{{if $managers}}
|
||||
<h3>{{$head_managers}}</h3>
|
||||
<h4>{{$head_managers}}</h4>
|
||||
|
||||
{{foreach $managers as $x}}
|
||||
|
||||
|
@ -20,7 +33,7 @@
|
|||
{{/if}}
|
||||
|
||||
|
||||
<h3>{{$head_delegates}}</h3>
|
||||
<h4>{{$head_delegates}}</h4>
|
||||
|
||||
{{if $delegates}}
|
||||
{{foreach $delegates as $x}}
|
||||
|
@ -39,7 +52,7 @@
|
|||
<hr />
|
||||
|
||||
|
||||
<h3>{{$head_potentials}}</h3>
|
||||
<h4>{{$head_potentials}}</h4>
|
||||
{{if $potentials}}
|
||||
{{foreach $potentials as $x}}
|
||||
|
||||
|
|
Loading…
Reference in a new issue