def uploaded_files_with_visibility(self, user_from):
        user_from_files = []

        all_files = self.uploaded_files
        all_files_without_visibility = all_files.filter(
            visibility__isnull=True)
        all_files_with_visibility = self.get_uploaded_files_with_visibility()

        files_with_visibility_public = all_files_with_visibility.filter(
            visibility=settings.FILES_VISIBILITY_GROUP)
        files_with_visibility_private = all_files_with_visibility.filter(
            visibility=settings.FILES_VISIBILITY_PRIVATE)

        # ALL users --> Files without visibility relation model or with public visibility
        user_from_files += all_files_without_visibility.values_list('pk',
                                                                    flat=True)
        user_from_files += files_with_visibility_public.values_list(
            'uploaded_file__pk', flat=True)

        # COACH perms --> All files private
        if has_team_perms(self.team, settings.TEAM_PERMS_COACH_TEAM,
                          user_from):
            user_from_files += files_with_visibility_private \
                .values_list('uploaded_file__pk', flat=True)
        # TEAM perms --> Private files created by me
        else:
            user_from_files += files_with_visibility_private \
                .filter(created_by=user_from) \
                .values_list('uploaded_file__pk', flat=True)

        return all_files.filter(pk__in=user_from_files).distinct()
Exemple #2
0
 def can_be_voted(self):
     # Answer can be voted if the person who created
     # it is not part of the team, coach or project head coach
     return not has_team_perms(
         self.post.team,
         settings.TEAM_PERMS_FULL_VIEW_TEAM,
         self.created_by,
     )
Exemple #3
0
    def zoom_url(self, user_from):
        zoom_url = self.join_url

        if has_team_perms(
            self,
            settings.TEAM_PERMS_COACH_TEAM,
            user_from,
        ):
            zoom_url = self.start_url

        return zoom_url
    def mark_status(self, user_from, step, team, status):
        if not has_team_perms(user=user_from,
                              team=team,
                              perms=settings.TEAM_PERMS_FULL_VIEW_TEAM):
            raise ValidationError(
                '{} has no permissions: TEAM_PERMS_FULL_VIEW_TEAM'.format(
                    user_from))

        assignment_step = AssignmentStep.objects.filter(
            step=step).filter_by_stream(team.stream).first()
        assignment_step_team = AssignmentStepTeam.objects.filter(
            assignment_step=assignment_step, team=team).first()
        defaults = {'status': status, 'created_by': user_from}
        assignment_task_team, _ = AssignmentTaskTeam.objects.update_or_create(
            assignment_step_team=assignment_step_team,
            assignment_task_item=self,
            defaults=defaults)
Exemple #5
0
 def check_user_can_post(self, user_from):
     return has_team_perms(
         self,
         settings.TEAM_PERMS_FULL_VIEW_TEAM,
         user_from)
Exemple #6
0
 def has_perm(self, user, permission):
     return has_team_perms(self, permission, user)
 def can_delete_uploaded_file(self, user, uploaded_file, raise_exception=True):
     return has_team_perms(
         self.team,
         settings.TEAM_PERMS_FULL_VIEW_TEAM,
         user,
     )