示例#1
0
    def _from_vars(self):
        self._search = get_search_expression()
        self._topic = html.request.get_ascii_input("topic")
        if self._topic and not self._search:
            if not re.match("^[a-zA-Z0-9_./]+$", self._topic):
                raise MKUserError("topic", _("Invalid topic"))

            self._path = tuple(
                self._topic.split("/"))  # e.g. [ "hw", "network" ]
        else:
            self._path = tuple()

        for comp in self._path:
            ID().validate_value(comp, None)  # Beware against code injection!

        self._manpages = self._get_check_catalog()
        self._titles = man_pages.man_page_catalog_titles()

        self._has_second_level = None
        if self._topic and not self._search:
            for t, has_second_level, title, _helptext in self._man_page_catalog_topics(
            ):
                if t == self._path[0]:
                    self._has_second_level = has_second_level
                    self._topic_title = title
                    break

            if len(self._path) == 2:
                self._topic_title = self._titles.get(self._path[1],
                                                     self._path[1])
示例#2
0
 def _from_vars(self):
     self._search = get_search_expression()
     self._manpages = _get_check_catalog(only_path=())
     self._titles = man_pages.man_page_catalog_titles()
示例#3
0
    def page(self):
        search = get_search_expression()

        html.begin_form("role", method="POST")

        # ID
        forms.header(_("Basic properties"), css="wide")
        forms.section(_("Internal ID"),
                      simple="builtin" in self._role,
                      is_required=True)
        if self._role.get("builtin"):
            html.write_text("%s (%s)" % (self._role_id, _("builtin role")))
            html.hidden_field("id", self._role_id)
        else:
            html.text_input("id", self._role_id)
            html.set_focus("id")

        # Alias
        forms.section(_("Alias"))
        html.help(_("An alias or description of the role"))
        html.text_input("alias", self._role.get("alias", ""), size=50)

        # Based on
        if not self._role.get("builtin"):
            forms.section(_("Based on role"))
            html.help(
                _("Each user defined role is based on one of the builtin roles. "
                  "When created it will start with all permissions of that role. When due to a software "
                  "update or installation of an addons new permissions appear, the user role will get or "
                  "not get those new permissions based on the default settings of the builtin role it's "
                  "based on."))
            role_choices: Choices = [(i, r["alias"])
                                     for i, r in self._roles.items()
                                     if r.get("builtin")]
            html.dropdown("basedon",
                          role_choices,
                          deflt=self._role.get("basedon", "user"),
                          ordered=True)

        forms.end()

        html.h2(_("Permissions"))

        # Permissions
        base_role_id = self._role.get("basedon", self._role_id)

        html.help(
            _("When you leave the permissions at "default" then they get their "
              "settings from the factory defaults (for builtin roles) or from the "
              "factory default of their base role (for user define roles). Factory defaults "
              "may change due to software updates. When choosing another base role, all "
              "permissions that are on default will reflect the new base role."
              ))

        for section in permission_section_registry.get_sorted_sections():
            # Now filter by the optional search term
            filtered_perms = []
            for perm in permission_registry.get_sorted_permissions(section):
                if search and (search not in perm.title.lower()
                               and search not in perm.name.lower()):
                    continue

                filtered_perms.append(perm)

            if not filtered_perms:
                continue

            forms.header(section.title, isopen=search is not None, css="wide")
            for perm in filtered_perms:
                forms.section(perm.title)

                pvalue = self._role["permissions"].get(perm.name)
                def_value = base_role_id in perm.defaults

                choices: Choices = [
                    ("yes", _("yes")),
                    ("no", _("no")),
                    ("default",
                     _("default (%s)") % (def_value and _("yes") or _("no"))),
                ]
                deflt = {True: "yes", False: "no"}.get(pvalue, "default")

                html.dropdown("perm_" + perm.name,
                              choices,
                              deflt=deflt,
                              style="width: 130px;")
                html.help(perm.description)

        forms.end()
        html.hidden_fields()
        html.end_form()