Example #1
0
def _get_default_org(user):
    """Gets the default org for a user and returns the id, name, and
    role_level. If no default organization is set for the user, the first
    organization the user has access to is set as default if it exists.

    :param user: the user to get the default org
    :returns: tuple (Organization id, Organization name, OrganizationUser role)
    """
    org = user.default_organization
    # check if user is still in the org, i.e. s/he wasn't removed from his/her
    # default org or did not have a set org and try to set the first one
    if not org or not user.orgs.exists():
        org = user.orgs.first()
        user.default_organization = org
        user.save()
    if org:
        org_id = org.pk
        org_name = org.name
        ou = user.organizationuser_set.filter(organization=org).first()
        # parent org owner has no role (None) yet has access to the sub-org
        org_user_role = _get_js_role(ou.role_level) if ou else ""
        return org_id, org_name, org_user_role
    else:
        return "", "", ""
Example #2
0
 def test__get_js_role(self):
     self.assertEquals(_get_js_role(ROLE_OWNER), 'owner')
     self.assertEquals(_get_js_role(ROLE_MEMBER), 'member')
     self.assertEquals(_get_js_role(ROLE_VIEWER), 'viewer')
Example #3
0
 def test__get_js_role(self):
     self.assertEquals(_get_js_role(ROLE_OWNER), 'owner')
     self.assertEquals(_get_js_role(ROLE_MEMBER), 'member')
     self.assertEquals(_get_js_role(ROLE_VIEWER), 'viewer')