Пример #1
0
def get_state_names(states):
    """Get a string of labels for states.

    :param states: The states to get labels for.

    :returns: A string of state names join with 'or'
    """
    states = listify(states)
    state_names = [s.name for s in states]

    return " or ".join(state_names)
Пример #2
0
def get_state_names(states):
    """Get a string of labels for states.

    :param states: The states to get labels for.

    :returns: A string of state names join with 'or'
    """
    states = listify(states)
    state_names = [s.name for s in states]

    return " or ".join(state_names)
Пример #3
0
    def check_membership(self, allowed_groups):
        """Check required group(s).

        Verify that the user is in a permitted group, always returns True if
        the user is a Super Administrator.

        :param allowed_groups: The groups permitted.

        :returns: True if user is in an allowed group, otherwise False.
        """
        # super admin skips group check
        user_groups = groups.user_groups(self.request.user)

        if len(listify(allowed_groups)) == 1 and \
                groups.TALLY_MANAGER in listify(allowed_groups):
            return groups.TALLY_MANAGER in user_groups;

        else:
            return groups.TALLY_MANAGER in user_groups or\
                    groups.SUPER_ADMINISTRATOR in user_groups or\
                    set(listify(allowed_groups)) & set(user_groups)
Пример #4
0
    def check_membership(self, allowed_groups):
        """Check required group(s).

        Verify that the user is in a permitted group, always returns True if
        the user is a Super Administrator.

        :param allowed_groups: The groups permitted.

        :returns: True if user is in an allowed group, otherwise False.
        """
        # super admin skips group check
        user_groups = groups.user_groups(self.request.user)

        if len(listify(allowed_groups)) == 1 and \
                groups.TALLY_MANAGER in listify(allowed_groups):
            return groups.TALLY_MANAGER in user_groups

        else:
            return groups.TALLY_MANAGER in user_groups or\
                    groups.SUPER_ADMINISTRATOR in user_groups or\
                    set(listify(allowed_groups)) & set(user_groups)
Пример #5
0
def check_membership(allowed_groups, user):
    """Check required group(s).

    Verify that the user is in a permitted group, always returns True if
    the user is a Super Administrator.

    :param allowed_groups: The groups permitted.

    :returns: True if user is in an allowed group, otherwise False.
    """
    user_groups = set(groups.user_groups(user))

    # super admin skips group check
    return admin_groups & user_groups or\
        set(listify(allowed_groups)) & user_groups
Пример #6
0
def form_in_state(result_form, states):
    """Raise a SuspiciousOperation if result form is not in an allowable state.

    :param result_form: The result form to check the state of.
    :param states: The allowable states.

    :raises: `SuspiciousOperation` if form not in one of states.
    :returns: True if form is in an allowable state.
    """
    states = listify(states)

    if result_form.form_state not in states:
        state_names = get_state_names(states)

        raise SuspiciousOperation(
            _(u"Form not in %(state_name)s.  Return form to %(state)s"
              % {'state_name': state_names,
                 'state': result_form.form_state_name}))

    return True
Пример #7
0
def form_in_state(result_form, states):
    """Raise a SuspiciousOperation if result form is not in an allowable state.

    :param result_form: The result form to check the state of.
    :param states: The allowable states.

    :raises: `SuspiciousOperation` if form not in one of states.
    :returns: True if form is in an allowable state.
    """
    states = listify(states)

    if result_form.form_state not in states:
        state_names = get_state_names(states)

        raise SuspiciousOperation(
            _(u"Form not in %(state_name)s.  Return form to %(state)s"
              % {'state_name': state_names,
                 'state': result_form.form_state_name}))

    return True