Example #1
0
    def declare_overriding_permissions(cls):
        declare_permission_section(cls.type_name(), cls.phrase("title_plural"), do_sort=True)

        declare_permission(
            "general.edit_" + cls.type_name(),
            _("Customize %s and use them") % cls.phrase("title_plural"),
            _("Allows to create own %s, customize builtin %s and use them.") %
            (cls.phrase("title_plural"), cls.phrase("title_plural")),
            ["admin", "user"],
        )

        declare_permission(
            "general.publish_" + cls.type_name(),
            _("Publish %s") % cls.phrase("title_plural"),
            _("Make %s visible and usable for other users.") % cls.phrase("title_plural"),
            ["admin", "user"],
        )

        config.declare_permission(
            "general.publish_to_foreign_groups_" + cls.type_name(),
            _("Publish %s to foreign contact groups") % cls.phrase("title_plural"),
            _("Make %s visible and usable for users of contact groups the publishing user is not a member of."
             ) % cls.phrase("title_plural"),
            ["admin"],
        )

        # TODO: Bug: This permission does not seem to be used
        declare_permission(
            "general.see_user_" + cls.type_name(),
            _("See user %s") % cls.phrase("title_plural"),
            _("Is needed for seeing %s that other users have created.") %
            cls.phrase("title_plural"),
            ["admin", "user", "guest"],
        )

        declare_permission(
            "general.force_" + cls.type_name(),
            _("Modify builtin %s") % cls.phrase("title_plural"),
            _("Make own published %s override builtin %s for all users.") %
            (cls.phrase("title_plural"), cls.phrase("title_plural")),
            ["admin"],
        )

        declare_permission(
            "general.edit_foreign_" + cls.type_name(),
            _("Edit foreign %s") % cls.phrase("title_plural"),
            _("Allows to edit %s created by other users.") % cls.phrase("title_plural"),
            ["admin"],
        )

        declare_permission(
            "general.delete_foreign_" + cls.type_name(),
            _("Delete foreign %s") % cls.phrase("title_plural"),
            _("Allows to delete %s created by other users.") % cls.phrase("title_plural"),
            ["admin"],
        )
Example #2
0
def test_declare_permission(monkeypatch):
    monkeypatch.setattr(permissions, "permission_section_registry",
                        permissions.PermissionSectionRegistry())
    assert "bla" not in permissions.permission_section_registry
    config.declare_permission_section("bla", u"bla perm", do_sort=False)
    assert "bla" in permissions.permission_section_registry

    monkeypatch.setattr(permissions, "permission_registry", permissions.PermissionRegistry())
    assert "bla.blub" not in permissions.permission_registry
    config.declare_permission("bla.blub", u"bla perm", u"descrrrrr", ["admin"])
    assert "bla.blub" in permissions.permission_registry

    permission = permissions.permission_registry["bla.blub"]()
    assert permission.section == permissions.permission_section_registry["bla"]
    assert permission.name == "bla.blub"
    assert permission.title == u"bla perm"
    assert permission.description == "descrrrrr"
    assert permission.defaults == ["admin"]