def is_alias_used(my_what: Union[GroupType, Literal["roles", "timeperiods"]], my_name: GroupName, my_alias: str) -> Tuple[bool, Optional[str]]: # Host / Service / Contact groups all_groups = load_group_information() for what, groups in all_groups.items(): for gid, group in groups.items(): if group["alias"] == my_alias and (my_what != what or my_name != gid): return False, _( "This alias is already used in the %s group %s.") % (what, gid) # Timeperiods timeperiods = cmk.gui.watolib.timeperiods.load_timeperiods() for key, value in timeperiods.items(): if timeperiod_spec_alias(value) == my_alias and ( my_what != "timeperiods" or my_name != key): return False, _( "This alias is already used in timeperiod %s.") % key # Roles roles = userdb_utils.load_roles() for key, value in roles.items(): if value.get("alias") == my_alias and (my_what != "roles" or my_name != key): return False, _("This alias is already used in the role %s.") % key return True, None
def page(self): role_list = sorted(userdb_utils.load_roles().items(), key=lambda a: (a[1]["alias"], a[0])) for section in permission_section_registry.get_sorted_sections(): html.begin_foldable_container("perm_matrix", section.name, section.name == "general", section.title, indent=True) with table_element(section.name) as table: for perm in permission_registry.get_sorted_permissions(section): table.row() table.cell(_("Permission"), perm.title, css="wide") html.help(perm.description) for role_id, role in role_list: base_on_id = role.get('basedon', role_id) pvalue = role["permissions"].get(perm.name) if pvalue is None: if base_on_id in perm.defaults: icon_name: Optional[str] = "perm_yes_default" else: icon_name = None else: icon_name = "perm_%s" % (pvalue and "yes" or "no") table.cell(role_id, css="center") if icon_name: html.icon(icon_name) html.end_foldable_container() html.close_table()
def __init__(self): super(ModeEditUser, self).__init__() # Load data that is referenced - in order to display dropdown # boxes and to check for validity. self._contact_groups = load_contact_group_information() self._timeperiods = watolib.timeperiods.load_timeperiods() self._roles = userdb_utils.load_roles() if cmk_version.is_managed_edition(): self._vs_customer = managed.vs_customer()
def page(self): role_list = sorted(userdb_utils.load_roles().items(), key=lambda a: (a[1]["alias"], a[0])) for section in permission_section_registry.get_sorted_sections(): with table_element( section.name, section.title, foldable=True, ) as table: permission_list = permission_registry.get_sorted_permissions( section) if not permission_list: table.row() table.cell(_("Permission"), _("No entries"), css="wide") continue for perm in permission_list: table.row() table.cell(_("Permission"), perm.title, css="wide") html.help(perm.description) for role_id, role in role_list: base_on_id = role.get("basedon", role_id) pvalue = role["permissions"].get(perm.name) if pvalue is None: if base_on_id in perm.defaults: icon_name: Optional[str] = "perm_yes_default" else: icon_name = None else: icon_name = "perm_%s" % (pvalue and "yes" or "no") table.cell(role_id, css="center") if icon_name: html.icon(icon_name) html.close_table()
def __init__(self): self._roles = userdb_utils.load_roles() super(RoleManagement, self).__init__()
def __init__(self): self._roles = userdb_utils.load_roles() super().__init__()
def _show_user_list(self): visible_custom_attrs = [(name, attr) for name, attr in userdb.get_user_attributes() if attr.show_in_table()] users = userdb.load_users() entries = list(users.items()) html.begin_form("bulk_delete_form", method="POST") roles = userdb_utils.load_roles() timeperiods = watolib.timeperiods.load_timeperiods() contact_groups = load_contact_group_information() with table_element("users", None, empty_text=_("No users are defined yet.")) as table: online_threshold = time.time() - config.user_online_maxage for uid, user in sorted( entries, key=lambda x: x[1].get("alias", x[0]).lower()): table.row() # Checkboxes table.cell(html.render_input( "_toggle_group", type_="button", class_="checkgroup", onclick="cmk.selection.toggle_all_rows();", value='X'), sortable=False, css="checkbox") if uid != config.user.id: html.checkbox( "_c_user_%s" % ensure_str(base64.b64encode(uid.encode("utf-8")))) user_connection_id = cleanup_connection_id( user.get('connector')) connection = get_connection(user_connection_id) # Buttons table.cell(_("Actions"), css="buttons") if connection: # only show edit buttons when the connector is available and enabled edit_url = watolib.folder_preserving_link([("mode", "edit_user"), ("edit", uid)]) html.icon_button(edit_url, _("Properties"), "edit") clone_url = watolib.folder_preserving_link([ ("mode", "edit_user"), ("clone", uid) ]) html.icon_button(clone_url, _("Create a copy of this user"), "clone") delete_url = make_action_link([("mode", "users"), ("_delete", uid)]) html.icon_button(delete_url, _("Delete"), "delete") notifications_url = watolib.folder_preserving_link([ ("mode", "user_notifications"), ("user", uid) ]) if rulebased_notifications_enabled(): html.icon_button( notifications_url, _("Custom notification table of this user"), "notifications") # ID table.cell(_("ID"), uid) # Online/Offline if config.save_user_access_times: last_seen = user.get('last_seen', 0) if last_seen >= online_threshold: title = _('Online') img_txt = 'online' elif last_seen != 0: title = _('Offline') img_txt = 'offline' elif last_seen == 0: title = _('Never logged in') img_txt = 'inactive' title += ' (%s %s)' % (render.date(last_seen), render.time_of_day(last_seen)) table.cell(_("Act.")) html.icon(title, img_txt) table.cell(_("Last seen")) if last_seen != 0: html.write_text("%s %s" % (render.date(last_seen), render.time_of_day(last_seen))) else: html.write_text(_("Never logged in")) if cmk_version.is_managed_edition(): table.cell(_("Customer"), managed.get_customer_name(user)) # Connection if connection: table.cell( _("Connection"), '%s (%s)' % (connection.short_title(), user_connection_id)) locked_attributes = userdb.locked_attributes( user_connection_id) else: table.cell( _("Connection"), "%s (%s) (%s)" % (_("UNKNOWN"), user_connection_id, _("disabled")), css="error") locked_attributes = [] # Authentication if "automation_secret" in user: auth_method = _("Automation") elif user.get("password") or 'password' in locked_attributes: auth_method = _("Password") else: auth_method = "<i>%s</i>" % _("none") table.cell(_("Authentication"), auth_method) table.cell(_("State")) if user.get("locked", False): html.icon(_('The login is currently locked'), 'user_locked') if "disable_notifications" in user and isinstance( user["disable_notifications"], bool): disable_notifications_opts = { "disable": user["disable_notifications"] } else: disable_notifications_opts = user.get( "disable_notifications", {}) if disable_notifications_opts.get("disable", False): html.icon(_('Notifications are disabled'), 'notif_disabled') # Full name / Alias table.text_cell(_("Alias"), user.get("alias", "")) # Email table.text_cell(_("Email"), user.get("email", "")) # Roles table.cell(_("Roles")) if user.get("roles", []): role_links = [(watolib.folder_preserving_link([ ("mode", "edit_role"), ("edit", role) ]), roles[role].get("alias")) for role in user["roles"]] html.write_html( HTML(", ").join( html.render_a(alias, href=link) for (link, alias) in role_links)) # contact groups table.cell(_("Contact groups")) cgs = user.get("contactgroups", []) if cgs: cg_aliases = [ contact_groups[c]['alias'] if c in contact_groups else c for c in cgs ] cg_urls = [ watolib.folder_preserving_link([("mode", "edit_contact_group"), ("edit", c)]) for c in cgs ] html.write_html( HTML(", ").join( html.render_a(content, href=url) for (content, url) in zip(cg_aliases, cg_urls))) else: html.i(_("none")) #table.cell(_("Sites")) #html.write(vs_authorized_sites().value_to_text(user.get("authorized_sites", # vs_authorized_sites().default_value()))) # notifications if not rulebased_notifications_enabled(): table.cell(_("Notifications")) if not cgs: html.i(_("not a contact")) elif not user.get("notifications_enabled", True): html.write_text(_("disabled")) elif user.get("host_notification_options", "") == "" and \ user.get("service_notification_options", "") == "": html.write_text(_("all events disabled")) else: tp = user.get("notification_period", "24X7") if tp not in timeperiods: tp = tp + _(" (invalid)") elif tp not in watolib.timeperiods.builtin_timeperiods( ): url = watolib.folder_preserving_link([ ("mode", "edit_timeperiod"), ("edit", tp) ]) tp = html.render_a(timeperiod_spec_alias( timeperiods[tp], tp), href=url) else: tp = timeperiod_spec_alias(timeperiods[tp], tp) html.write(tp) # the visible custom attributes for name, attr in visible_custom_attrs: vs = attr.valuespec() table.cell(escaping.escape_attribute(_u(vs.title()))) html.write( vs.value_to_text(user.get(name, vs.default_value()))) html.button("_bulk_delete_users", _("Bulk Delete"), "submit", style="margin-top:10px") html.hidden_fields() html.end_form() if not load_contact_group_information(): url = "wato.py?mode=contact_groups" html.open_div(class_="info") html.write( _("Note: you haven't defined any contact groups yet. If you <a href='%s'>" "create some contact groups</a> you can assign users to them und thus " "make them monitoring contacts. Only monitoring contacts can receive " "notifications.") % url) html.write( " you can assign users to them und thus " "make them monitoring contacts. Only monitoring contacts can receive " "notifications.") html.close_div()