def __init__(self, label, config): """Make several values related to this label available as attrs. Args: label: artifact label string. E.g., 'Priority-High' or 'Frontend'. config: PB with a well_known_labels list, or None. """ self.name = label self.is_restrict = ezt.boolean(permissions.IsRestrictLabel(label)) self.docstring = '' if config: for wkl in config.well_known_labels: if label.lower() == wkl.label.lower(): self.docstring = wkl.label_docstring if '-' in label: self.prefix, self.value = label.split('-', 1) else: self.prefix, self.value = '', label
def __init__(self, issue): # List of restrictions that don't map to a known action kind. self.other = [] restrictions_by_action = collections.defaultdict(list) # We can't use GetRestrictions here, as we prefer to preserve # the case of the label when showing restrictions in the UI. for label in tracker_bizobj.GetLabels(issue): if permissions.IsRestrictLabel(label): _kw, action_kind, needed_perm = label.split('-', 2) action_kind = action_kind.lower() if action_kind in self._KNOWN_ACTION_KINDS: restrictions_by_action[action_kind].append(needed_perm) else: self.other.append(label) self.view = ' and '.join(restrictions_by_action[self._VIEW]) self.add_comment = ' and '.join(restrictions_by_action[self._ADD_COMMENT]) self.edit = ' and '.join(restrictions_by_action[self._EDIT]) self.has_restrictions = ezt.boolean( self.view or self.add_comment or self.edit or self.other)