diff --git a/og.api.php b/og.api.php index 1265d294e..667871bb8 100644 --- a/og.api.php +++ b/og.api.php @@ -11,24 +11,6 @@ * @{ */ -/** - * Add group permissions. - */ -function hook_og_permission() { - return array( - 'subscribe' => array( - 'title' => t('Subscribe user to group'), - 'description' => t("Allow user to be a member of a group (approval required)."), - // Determine to which role to limit the permission. For example the - // "subscribe" can't be assigned only to a non-member, as a member doesn't - // need it. - 'roles' => array(Og::ANONYMOUS_ROLE), - // Determine to which roles the permissions will be enabled by default. - 'default roles' => array(Og::ANONYMOUS_ROLE), - ), - ); -} - /** * Alter the organic groups permissions. * diff --git a/og.og_permissions.yml b/og.og_permissions.yml index 89c3b9dee..92b68b8fe 100644 --- a/og.og_permissions.yml +++ b/og.og_permissions.yml @@ -9,3 +9,6 @@ administer group: 'restrict access': TRUE 'default roles': - ADMINISTRATOR_ROLE + +permission_callbacks: + - \Drupal\og\OgNodePermissions::nodeTypePermissions diff --git a/src/OgNodePermissions.php b/src/OgNodePermissions.php new file mode 100644 index 000000000..684e919d0 --- /dev/null +++ b/src/OgNodePermissions.php @@ -0,0 +1,42 @@ +id())) { + continue; + } + + $perms += $this->buildPermissions($bundle); + } + + return $perms; + } + +} diff --git a/src/OgPermissionHandler.php b/src/OgPermissionHandler.php index fb521f4b0..21d6e43a7 100644 --- a/src/OgPermissionHandler.php +++ b/src/OgPermissionHandler.php @@ -12,7 +12,7 @@ use Drupal\user\PermissionHandlerInterface; /** - * Provides permissions for groups based on YNL files. + * Provides permissions for groups based on YAML files. * * The permissions file should be constructed by the next format(with comments): * @code diff --git a/tests/src/Kernel/Entity/OgNodePermissionsTest.php b/tests/src/Kernel/Entity/OgNodePermissionsTest.php new file mode 100644 index 000000000..eca9151ad --- /dev/null +++ b/tests/src/Kernel/Entity/OgNodePermissionsTest.php @@ -0,0 +1,58 @@ + Unicode::strtolower($this->randomMachineName()), + 'name' => $this->randomString(), + ]); + + $bundle->save(); + Og::CreateField(OgGroupAudienceHelper::DEFAULT_FIELD, 'node', $bundle->id()); + + $name = $bundle->id(); + $expected = [ + 'administer group', + 'update group', + "create $name content", + "delete any $name content", + "delete own $name content", + "delete $name revisions", + "edit any $name content", + "edit own $name content", + "revert $name revisions", + "view $name revisions", + ]; + + $permissions = Og::permissionHandler()->getPermissions(); + + $this->assertEquals($expected, array_keys($permissions)); + } + +}