Exemplo n.º 1
0
    async def get_action_details(action: str):
        action = await Actions.get(action=action)

        if not action:
            raise HTTPException(
                status_code=404, detail=f"No permission with name {action} exists"
            )

        all_roles = await Roles.all()

        roles = []
        for role in all_roles:
            role_actions = {a.action for a in role.actions}
            if action.action in role_actions:
                roles.append(role.role)
        roles = list(set(roles))

        all_groups = await Groups.all()

        groups = []
        for group in all_groups:
            for role in group.roles:
                if role.role in roles:
                    groups.append(group.group_name)
                    break

        all_users = await Users.all()

        users = []

        for user in all_users:
            for group in user.groups:
                if group.group_name in groups:
                    users.append(user.username)
                    break

        update_form = forms.get_form(
            f"Update {action.action}",
            [
                html_input.get_text_input("action", value=action.action),
                html_input.get_text_input("details", value=action.details),
            ],
            submit_name="update permission",
            method="post",
            action="/auth/actions",
            transform_id=f"Update{action.action}",
        )

        modal_row = row.get_row(
            card.get_card(f"{action.action}", update_form, size=12)
            + card.get_card(
                f"Users",
                "".join(
                    [
                        buttons.get_button(
                            user,
                            color="success",
                            href=f"#{user}",
                            onclick=f"OnClickUpdate('{admin_prefix}/user/{user}', 'page-top')",
                        )
                        for user in users
                    ]
                ),
                size=4,
            )
            + card.get_card(
                f"Groups",
                "".join(
                    [
                        buttons.get_button(
                            group,
                            color="success",
                            href=f"#{group}",
                            onclick=f"OnClickUpdate('{admin_prefix}/group/{group}', 'page-top')",
                        )
                        for group in groups
                    ]
                ),
                size=4,
            )
            + card.get_card(
                f"Roles",
                "".join(
                    [
                        buttons.get_button(
                            role,
                            color="success",
                            href=f"#{role}",
                            onclick=f"OnClickUpdate('{admin_prefix}/role/{role}', 'page-top')",
                        )
                        for role in roles
                    ]
                ),
                size=4,
            )
        )
        return modal_row
Exemplo n.º 2
0
    async def get_role_details(role_name: str):
        role = await Roles.get(role=role_name)
        if not role:
            raise HTTPException(
                status_code=404, detail=f"No Role with name {role_name} exists"
            )
        role_actions = role.actions
        all_actions = await Actions.all()
        all_actions = [action.action for action in all_actions]

        permissions = [
            action.action for action in role_actions if action.action in all_actions
        ]

        all_groups = await Groups.all()

        groups = [
            group.group_name
            for group in all_groups
            if role_name in [r.role for r in group.roles]
        ]

        all_users = await Users.all()

        users = []

        for user in all_users:
            for group in user.groups:
                if group.group_name in groups:
                    users.append(user.username)
                    break
        actions_in_role = [(action, True) for action in permissions] + [
            (action, False) for action in all_actions if not action in permissions
        ]
        update_form = forms.get_form(
            f"Update {role_name}",
            [
                html_input.get_text_input("role", value=role_name),
                html_input.get_checkbox("actions", actions_in_role, size=12)
                if len(actions_in_role) > 0
                else "no actions",
            ],
            submit_name="update role",
            method="post",
            action=f"/auth/role/{role_name}",
            transform_id=f"Update{role_name}",
        )

        modal_row = row.get_row(
            card.get_card(f"{role_name}", update_form, size=12)
            + card.get_card(
                f"Users",
                "".join(
                    [
                        buttons.get_button(
                            user,
                            color="success",
                            href=f"#{user}",
                            onclick=f"OnClickUpdate('{admin_prefix}/user/{user}', 'page-top')",
                        )
                        for user in users
                    ]
                ),
                size=4,
            )
            + card.get_card(
                f"Groups",
                "".join(
                    [
                        buttons.get_button(
                            group,
                            color="success",
                            href=f"#{group}",
                            onclick=f"OnClickUpdate('{admin_prefix}/group/{group}', 'page-top')",
                        )
                        for group in groups
                    ]
                ),
                size=4,
            )
            + card.get_card(
                f"Actions",
                "".join(
                    [
                        buttons.get_button(
                            action,
                            color="success",
                            href=f"#{action}",
                            onclick=f"OnClickUpdate('{admin_prefix}/action/{action}', 'page-top')",
                        )
                        for action in permissions
                    ]
                ),
                size=4,
            )
        )
        return modal_row
