From d7b567447616c560e2bb1e1d4fad9193042b1dd2 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 26 Jul 2020 18:35:02 -0400 Subject: [PATCH] Move mod/lockview to Module\PermissionTooltip - Add explicit type parameter to lockview() in main.js --- doc/Addons.md | 8 +- doc/de/Addons.md | 8 +- src/Module/PermissionTooltip.php | 122 ++++++++++++++++++ static/routes.config.php | 2 + view/js/main.js | 27 ++-- view/templates/photo_view.tpl | 2 +- view/templates/search_item.tpl | 2 +- view/templates/wall_thread.tpl | 2 +- view/theme/frio/templates/photo_view.tpl | 2 +- view/theme/frio/templates/search_item.tpl | 4 +- view/theme/frio/templates/wall_thread.tpl | 4 +- view/theme/quattro/templates/photo_view.tpl | 2 +- view/theme/quattro/templates/search_item.tpl | 2 +- view/theme/quattro/templates/wall_thread.tpl | 2 +- view/theme/smoothly/templates/search_item.tpl | 2 +- view/theme/smoothly/templates/wall_thread.tpl | 2 +- view/theme/vier/templates/photo_item.tpl | 2 +- view/theme/vier/templates/photo_view.tpl | 2 +- view/theme/vier/templates/search_item.tpl | 4 +- view/theme/vier/templates/wall_thread.tpl | 2 +- 20 files changed, 158 insertions(+), 45 deletions(-) create mode 100644 src/Module/PermissionTooltip.php diff --git a/doc/Addons.md b/doc/Addons.md index 54363cb1d7..c1861c7913 100644 --- a/doc/Addons.md +++ b/doc/Addons.md @@ -604,10 +604,6 @@ Here is a complete list of all hook callbacks with file locations (as of 24-Sep- Hook::callAll('post_local_end', $arr); -### mod/lockview.php - - Hook::callAll('lockview_content', $item); - ### mod/uexport.php Hook::callAll('uexport_options', $options); @@ -679,6 +675,10 @@ Here is a complete list of all hook callbacks with file locations (as of 24-Sep- Hook::callAll('register_account', $uid); Hook::callAll('remove_user', $user); +### src/Module/PermissionTooltip.php + + Hook::callAll('lockview_content', $item); + ### src/Content/ContactBlock.php Hook::callAll('contact_block_end', $arr); diff --git a/doc/de/Addons.md b/doc/de/Addons.md index 745010ff4e..2ff7495497 100644 --- a/doc/de/Addons.md +++ b/doc/de/Addons.md @@ -312,10 +312,6 @@ Eine komplette Liste aller Hook-Callbacks mit den zugehörigen Dateien (am 01-Ap Hook::callAll('post_local_end', $arr); -### mod/lockview.php - - Hook::callAll('lockview_content', $item); - ### mod/uexport.php Hook::callAll('uexport_options', $options); @@ -422,6 +418,10 @@ Eine komplette Liste aller Hook-Callbacks mit den zugehörigen Dateien (am 01-Ap Hook::callAll('storage_instance', $data); +### src/Module/PermissionTooltip.php + + Hook::callAll('lockview_content', $item); + ### src/Worker/Directory.php Hook::callAll('globaldir_update', $arr); diff --git a/src/Module/PermissionTooltip.php b/src/Module/PermissionTooltip.php new file mode 100644 index 0000000000..59478b326c --- /dev/null +++ b/src/Module/PermissionTooltip.php @@ -0,0 +1,122 @@ +t('Wrong type "%s", expected one of: %s', $type, implode(', ', $expectedTypes))); + } + + $condition = ['id' => $referenceId]; + if ($type == 'item') { + $fields = ['uid', 'psid', 'private']; + $model = Item::selectFirst($fields, $condition); + } else { + $fields = ['uid', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid']; + $model = DBA::selectFirst($type, $fields, $condition); + } + + if (!DBA::isResult($model)) { + throw new HttpException\NotFoundException(DI::l10n()->t('Model not found')); + } + + if (isset($model['psid'])) { + $permissionSet = DI::permissionSet()->selectFirst(['id' => $model['psid']]); + $model['allow_cid'] = $permissionSet->allow_cid; + $model['allow_gid'] = $permissionSet->allow_gid; + $model['deny_cid'] = $permissionSet->deny_cid; + $model['deny_gid'] = $permissionSet->deny_gid; + } + + // Kept for backwards compatiblity + Hook::callAll('lockview_content', $model); + + if ($model['uid'] != local_user() || + isset($model['private']) + && $model['private'] == Item::PRIVATE + && empty($model['allow_cid']) + && empty($model['allow_gid']) + && empty($model['deny_cid']) + && empty($model['deny_gid'])) + { + echo DI::l10n()->t('Remote privacy information not available.'); + exit; + } + + $aclFormatter = DI::aclFormatter(); + + $allowed_users = $aclFormatter->expand($model['allow_cid']); + $allowed_groups = $aclFormatter->expand($model['allow_gid']); + $deny_users = $aclFormatter->expand($model['deny_cid']); + $deny_groups = $aclFormatter->expand($model['deny_gid']); + + $o = DI::l10n()->t('Visible to:') . '
'; + $l = []; + + if (count($allowed_groups)) { + $key = array_search(Group::FOLLOWERS, $allowed_groups); + if ($key !== false) { + $l[] = '' . DI::l10n()->t('Followers') . ''; + unset($allowed_groups[$key]); + } + + $key = array_search(Group::MUTUALS, $allowed_groups); + if ($key !== false) { + $l[] = '' . DI::l10n()->t('Mutuals') . ''; + unset($allowed_groups[$key]); + } + + foreach (DI::dba()->selectToArray('group', ['name'], ['id' => $allowed_groups]) as $group) { + $l[] = '' . $group['name'] . ''; + } + } + + foreach (DI::dba()->selectToArray('contact', ['name'], ['id' => $allowed_users]) as $contact) { + $l[] = $contact['name']; + } + + if (count($deny_groups)) { + $key = array_search(Group::FOLLOWERS, $deny_groups); + if ($key !== false) { + $l[] = '' . DI::l10n()->t('Followers') . ''; + unset($deny_groups[$key]); + } + + $key = array_search(Group::MUTUALS, $deny_groups); + if ($key !== false) { + $l[] = '' . DI::l10n()->t('Mutuals') . ''; + unset($deny_groups[$key]); + } + + foreach (DI::dba()->selectToArray('group', ['name'], ['id' => $allowed_groups]) as $group) { + $l[] = '' . $group['name'] . ''; + } + } + + foreach (DI::dba()->selectToArray('contact', ['name'], ['id' => $deny_users]) as $contact) { + $l[] = '' . $contact['name'] . ''; + } + + echo $o . implode(', ', $l); + exit(); + } +} diff --git a/static/routes.config.php b/static/routes.config.php index 8c3fba99b7..ddfabd7780 100644 --- a/static/routes.config.php +++ b/static/routes.config.php @@ -237,6 +237,8 @@ return [ '/openid' => [Module\Security\OpenID::class, [R::GET]], '/opensearch' => [Module\OpenSearch::class, [R::GET]], + '/permission/tooltip/{type}/{id:\d+}' => [Module\PermissionTooltip::class, [R::GET]], + '/photo' => [ '/{name}' => [Module\Photo::class, [R::GET]], '/{type}/{name}' => [Module\Photo::class, [R::GET]], diff --git a/view/js/main.js b/view/js/main.js index 60337918b4..36c9cbb88d 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -750,26 +750,23 @@ function getPosition(e) { var lockvisible = false; -function lockview(event,id) { +function lockview(event, type, id) { event = event || window.event; cursor = getPosition(event); if (lockvisible) { - lockviewhide(); + lockvisible = false; + $('#panel').hide(); } else { lockvisible = true; - $.get('lockview/' + id, function(data) { - $('#panel').html(data); - $('#panel').css({'left': cursor.x + 5 , 'top': cursor.y + 5}); - $('#panel').show(); + $.get('permission/tooltip/' + type + '/' + id, function(data) { + $('#panel') + .html(data) + .css({'left': cursor.x + 5 , 'top': cursor.y + 5}) + .show(); }); } } -function lockviewhide() { - lockvisible = false; - $('#panel').hide(); -} - function post_comment(id) { unpause(); commentBusy = true; @@ -940,14 +937,6 @@ function groupChangeMember(gid, cid, sec_token) { }); } -function profChangeMember(gid,cid) { - $('body .fakelink').css('cursor', 'wait'); - $.get('profperm/' + gid + '/' + cid, function(data) { - $('#prof-update-wrapper').html(data); - $('body .fakelink').css('cursor', 'auto'); - }); -} - function contactgroupChangeMember(checkbox, gid, cid) { let url; // checkbox.checked is the checkbox state after the click diff --git a/view/templates/photo_view.tpl b/view/templates/photo_view.tpl index 7170ceb333..0d7ccb20fa 100644 --- a/view/templates/photo_view.tpl +++ b/view/templates/photo_view.tpl @@ -17,7 +17,7 @@ | {{$tools.profile.1}} {{/if}} {{if $tools.lock}} - | {{$tools.lock}} + | {{$tools.lock}} {{/if}} {{/if}} diff --git a/view/templates/search_item.tpl b/view/templates/search_item.tpl index 38aa947498..1a756db8a3 100644 --- a/view/templates/search_item.tpl +++ b/view/templates/search_item.tpl @@ -17,7 +17,7 @@
- {{if $item.lock}}
{{$item.lock}}
+ {{if $item.lock}}
{{$item.lock}}
{{else}}
{{/if}}
{{$item.location nofilter}}
diff --git a/view/templates/wall_thread.tpl b/view/templates/wall_thread.tpl index 0d8c896e16..cec886253f 100644 --- a/view/templates/wall_thread.tpl +++ b/view/templates/wall_thread.tpl @@ -43,7 +43,7 @@
- {{if $item.lock}}
{{$item.lock}}
+ {{if $item.lock}}
{{$item.lock}}
{{else}}
{{/if}}
{{$item.location nofilter}}
diff --git a/view/theme/frio/templates/photo_view.tpl b/view/theme/frio/templates/photo_view.tpl index 91e9dafe44..de45eecff0 100644 --- a/view/theme/frio/templates/photo_view.tpl +++ b/view/theme/frio/templates/photo_view.tpl @@ -37,7 +37,7 @@ {{/if}} {{if $tools.lock}} - + {{/if}} diff --git a/view/theme/frio/templates/search_item.tpl b/view/theme/frio/templates/search_item.tpl index a5b6d52d6d..2cd231f8fb 100644 --- a/view/theme/frio/templates/search_item.tpl +++ b/view/theme/frio/templates/search_item.tpl @@ -1,7 +1,7 @@ @@ -56,7 +56,7 @@ {{/if}} {{if $item.lock}} - +   {{/if}} diff --git a/view/theme/frio/templates/wall_thread.tpl b/view/theme/frio/templates/wall_thread.tpl index c15b110ec9..5e7f49bf48 100644 --- a/view/theme/frio/templates/wall_thread.tpl +++ b/view/theme/frio/templates/wall_thread.tpl @@ -63,7 +63,7 @@ as the value of $top_child_total (this is done at the end of this file) {{if $item.star}} {{$item.star.starred}} {{/if}} - {{if $item.lock}}{{/if}} + {{if $item.lock}}{{/if}} {{* /TODO => Unknown block *}} @@ -138,7 +138,7 @@ as the value of $top_child_total (this is done at the end of this file) {{/if}} {{if $item.lock}} - +   {{/if}} diff --git a/view/theme/quattro/templates/photo_view.tpl b/view/theme/quattro/templates/photo_view.tpl index 1ce336b0a6..11947643c6 100644 --- a/view/theme/quattro/templates/photo_view.tpl +++ b/view/theme/quattro/templates/photo_view.tpl @@ -16,7 +16,7 @@ | {{$tools.profile.1}} {{/if}} {{if $tools.lock}} - | {{$tools.lock}} + | {{$tools.lock}} {{/if}} {{/if}} diff --git a/view/theme/quattro/templates/search_item.tpl b/view/theme/quattro/templates/search_item.tpl index 0e4aaaf8f7..cb400ac4f5 100644 --- a/view/theme/quattro/templates/search_item.tpl +++ b/view/theme/quattro/templates/search_item.tpl @@ -1,6 +1,6 @@
{{if $item.star}}{{$item.star.starred}}{{/if}} - {{if $item.lock}}{{$item.lock}}{{/if}} + {{if $item.lock}}{{$item.lock}}{{/if}}
diff --git a/view/theme/quattro/templates/wall_thread.tpl b/view/theme/quattro/templates/wall_thread.tpl index e6d8b97547..b6907219ff 100644 --- a/view/theme/quattro/templates/wall_thread.tpl +++ b/view/theme/quattro/templates/wall_thread.tpl @@ -24,7 +24,7 @@
{{if $item.star}}{{$item.star.starred}}{{/if}} - {{if $item.lock}}{{$item.lock}}{{/if}} + {{if $item.lock}}{{$item.lock}}{{/if}}
diff --git a/view/theme/smoothly/templates/search_item.tpl b/view/theme/smoothly/templates/search_item.tpl index 23af1b794b..b3ae01eb4e 100644 --- a/view/theme/smoothly/templates/search_item.tpl +++ b/view/theme/smoothly/templates/search_item.tpl @@ -18,7 +18,7 @@
{{if $item.location}}{{$item.location nofilter}} {{/if}}
- {{if $item.lock}}
{{$item.lock}}
+ {{if $item.lock}}
{{$item.lock}}
{{else}}
{{/if}}
diff --git a/view/theme/smoothly/templates/wall_thread.tpl b/view/theme/smoothly/templates/wall_thread.tpl index 85d480c31f..4ff34aed11 100644 --- a/view/theme/smoothly/templates/wall_thread.tpl +++ b/view/theme/smoothly/templates/wall_thread.tpl @@ -42,7 +42,7 @@
{{if $item.lock}}
- {{$item.lock}} + {{$item.lock}}
{{else}}
diff --git a/view/theme/vier/templates/photo_item.tpl b/view/theme/vier/templates/photo_item.tpl index f0b7a60890..94e9232af5 100644 --- a/view/theme/vier/templates/photo_item.tpl +++ b/view/theme/vier/templates/photo_item.tpl @@ -11,7 +11,7 @@ {{$name}} {{if $plink}}{{$ago}}{{else}} {{$ago}} {{/if}} - {{if $lock}}{{$lock}} {{/if}} + {{if $lock}}{{$lock}} {{/if}}
diff --git a/view/theme/vier/templates/photo_view.tpl b/view/theme/vier/templates/photo_view.tpl index f70ec5b561..87501c031a 100644 --- a/view/theme/vier/templates/photo_view.tpl +++ b/view/theme/vier/templates/photo_view.tpl @@ -17,7 +17,7 @@ | {{$tools.profile.1}} {{/if}} {{if $tools.lock}} - | {{$tools.lock}} + | {{$tools.lock}} {{/if}} {{/if}}
diff --git a/view/theme/vier/templates/search_item.tpl b/view/theme/vier/templates/search_item.tpl index 1813dd49f6..1da18b0867 100644 --- a/view/theme/vier/templates/search_item.tpl +++ b/view/theme/vier/templates/search_item.tpl @@ -2,7 +2,7 @@
{{if $item.star}}{{$item.star.starred}}{{/if}} - {{if $item.lock}}{{$item.lock}}{{/if}} + {{if $item.lock}}{{$item.lock}}{{/if}}
@@ -25,7 +25,7 @@ {{$item.name}} {{if $item.plink}}{{$item.ago}}{{else}} {{$item.ago}} {{/if}} - {{if $item.lock}}{{$item.lock}} {{/if}} + {{if $item.lock}}{{$item.lock}} {{/if}}
diff --git a/view/theme/vier/templates/wall_thread.tpl b/view/theme/vier/templates/wall_thread.tpl index 04ea7b424d..430a6943e3 100644 --- a/view/theme/vier/templates/wall_thread.tpl +++ b/view/theme/vier/templates/wall_thread.tpl @@ -65,7 +65,7 @@ {{/if}} {{$item.pinned}} - {{if $item.lock}}{{$item.lock}}{{/if}} + {{if $item.lock}}{{$item.lock}}{{/if}} {{$item.network_name}}