def check_inherit_permission_from_project(xform_id, user): """ Checks if a user has the same project permissions for the given xform_id, if there is a difference applies the project permissions to the user for the given xform_id. """ if xform_id == 'public': return try: int(xform_id) except ValueError: return # get the project_xform xform = XForm.objects.filter(pk=xform_id).select_related('project').only( 'project_id', 'id').first() if not xform: return # ignore if forms has meta perms set if xform.metadata_set.filter(data_type=XFORM_META_PERMS): return # get and compare the project role to the xform role project_role = get_role_in_org(user, xform.project) xform_role = get_role_in_org(user, xform) # if diff set the project role to the xform if xform_role != project_role: _set_xform_permission(project_role, user, xform)
def check_inherit_permission_from_project(xform_id, user): if xform_id == 'public': return try: int(xform_id) except ValueError: return # get the project_xform xforms = XForm.objects.filter(pk=xform_id).select_related('project') if not xforms: return # ignore if forms has meta perms set if xforms[0].metadata_set.filter(data_type='xform_meta_perms'): return # get and compare the project role to the xform role project_role = get_role_in_org(user, xforms[0].project) xform_role = get_role_in_org(user, xforms[0]) # if diff set the project role to the xform if xform_role != project_role: _set_xform_permission(project_role, user, xforms[0])
def get_org_permissions(self, obj): members = get_organization_members(obj) if obj else [] return [{ 'user': u.username, 'role': get_role_in_org(u, obj) } for u in members]
def _get_owners(organization): # Get users with owners perms and not the org itself return [user for user in get_organization_owners_team( organization).user_set.all() if get_role_in_org(user, organization) == 'owner' and organization.user != user]
def create_user_list(user_list): return [{ 'user': u.username, 'role': get_role_in_org(u, obj), 'first_name': u.first_name, 'last_name': u.last_name, 'gravatar': u.profile.gravatar } for u in user_list]
def _get_owners(organization): # Get users with owners perms and not the org itself return [ user for user in get_organization_owners_team(organization).user_set.all() if get_role_in_org(user, organization) == 'owner' and organization.user != user ]
def remove_user_from_organization(organization, user): """Remove a user from an organization""" team = get_organization_members_team(organization) remove_user_from_team(team, user) owners_team = get_organization_owners_team(organization) remove_user_from_team(owners_team, user) role = get_role_in_org(user, organization) # Remove user from all org projects for project in organization.user.project_org.all(): ShareProject(project, user.username, role, remove=True).save()
def get_users(self, obj): members = get_organization_members(obj) if obj else [] return [{ 'user': u.username, 'role': get_role_in_org(u, obj), 'first_name': u.first_name, 'last_name': u.last_name, 'gravatar': u.profile.gravatar, 'metadata': u.profile.metadata, } for u in members]
def check_inherit_permission_from_project(xform_id, user): if xform_id == 'public': return try: int(xform_id) except ValueError: return # get the project_xform xforms = XForm.objects.filter(pk=xform_id) if not xforms: return # get and compare the project role to the xform role project_role = get_role_in_org(user, xforms[0].project) xform_role = get_role_in_org(user, xforms[0]) # if diff set the project role to the xform if xform_role != project_role: _set_xform_permission(project_role, user, xforms[0])
def get_users(self, obj): # pylint: disable=no-self-use """ Return organization members. """ members = get_organization_members(obj) if obj else [] return [{ 'user': u.username, 'role': get_role_in_org(u, obj), 'first_name': u.first_name, 'last_name': u.last_name, 'gravatar': u.profile.gravatar, } for u in members]
def remove_user_from_organization(organization, user): """Remove a user from an organization""" team = get_organization_members_team(organization) remove_user_from_team(team, user) owners_team = get_organization_owners_team(organization) remove_user_from_team(owners_team, user) role = get_role_in_org(user, organization) role_cls = ROLES.get(role) if role_cls: # Remove object permissions role_cls.remove_obj_permissions(user, organization) role_cls.remove_obj_permissions(user, organization.userprofile_ptr) # Remove user from all org projects for project in organization.user.project_org.all(): ShareProject(project, user.username, role, remove=True).save()