def resolve_project_incidences(self, info): project_incidences = {} type_incidence = None number_incidences = 0 if has_project_perms( self, settings.PROJECT_PERMS_PROJECT_MANAGER, info.context.user, ): errors_incidences = self.validations \ .filter_by_validation_type_error() \ .filter_by_status_pending().count() warnings_incidences = self.validations \ .filter_by_validation_type_warning() \ .filter_by_status_pending().count() if errors_incidences: type_incidence = self.validations \ .filter_by_validation_type_error() \ .first().validation_type number_incidences = errors_incidences elif warnings_incidences: type_incidence = self.validations \ .filter_by_validation_type_warning() \ .first().validation_type number_incidences = warnings_incidences project_incidences = {'type': type_incidence, 'number': number_incidences} return project_incidences
def check_edit_permissions(self): user = self.request.user project = self.get_object() valid = has_project_perms(project, settings.PROJECT_PERMS_EDIT_PROJECT, user) if not valid: raise exceptions.PermissionDenied
def resolve_admin_url(self, info): url = '' if has_project_perms( self, settings.PROJECT_PERMS_PROJECT_MANAGER, info.context.user, ): url = reverse('project:project:dashboard', kwargs={'project_id': self.pk}) return url
def create(self, user_from, project, name, coach, *args, **kwargs): """ User: the user that creates the object Members must be a dict {'name': '', 'email': ''} """ # Create the ConsultantProjectRole for this consultant # with a Coach role if don't exist # Check for permissions for the user has_project_perms( project, settings.PROJECT_PERMS_CRUD_TEAM, user_from, ) role_code = project.customize.get('roles').get('team_manager')[0] exo_role = ExORole.objects.get(code=role_code) ConsultantProjectRole.objects.get_or_create_consultant( user_from=user_from, consultant=coach, project=project, exo_role=exo_role) stream = kwargs.get('stream') team = self.model( created_by=kwargs.get('created_by'), project=project, name=name, coach=coach, stream=stream, ) team.save() team.zoom_id = kwargs.get('zoom_id', None) for member in kwargs.get('team_members', []): team.add_member( user_from=user_from, email=member.get('email'), name=member.get('short_name'), ) return team
def update(self, instance, user_from, name, coach, *args, **kwargs): has_project_perms(instance.project, settings.PROJECT_PERMS_CRUD_TEAM, user_from) instance.name = name instance.stream = kwargs.get('stream') instance.zoom_id = kwargs.get('zoom_id', None) instance.save(update_fields=['name', 'stream', 'slug']) role_code = instance.project.customize.get('roles').get( 'team_manager')[0] exo_role = ExORole.objects.get(code=role_code) ConsultantProjectRole.objects.get_or_create_consultant( user_from=user_from, consultant=coach, project=instance.project, exo_role=exo_role) instance.update_coach(user_from, coach) instance.update_members(user_from, kwargs.get('team_members', [])) instance.refresh_from_db() return instance
def next_project_url(project, user): zone = False is_a_participant = user.projects_member \ .filter_by_project(project) \ .exclude_staff_and_admin() \ .actives_only() \ .exists() is_a_coach = user.is_consultant and user.consultant.teams_coach.filter_by_project( project).exists() project_admin = has_project_perms( project, settings.PROJECT_PERMS_PROJECT_MANAGER, user, ) if is_a_participant or is_a_coach: url = project.get_frontend_index_url(user) if url and url.startswith('http'): zone = True elif user.is_superuser or project_admin: url = project.get_absolute_url() zone = True else: consultant_project_roles = project.consultants_roles.filter_by_user( user) is_manager = False can_access_to_project = False for c_project_role in consultant_project_roles: if c_project_role.has_manager_perms: is_manager = True elif c_project_role.exo_role.code == settings.EXO_ROLE_CODE_SPRINT_REPORTER: can_access_to_project = True if is_manager: url = project.get_absolute_url() zone = True elif can_access_to_project: url = project.get_frontend_index_url(user) else: url = '' return url, zone
def has_perm(self, user, permission): return has_project_perms(self, permission, user)
def user_can_fill(self, user): user_in_project = has_project_perms( self.project, settings.PROJECT_PERMS_VIEW_PROJECT, user) return user_in_project