Coverage for apps/comments_views/core/app_settings.py: 91%

22 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-05-19 19:20 +0000

1from django.conf import settings 

2 

3 

4class AppSettings: 

5 """Wrapper for django settings related to this application.""" 

6 

7 def __init__(self): 

8 self.prefix = "COMMENTS_VIEWS_" 

9 

10 def _setting(self, name, default): 

11 """ 

12 Gets the provided setting with the app prefix (see `self.prefix`). 

13 Params: 

14 - `name`: The name of the setting. 

15 - `default`: Fallback if the settings is not defined. 

16 """ 

17 return getattr(settings, self.prefix + name, default) 

18 

19 @property 

20 def API_BASE_URL(self) -> str: 

21 """ 

22 The base URL of the comments database server. 

23 Falls back to https://comments.centre-mersenne.org. 

24 """ 

25 return self._setting("API_BASE_URL", "https://comments.centre-mersenne.org") 

26 

27 @property 

28 def API_CREDENTIALS(self): 

29 """ 

30 Credentials used to authenticate when performing API calls to the comments 

31 server. 

32 """ 

33 return self._setting("API_CREDENTIALS", None) 

34 

35 @property 

36 def EMAIL_AUTHOR(self) -> bool: 

37 """ 

38 Whether to send an e-mail to the article's authors when a comment is validated 

39 by a moderator. 

40 Default: True. 

41 

42 TODO: This should be included in the comments_moderation app instead. 

43 There is a design error regarding the POST function of 

44 `CommentDashboardDetailsView`. It's used differently by comments_views/journal 

45 and comments_moderation apps. The POST logic for the moderation should be 

46 overwritten in comments_moderation app instead of being located 

47 in comments_views/core. 

48 """ 

49 return self._setting("EMAIL_AUTHOR", True) 

50 

51 @property 

52 def ORCID_BASE_URL(self) -> str: 

53 """ 

54 Base URL used to generate ORCID record links. 

55 

56 This should only be used in test to use https://sandbox.orcid.org/ domain 

57 instead of https://orcid.org/ 

58 """ 

59 url = self._setting("ORCID_BASE_URL", "https://orcid.org/") 

60 if url[-1] != "/": 60 ↛ 61line 60 didn't jump to line 61, because the condition on line 60 was never true

61 url += "/" 

62 return url 

63 

64 

65app_settings = AppSettings()