acl.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. const logger = require('@alias/logger')('growi:service:AclService'); // eslint-disable-line no-unused-vars
  2. /**
  3. * the service class of AclService
  4. */
  5. class AclService {
  6. constructor(configManager) {
  7. this.configManager = configManager;
  8. this.labels = {
  9. SECURITY_RESTRICT_GUEST_MODE_DENY: 'Deny',
  10. SECURITY_RESTRICT_GUEST_MODE_READONLY: 'Readonly',
  11. SECURITY_REGISTRATION_MODE_OPEN: 'Open',
  12. SECURITY_REGISTRATION_MODE_RESTRICTED: 'Restricted',
  13. SECURITY_REGISTRATION_MODE_CLOSED: 'Closed',
  14. };
  15. }
  16. isAclEnabled() {
  17. const isPublicWikiOnly = this.configManager.getConfig('crowi', 'security:isPublicWikiOnly');
  18. const isPrivateWikiOnly = this.configManager.getConfig('crowi', 'security:isPrivateWikiOnly');
  19. return !(isPublicWikiOnly || isPrivateWikiOnly);
  20. }
  21. getIsGuestAllowedToRead() {
  22. const isPublicWikiOnly = this.configManager.getConfig('crowi', 'security:isPublicWikiOnly');
  23. const isPrivateWikiOnly = this.configManager.getConfig('crowi', 'security:isPrivateWikiOnly');
  24. // return false if private wiki mode
  25. if (isPrivateWikiOnly) {
  26. return false;
  27. }
  28. // return true if puclic wiki mode
  29. if (isPublicWikiOnly) {
  30. return true;
  31. }
  32. const guestMode = this.configManager.getConfig('crowi', 'security:restrictGuestMode');
  33. // 'Readonly' => returns true (allow access to guests)
  34. // 'Deny', null, undefined, '', ... everything else => returns false (requires login)
  35. return guestMode === this.labels.SECURITY_RESTRICT_GUEST_MODE_READONLY;
  36. }
  37. getRestrictGuestModeLabels() {
  38. const labels = {};
  39. labels[this.labels.SECURITY_RESTRICT_GUEST_MODE_DENY] = 'security_setting.guest_mode.deny';
  40. labels[this.labels.SECURITY_RESTRICT_GUEST_MODE_READONLY] = 'security_setting.guest_mode.readonly';
  41. return labels;
  42. }
  43. getRegistrationModeLabels() {
  44. const labels = {};
  45. labels[this.labels.SECURITY_REGISTRATION_MODE_OPEN] = 'security_setting.registration_mode.open';
  46. labels[this.labels.SECURITY_REGISTRATION_MODE_RESTRICTED] = 'security_setting.registration_mode.restricted';
  47. labels[this.labels.SECURITY_REGISTRATION_MODE_CLOSED] = 'security_setting.registration_mode.closed';
  48. return labels;
  49. }
  50. userUpperLimit() {
  51. // const limit = this.configManager.getConfig('crowi', 'USER_UPPER_LIMIT');
  52. const limit = process.env.USER_UPPER_LIMIT;
  53. if (limit) {
  54. return Number(limit);
  55. }
  56. return 0;
  57. }
  58. }
  59. module.exports = AclService;