ConfigService.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /**
  2. * @copyright Copyright (c) 2019 John Molakvoæ <skjnldsv@protonmail.com>
  3. *
  4. * @author John Molakvoæ <skjnldsv@protonmail.com>
  5. *
  6. * @license GNU AGPL version 3 or any later version
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as
  10. * published by the Free Software Foundation, either version 3 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. export default class Config {
  23. /**
  24. * Is public upload allowed on link shares ?
  25. *
  26. * @returns {boolean}
  27. * @readonly
  28. * @memberof Config
  29. */
  30. get isPublicUploadEnabled() {
  31. return document.getElementById('filestable')
  32. && document.getElementById('filestable').dataset.allowPublicUpload === 'yes'
  33. }
  34. /**
  35. * Are link share allowed ?
  36. *
  37. * @returns {boolean}
  38. * @readonly
  39. * @memberof Config
  40. */
  41. get isShareWithLinkAllowed() {
  42. return document.getElementById('allowShareWithLink')
  43. && document.getElementById('allowShareWithLink').value === 'yes'
  44. }
  45. /**
  46. * Get the federated sharing documentation link
  47. *
  48. * @returns {string}
  49. * @readonly
  50. * @memberof Config
  51. */
  52. get federatedShareDocLink() {
  53. return OC.appConfig.core.federatedCloudShareDoc
  54. }
  55. /**
  56. * Get the default expiration date as string
  57. *
  58. * @returns {string}
  59. * @readonly
  60. * @memberof Config
  61. */
  62. get defaultExpirationDateString() {
  63. let expireDateString = ''
  64. if (this.isDefaultExpireDateEnabled) {
  65. const date = window.moment.utc()
  66. const expireAfterDays = this.defaultExpireDate
  67. date.add(expireAfterDays, 'days')
  68. expireDateString = date.format('YYYY-MM-DD')
  69. }
  70. return expireDateString
  71. }
  72. /**
  73. * Are link shares password-enforced ?
  74. *
  75. * @returns {boolean}
  76. * @readonly
  77. * @memberof Config
  78. */
  79. get enforcePasswordForPublicLink() {
  80. return OC.appConfig.core.enforcePasswordForPublicLink === true
  81. }
  82. /**
  83. * Is password asked by default on link shares ?
  84. *
  85. * @returns {boolean}
  86. * @readonly
  87. * @memberof Config
  88. */
  89. get enableLinkPasswordByDefault() {
  90. return OC.appConfig.core.enableLinkPasswordByDefault === true
  91. }
  92. /**
  93. * Is link shares expiration enforced ?
  94. *
  95. * @returns {boolean}
  96. * @readonly
  97. * @memberof Config
  98. */
  99. get isDefaultExpireDateEnforced() {
  100. return OC.appConfig.core.defaultExpireDateEnforced === true
  101. }
  102. /**
  103. * Is there a default expiration date for new link shares ?
  104. *
  105. * @returns {boolean}
  106. * @readonly
  107. * @memberof Config
  108. */
  109. get isDefaultExpireDateEnabled() {
  110. return OC.appConfig.core.defaultExpireDateEnabled === true
  111. }
  112. /**
  113. * Are users on this server allowed to send shares to other servers ?
  114. *
  115. * @returns {boolean}
  116. * @readonly
  117. * @memberof Config
  118. */
  119. get isRemoteShareAllowed() {
  120. return OC.appConfig.core.remoteShareAllowed === true
  121. }
  122. /**
  123. * Is sharing my mail (link share) enabled ?
  124. *
  125. * @returns {boolean}
  126. * @readonly
  127. * @memberof Config
  128. */
  129. get isMailShareAllowed() {
  130. return OC.appConfig.shareByMailEnabled !== undefined
  131. }
  132. /**
  133. * Get the default days to expiration
  134. *
  135. * @returns {int}
  136. * @readonly
  137. * @memberof Config
  138. */
  139. get defaultExpireDate() {
  140. return OC.appConfig.core.defaultExpireDate
  141. }
  142. /**
  143. * Is resharing allowed ?
  144. *
  145. * @returns {boolean}
  146. * @readonly
  147. * @memberof Config
  148. */
  149. get isResharingAllowed() {
  150. return OC.appConfig.core.resharingAllowed === true
  151. }
  152. /**
  153. * Is password enforced for mail shares ?
  154. *
  155. * @returns {boolean}
  156. * @readonly
  157. * @memberof Config
  158. */
  159. get isPasswordForMailSharesRequired() {
  160. return (OC.appConfig.shareByMail === undefined) ? false : OC.appConfig.shareByMail.enforcePasswordProtection === true
  161. }
  162. /**
  163. * Is sharing with groups allowed ?
  164. *
  165. * @returns {boolean}
  166. * @readonly
  167. * @memberof Config
  168. */
  169. get allowGroupSharing() {
  170. return OC.appConfig.core.allowGroupSharing === true
  171. }
  172. /**
  173. * Get the maximum results of a share search
  174. *
  175. * @returns {int}
  176. * @readonly
  177. * @memberof Config
  178. */
  179. get maxAutocompleteResults() {
  180. return parseInt(OC.config['sharing.maxAutocompleteResults'], 10) || 200
  181. }
  182. /**
  183. * Get the minimal string length
  184. * to initiate a share search
  185. *
  186. * @returns {int}
  187. * @readonly
  188. * @memberof Config
  189. */
  190. get minSearchStringLength() {
  191. return parseInt(OC.config['sharing.minSearchStringLength'], 10) || 0
  192. }
  193. /**
  194. * Get the password policy config
  195. *
  196. * @returns {Object}
  197. * @readonly
  198. * @memberof Config
  199. */
  200. get passwordPolicy() {
  201. const capabilities = OC.getCapabilities()
  202. return capabilities.password_policy ? capabilities.password_policy : {}
  203. }
  204. }