Coverage for src / mesh / crud / comments.py: 89%

19 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-10-22 07:20 +0000

1from mesh.models.orm.journal_models import JournalSection 

2from mesh.models.orm.submission_models import Submission 

3from mesh.models.orm.user_models import User 

4 

5 

6# todo : move to submission_models.py or somewhere else 

7def _is_section_editor(user: User, submission: Submission) -> bool: 

8 """ 

9 An editor can access a submissions being or not in submission.editors, being in the submission's journal_section 

10 """ 

11 if not submission.journal_section: 

12 return False 

13 journal_sections = [ 

14 submission.journal_section, 

15 *JournalSection.objects.get_parents_recursive(submission.journal_section), 

16 ] 

17 return user.editor_sections.filter(journal_section__in=journal_sections).exists() 

18 

19 

20def submission_roles(user: User, submission: Submission) -> set[str]: 

21 """ 

22 User's roles on a given submission. 

23 Not the current role. 

24 """ 

25 roles: set[str] = set() 

26 

27 # Author 

28 if submission.created_by_id == user.pk: 

29 roles.add("author") 

30 # 

31 # if user in submission.authors: 

32 # roles.add("author") 

33 

34 # Reviewer 

35 # (cf. Reviewer.can_access_submission) 

36 if submission.versions.filter(reviews__reviewer=user).exists(): 

37 roles.add("reviewer") 

38 

39 # Editor 

40 if submission.editors.filter(user=user).exists() or _is_section_editor(user, submission): 

41 roles.add("editor") 

42 

43 # Journal Manager 

44 if user.current_role == "journal_manager": 

45 roles.add("editor") 

46 

47 return roles