From 6ba80af00968db4614f153b99ce9e1ce3ace7505 Mon Sep 17 00:00:00 2001 From: bach Date: Tue, 31 Aug 2021 23:17:43 +0200 Subject: [PATCH] patched flag_list https://www.drupal.org/project/flag_lists/issues/3230729, forgot the patche --- patches/hook_flag_access_id_on_null.patch | 93 +++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 patches/hook_flag_access_id_on_null.patch diff --git a/patches/hook_flag_access_id_on_null.patch b/patches/hook_flag_access_id_on_null.patch new file mode 100644 index 0000000..2fe21af --- /dev/null +++ b/patches/hook_flag_access_id_on_null.patch @@ -0,0 +1,93 @@ +diff --git a/flag_lists.module b/flag_lists.module +index cd81104..3decec0 100644 +--- a/flag_lists.module ++++ b/flag_lists.module +@@ -237,47 +237,49 @@ function flag_lists_flag_action_access($action, FlagInterface $flag, AccountInte + // Allow both users flag and the corresponding template. + // Currently only the users flag lists are accepted. + // This needs to corrected to allow also global lists. +- $flagListsService = Drupal::service('flaglists'); +- $flagLists = $flagListsService->getAllFlaggingCollections(); +- foreach ($flagLists as $flagList) { +- if ($flag->id() == $flagList->getRelatedFlag()->id()) { +- if ($flagList->getBaseFlag()->isGlobal()) { +- // The flag list is global. +- return AccessResult::allowedIfHasPermission($account, +- 'access global flag lists'); +- } +- elseif ($flagList->getOwnerId() == $account->id()) { +- // The flag list is owned by current user. +- return AccessResult::allowedIfHasPermission($account, +- 'view own flag lists'); +- } +- else { +- // The user is allowed to see all flag lists. +- return AccessResult::allowedIfHasPermission($account, +- 'view flag lists'); ++ if ($flag){ ++ $flagListsService = Drupal::service('flaglists'); ++ $flagLists = $flagListsService->getAllFlaggingCollections(); ++ foreach ($flagLists as $flagList) { ++ if ($flag->id() == $flagList->getRelatedFlag()->id()) { ++ if ($flagList->getBaseFlag()->isGlobal()) { ++ // The flag list is global. ++ return AccessResult::allowedIfHasPermission($account, ++ 'access global flag lists'); ++ } ++ elseif ($flagList->getOwnerId() == $account->id()) { ++ // The flag list is owned by current user. ++ return AccessResult::allowedIfHasPermission($account, ++ 'view own flag lists'); ++ } ++ else { ++ // The user is allowed to see all flag lists. ++ return AccessResult::allowedIfHasPermission($account, ++ 'view flag lists'); ++ } + } + } +- } +- +- // Check for access for the used template as well. +- $flagTemplates = $flagListsService->getAllFlagForList(); +- foreach ($flagTemplates as $flagTemplate) { +- if ($flag->id() == $flagTemplate->id()) { +- // This is one of the template flags. +- // But is it global? +- $baseFlag = Drupal::service('flag')->getFlagById($flagTemplate->getBaseFlag()); +- if ($baseFlag->isGlobal()) { +- return AccessResult::allowedIfHasPermission($account, +- 'access global flag lists'); +- } +- else { +- return AccessResult::allowedIfHasPermissions($account, [ +- 'administer flag lists', +- 'view own flag lists', +- 'view flag lists', +- ], +- 'OR' +- ); ++ ++ // Check for access for the used template as well. ++ $flagTemplates = $flagListsService->getAllFlagForList(); ++ foreach ($flagTemplates as $flagTemplate) { ++ if ($flag->id() == $flagTemplate->id()) { ++ // This is one of the template flags. ++ // But is it global? ++ $baseFlag = Drupal::service('flag')->getFlagById($flagTemplate->getBaseFlag()); ++ if ($baseFlag->isGlobal()) { ++ return AccessResult::allowedIfHasPermission($account, ++ 'access global flag lists'); ++ } ++ else { ++ return AccessResult::allowedIfHasPermissions($account, [ ++ 'administer flag lists', ++ 'view own flag lists', ++ 'view flag lists', ++ ], ++ 'OR' ++ ); ++ } + } + } + }