Exemplo n.º 3
0
    async def get_user_details(user):

        all_groups = await Groups.all()

        username_normalized = sub("[@.]", "", user.username)
        update_form = forms.get_form(
            f"Update {username_normalized}",
            [
                html_input.get_text_input("username", value=user.username),
                html_input.get_text_input("password", input_type="password")
                if user.account_type == "user"
                else "",
                html_input.get_text_input("email", value=user.email)
                + html_input.get_text_input("full_name", value=user.full_name)
                if user.account_type == "user"
                else "",
                html_input.get_checkbox(
                    "groups",
                    [(group.group_name, True) for group in user.groups]
                    + [
                        (group.group_name, False)
                        for group in all_groups
                        if not group in user.groups
                    ],
                    size=12,
                    unique_id=user.username,
                ),
            ],
            submit_name="update user",
            method="post",
            action=f"/auth/user/{user.username}",
            transform_id=f"Update{username_normalized}",
        )

        groups, roles, actions = [], [], []
        for group in user.groups:
            for role in group.roles:
                if role.role in roles:
                    continue
                for action in role.actions:
                    if action.action in actions:
                        continue
                    actions.append(action.action)
                roles.append(role.role)
            groups.append(group.group_name)

        modal_row = row.get_row(
            card.get_card(f"{user.username}", update_form, size=12)
            + card.get_card(
                f"Groups",
                "".join(
                    [
                        buttons.get_button(
                            group,
                            color="success",
                            href=f"#{group}",
                            onclick=f"OnClickUpdate('{admin_prefix}/group/{group}', 'page-top')",
                        )
                        for group in groups
                    ]
                ),
                size=4,
            )
            + card.get_card(
                f"Roles",
                "".join(
                    [
                        buttons.get_button(
                            role,
                            color="success",
                            href=f"#{role}",
                            onclick=f"OnClickUpdate('{admin_prefix}/role/{role}', 'page-top')",
                        )
                        for role in roles
                    ]
                ),
                size=4,
            )
            + card.get_card(
                f"Actions",
                "".join(
                    [
                        buttons.get_button(
                            action,
                            color="success",
                            href=f"#{action}",
                            onclick=f"OnClickUpdate('{admin_prefix}/action/{action}', 'page-top')",
                        )
                        for action in actions
                    ]
                ),
                size=4,
            )
        )
        return modal_row
Exemplo n.º 4
0
    async def get_group_details(group_name: str):
        group = await Groups.get(group_name=group_name)

        if not group:
            raise HTTPException(
                status_code=404, detail=f"No Group with name {group_name} exists"
            )

        all_roles = [r.role for r in await Roles.all()]

        roles = [role.role for role in group.roles if role.role in all_roles]

        permissions = []
        all_actions = await Actions.all()
        all_actions = [action.action for action in all_actions]
        for role in group.roles:
            for action in role.actions:
                if not action.action in permissions:
                    permissions.append(action.action)

        users = await Users.all()
        users = [
            user.username
            for user in users
            if group_name in [g.group_name for g in user.groups]
        ]

        roles_in_group = [(role, True) for role in roles] + [
            (role, False) for role in all_roles if not role in roles
        ]
        update_form = forms.get_form(
            f"Update {group_name}",
            [
                html_input.get_text_input("group_name", value=group_name),
                html_input.get_checkbox("roles", roles_in_group, size=12)
                if len(roles_in_group) > 0
                else "No Roles",
            ],
            submit_name="update group",
            method="post",
            action=f"/auth/group/{group_name}",
            transform_id=f"Update{group_name}",
        )

        modal_row = row.get_row(
            card.get_card(f"{group_name}", update_form, size=12)
            + card.get_card(
                f"Users",
                "".join(
                    [
                        buttons.get_button(
                            user,
                            color="success",
                            href=f"#{user}",
                            onclick=f"OnClickUpdate('{admin_prefix}/user/{user}', 'page-top')",
                        )
                        for user in users
                    ]
                ),
                size=4,
            )
            + card.get_card(
                f"Roles",
                "".join(
                    [
                        buttons.get_button(
                            role,
                            color="success",
                            href=f"#{role}",
                            onclick=f"OnClickUpdate('{admin_prefix}/role/{role}', 'page-top')",
                        )
                        for role in roles
                    ]
                ),
                size=4,
            )
            + card.get_card(
                f"Actions",
                "".join(
                    [
                        buttons.get_button(
                            action,
                            color="success",
                            href=f"#{action}",
                            onclick=f"OnClickUpdate('{admin_prefix}/action/{action}', 'page-top')",
                        )
                        for action in permissions
                    ]
                ),
                size=4,
            )
        )
        return modal_row
Exemplo n.º 5
0
    def get_token_details(token: dict):

        users = token["users"] if "users" in token else []
        groups = token["groups"] if "groups" in token else []
        roles = token["roles"] if "roles" in token else []
        actions = token["actions"] if "actions" in token else []

        modal_row = card.get_card(
            f"{users[0]} Token Permissions",
            body=row.get_row(
                card.get_card(
                    f"Users",
                    "".join(
                        [
                            buttons.get_button(
                                user,
                                color="success",
                                href=f"#{user}",
                                onclick=f"OnClickUpdate('{admin_prefix}/user/{user}', 'page-top')",
                            )
                            for user in users
                        ]
                    ),
                    size=4,
                )
                + card.get_card(
                    f"Groups",
                    "".join(
                        [
                            buttons.get_button(
                                group,
                                color="success",
                                href=f"#{group}",
                                onclick=f"OnClickUpdate('{admin_prefix}/group/{group}', 'page-top')",
                            )
                            for group in groups
                        ]
                    ),
                    size=4,
                )
                + card.get_card(
                    f"Roles",
                    "".join(
                        [
                            buttons.get_button(
                                role,
                                color="success",
                                href=f"#{role}",
                                onclick=f"OnClickUpdate('{admin_prefix}/role/{role}', 'page-top')",
                            )
                            for role in roles
                        ]
                    ),
                    size=4,
                )
                + card.get_card(
                    f"Actions",
                    "".join(
                        [
                            buttons.get_button(
                                action,
                                color="success",
                                href=f"#{action}",
                                onclick=f"OnClickUpdate('{admin_prefix}/action/{action}', 'page-top')",
                            )
                            for action in actions
                        ]
                    ),
                    size=4,
                )
            ),
            size=12,
        )
        return modal_row