Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

install managers group by default #960

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ CHANGELOG

- Move from travis to github actions [lferran]

- Install managers group by default [lferran]

6.0.0b3 (2020-04-24)
--------------------
Expand Down
16 changes: 11 additions & 5 deletions guillotina/auth/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,24 @@
import typing


MANAGER_ROLES = [
"guillotina.ContainerAdmin",
"guillotina.ContainerDeleter",
"guillotina.Owner",
"guillotina.Member",
"guillotina.Manager",
]


class GuillotinaGroup(GuillotinaUser):
def __init__(self, ident):
super(GuillotinaGroup, self).__init__(ident)
self.id = ident

if ident == "Managers":
# Special Case its a Root Manager user
self._roles["guillotina.ContainerAdmin"] = 1
self._roles["guillotina.ContainerDeleter"] = 1
self._roles["guillotina.Owner"] = 1
self._roles["guillotina.Member"] = 1
self._roles["guillotina.Manager"] = 1
for role in MANAGER_ROLES:
self._roles[role] = 1


@configure.utility(provides=IGroups)
Expand Down
14 changes: 13 additions & 1 deletion guillotina/contrib/dbusers/install.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from guillotina import configure
from guillotina.addons import Addon
from guillotina.auth.groups import MANAGER_ROLES
from guillotina.content import create_content_in_container
from guillotina.interfaces import ILayers
from guillotina.utils import get_authenticated_user_id
Expand All @@ -19,9 +20,20 @@ async def install(self, site, request):
await create_content_in_container(
site, "UserManager", "users", creators=(user,), title="Users", check_constraints=False
)
await create_content_in_container(
groups = await create_content_in_container(
site, "GroupManager", "groups", creators=(user,), title="Groups", check_constraints=False
)
users = {"root", user}
await create_content_in_container(
groups,
"Group",
"Managers",
creators=(user,),
title="Managers",
description="Container managers",
user_roles=MANAGER_ROLES,
users=list(users),
)

@classmethod
async def uninstall(self, site, request):
Expand Down
6 changes: 6 additions & 0 deletions guillotina/tests/dbusers/test_setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from . import settings
from guillotina.auth.groups import MANAGER_ROLES
from guillotina.tests.utils import get_container

import pytest
Expand All @@ -15,3 +16,8 @@ async def test_users_and_groups_folders_are_created_on_install(dbusers_requester
assert users.type_name == "UserManager"
groups = await container.async_get("groups")
assert groups.type_name == "GroupManager"
managers = await groups.async_get("Managers")
assert managers.type_name == "Group"
assert managers.title == "Managers"
assert managers.users == ["root"]
assert set(managers.user_roles) == set(MANAGER_ROLES)