AccountPropertyConstants.js 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /**
  2. * @copyright 2021, Christopher Ng <chrng8@gmail.com>
  3. *
  4. * @author Christopher Ng <chrng8@gmail.com>
  5. *
  6. * @license AGPL-3.0-or-later
  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. /*
  23. * SYNC to be kept in sync with `lib/public/Accounts/IAccountManager.php`
  24. */
  25. import { mdiAccountGroup, mdiCellphone, mdiLock, mdiWeb } from '@mdi/js'
  26. import { translate as t } from '@nextcloud/l10n'
  27. /** Enum of account properties */
  28. export const ACCOUNT_PROPERTY_ENUM = Object.freeze({
  29. ADDRESS: 'address',
  30. AVATAR: 'avatar',
  31. BIOGRAPHY: 'biography',
  32. DISPLAYNAME: 'displayname',
  33. EMAIL_COLLECTION: 'additional_mail',
  34. EMAIL: 'email',
  35. HEADLINE: 'headline',
  36. NOTIFICATION_EMAIL: 'notify_email',
  37. FEDIVERSE: 'fediverse',
  38. ORGANISATION: 'organisation',
  39. PHONE: 'phone',
  40. PROFILE_ENABLED: 'profile_enabled',
  41. ROLE: 'role',
  42. TWITTER: 'twitter',
  43. WEBSITE: 'website',
  44. })
  45. /** Enum of account properties to human readable account property names */
  46. export const ACCOUNT_PROPERTY_READABLE_ENUM = Object.freeze({
  47. ADDRESS: t('settings', 'Location'),
  48. AVATAR: t('settings', 'Profile picture'),
  49. BIOGRAPHY: t('settings', 'About'),
  50. DISPLAYNAME: t('settings', 'Full name'),
  51. EMAIL_COLLECTION: t('settings', 'Additional email'),
  52. EMAIL: t('settings', 'Email'),
  53. HEADLINE: t('settings', 'Headline'),
  54. ORGANISATION: t('settings', 'Organisation'),
  55. PHONE: t('settings', 'Phone number'),
  56. PROFILE_ENABLED: t('settings', 'Profile'),
  57. ROLE: t('settings', 'Role'),
  58. TWITTER: t('settings', 'X (formerly Twitter)'),
  59. FEDIVERSE: t('settings', 'Fediverse (e.g. Mastodon)'),
  60. WEBSITE: t('settings', 'Website'),
  61. })
  62. export const NAME_READABLE_ENUM = Object.freeze({
  63. [ACCOUNT_PROPERTY_ENUM.ADDRESS]: ACCOUNT_PROPERTY_READABLE_ENUM.ADDRESS,
  64. [ACCOUNT_PROPERTY_ENUM.AVATAR]: ACCOUNT_PROPERTY_READABLE_ENUM.AVATAR,
  65. [ACCOUNT_PROPERTY_ENUM.BIOGRAPHY]: ACCOUNT_PROPERTY_READABLE_ENUM.BIOGRAPHY,
  66. [ACCOUNT_PROPERTY_ENUM.DISPLAYNAME]: ACCOUNT_PROPERTY_READABLE_ENUM.DISPLAYNAME,
  67. [ACCOUNT_PROPERTY_ENUM.EMAIL_COLLECTION]: ACCOUNT_PROPERTY_READABLE_ENUM.EMAIL_COLLECTION,
  68. [ACCOUNT_PROPERTY_ENUM.EMAIL]: ACCOUNT_PROPERTY_READABLE_ENUM.EMAIL,
  69. [ACCOUNT_PROPERTY_ENUM.HEADLINE]: ACCOUNT_PROPERTY_READABLE_ENUM.HEADLINE,
  70. [ACCOUNT_PROPERTY_ENUM.ORGANISATION]: ACCOUNT_PROPERTY_READABLE_ENUM.ORGANISATION,
  71. [ACCOUNT_PROPERTY_ENUM.PHONE]: ACCOUNT_PROPERTY_READABLE_ENUM.PHONE,
  72. [ACCOUNT_PROPERTY_ENUM.PROFILE_ENABLED]: ACCOUNT_PROPERTY_READABLE_ENUM.PROFILE_ENABLED,
  73. [ACCOUNT_PROPERTY_ENUM.ROLE]: ACCOUNT_PROPERTY_READABLE_ENUM.ROLE,
  74. [ACCOUNT_PROPERTY_ENUM.TWITTER]: ACCOUNT_PROPERTY_READABLE_ENUM.TWITTER,
  75. [ACCOUNT_PROPERTY_ENUM.FEDIVERSE]: ACCOUNT_PROPERTY_READABLE_ENUM.FEDIVERSE,
  76. [ACCOUNT_PROPERTY_ENUM.WEBSITE]: ACCOUNT_PROPERTY_READABLE_ENUM.WEBSITE,
  77. })
  78. /** Enum of profile specific sections to human readable names */
  79. export const PROFILE_READABLE_ENUM = Object.freeze({
  80. PROFILE_VISIBILITY: t('settings', 'Profile visibility'),
  81. })
  82. /** Enum of readable account properties to account property keys used by the server */
  83. export const PROPERTY_READABLE_KEYS_ENUM = Object.freeze({
  84. [ACCOUNT_PROPERTY_READABLE_ENUM.ADDRESS]: ACCOUNT_PROPERTY_ENUM.ADDRESS,
  85. [ACCOUNT_PROPERTY_READABLE_ENUM.AVATAR]: ACCOUNT_PROPERTY_ENUM.AVATAR,
  86. [ACCOUNT_PROPERTY_READABLE_ENUM.BIOGRAPHY]: ACCOUNT_PROPERTY_ENUM.BIOGRAPHY,
  87. [ACCOUNT_PROPERTY_READABLE_ENUM.DISPLAYNAME]: ACCOUNT_PROPERTY_ENUM.DISPLAYNAME,
  88. [ACCOUNT_PROPERTY_READABLE_ENUM.EMAIL_COLLECTION]: ACCOUNT_PROPERTY_ENUM.EMAIL_COLLECTION,
  89. [ACCOUNT_PROPERTY_READABLE_ENUM.EMAIL]: ACCOUNT_PROPERTY_ENUM.EMAIL,
  90. [ACCOUNT_PROPERTY_READABLE_ENUM.HEADLINE]: ACCOUNT_PROPERTY_ENUM.HEADLINE,
  91. [ACCOUNT_PROPERTY_READABLE_ENUM.ORGANISATION]: ACCOUNT_PROPERTY_ENUM.ORGANISATION,
  92. [ACCOUNT_PROPERTY_READABLE_ENUM.PHONE]: ACCOUNT_PROPERTY_ENUM.PHONE,
  93. [ACCOUNT_PROPERTY_READABLE_ENUM.PROFILE_ENABLED]: ACCOUNT_PROPERTY_ENUM.PROFILE_ENABLED,
  94. [ACCOUNT_PROPERTY_READABLE_ENUM.ROLE]: ACCOUNT_PROPERTY_ENUM.ROLE,
  95. [ACCOUNT_PROPERTY_READABLE_ENUM.TWITTER]: ACCOUNT_PROPERTY_ENUM.TWITTER,
  96. [ACCOUNT_PROPERTY_READABLE_ENUM.FEDIVERSE]: ACCOUNT_PROPERTY_ENUM.FEDIVERSE,
  97. [ACCOUNT_PROPERTY_READABLE_ENUM.WEBSITE]: ACCOUNT_PROPERTY_ENUM.WEBSITE,
  98. })
  99. /**
  100. * Enum of account setting properties
  101. *
  102. * Account setting properties unlike account properties do not support scopes*
  103. */
  104. export const ACCOUNT_SETTING_PROPERTY_ENUM = Object.freeze({
  105. LANGUAGE: 'language',
  106. LOCALE: 'locale',
  107. })
  108. /** Enum of account setting properties to human readable setting properties */
  109. export const ACCOUNT_SETTING_PROPERTY_READABLE_ENUM = Object.freeze({
  110. LANGUAGE: t('settings', 'Language'),
  111. LOCALE: t('settings', 'Locale'),
  112. })
  113. /** Enum of scopes */
  114. export const SCOPE_ENUM = Object.freeze({
  115. PRIVATE: 'v2-private',
  116. LOCAL: 'v2-local',
  117. FEDERATED: 'v2-federated',
  118. PUBLISHED: 'v2-published',
  119. })
  120. /** Enum of readable account properties to supported scopes */
  121. export const PROPERTY_READABLE_SUPPORTED_SCOPES_ENUM = Object.freeze({
  122. [ACCOUNT_PROPERTY_READABLE_ENUM.ADDRESS]: [SCOPE_ENUM.LOCAL, SCOPE_ENUM.PRIVATE],
  123. [ACCOUNT_PROPERTY_READABLE_ENUM.AVATAR]: [SCOPE_ENUM.LOCAL, SCOPE_ENUM.PRIVATE],
  124. [ACCOUNT_PROPERTY_READABLE_ENUM.BIOGRAPHY]: [SCOPE_ENUM.LOCAL, SCOPE_ENUM.PRIVATE],
  125. [ACCOUNT_PROPERTY_READABLE_ENUM.DISPLAYNAME]: [SCOPE_ENUM.LOCAL],
  126. [ACCOUNT_PROPERTY_READABLE_ENUM.EMAIL_COLLECTION]: [SCOPE_ENUM.LOCAL],
  127. [ACCOUNT_PROPERTY_READABLE_ENUM.EMAIL]: [SCOPE_ENUM.LOCAL],
  128. [ACCOUNT_PROPERTY_READABLE_ENUM.HEADLINE]: [SCOPE_ENUM.LOCAL, SCOPE_ENUM.PRIVATE],
  129. [ACCOUNT_PROPERTY_READABLE_ENUM.ORGANISATION]: [SCOPE_ENUM.LOCAL, SCOPE_ENUM.PRIVATE],
  130. [ACCOUNT_PROPERTY_READABLE_ENUM.PHONE]: [SCOPE_ENUM.LOCAL, SCOPE_ENUM.PRIVATE],
  131. [ACCOUNT_PROPERTY_READABLE_ENUM.PROFILE_ENABLED]: [SCOPE_ENUM.LOCAL, SCOPE_ENUM.PRIVATE],
  132. [ACCOUNT_PROPERTY_READABLE_ENUM.ROLE]: [SCOPE_ENUM.LOCAL, SCOPE_ENUM.PRIVATE],
  133. [ACCOUNT_PROPERTY_READABLE_ENUM.TWITTER]: [SCOPE_ENUM.LOCAL, SCOPE_ENUM.PRIVATE],
  134. [ACCOUNT_PROPERTY_READABLE_ENUM.FEDIVERSE]: [SCOPE_ENUM.LOCAL, SCOPE_ENUM.PRIVATE],
  135. [ACCOUNT_PROPERTY_READABLE_ENUM.WEBSITE]: [SCOPE_ENUM.LOCAL, SCOPE_ENUM.PRIVATE],
  136. })
  137. /** List of readable account properties which aren't published to the lookup server */
  138. export const UNPUBLISHED_READABLE_PROPERTIES = Object.freeze([
  139. ACCOUNT_PROPERTY_READABLE_ENUM.BIOGRAPHY,
  140. ACCOUNT_PROPERTY_READABLE_ENUM.HEADLINE,
  141. ACCOUNT_PROPERTY_READABLE_ENUM.ORGANISATION,
  142. ACCOUNT_PROPERTY_READABLE_ENUM.ROLE,
  143. ])
  144. /** Scope suffix */
  145. export const SCOPE_SUFFIX = 'Scope'
  146. /**
  147. * Enum of scope names to properties
  148. *
  149. * Used for federation control*
  150. */
  151. export const SCOPE_PROPERTY_ENUM = Object.freeze({
  152. [SCOPE_ENUM.PRIVATE]: {
  153. name: SCOPE_ENUM.PRIVATE,
  154. displayName: t('settings', 'Private'),
  155. tooltip: t('settings', 'Only visible to people matched via phone number integration through Talk on mobile'),
  156. tooltipDisabled: t('settings', 'Not available as this property is required for core functionality including file sharing and calendar invitations'),
  157. icon: mdiCellphone,
  158. },
  159. [SCOPE_ENUM.LOCAL]: {
  160. name: SCOPE_ENUM.LOCAL,
  161. displayName: t('settings', 'Local'),
  162. tooltip: t('settings', 'Only visible to people on this instance and guests'),
  163. // tooltipDisabled is not required here as this scope is supported by all account properties
  164. icon: mdiLock,
  165. },
  166. [SCOPE_ENUM.FEDERATED]: {
  167. name: SCOPE_ENUM.FEDERATED,
  168. displayName: t('settings', 'Federated'),
  169. tooltip: t('settings', 'Only synchronize to trusted servers'),
  170. tooltipDisabled: t('settings', 'Not available as federation has been disabled for your account, contact your system administration if you have any questions'),
  171. icon: mdiAccountGroup,
  172. },
  173. [SCOPE_ENUM.PUBLISHED]: {
  174. name: SCOPE_ENUM.PUBLISHED,
  175. displayName: t('settings', 'Published'),
  176. tooltip: t('settings', 'Synchronize to trusted servers and the global and public address book'),
  177. tooltipDisabled: t('settings', 'Not available as publishing account specific data to the lookup server is not allowed, contact your system administration if you have any questions'),
  178. icon: mdiWeb,
  179. },
  180. })
  181. /** Default additional email scope */
  182. export const DEFAULT_ADDITIONAL_EMAIL_SCOPE = SCOPE_ENUM.LOCAL
  183. /** Enum of verification constants, according to IAccountManager */
  184. export const VERIFICATION_ENUM = Object.freeze({
  185. NOT_VERIFIED: 0,
  186. VERIFICATION_IN_PROGRESS: 1,
  187. VERIFIED: 2,
  188. })
  189. /**
  190. * Email validation regex
  191. *
  192. * Sourced from https://github.com/mpyw/FILTER_VALIDATE_EMAIL.js/blob/71e62ca48841d2246a1b531e7e84f5a01f15e615/src/regexp/ascii.ts*
  193. */
  194. // eslint-disable-next-line no-control-regex
  195. export const VALIDATE_EMAIL_REGEX = /^(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){255,})(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){65,}@)(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22))(?:\.(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22)))*@(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn--)?[a-z0-9]+(?:-+[a-z0-9]+)*\.){1,126}){1,}(?:(?:[a-z][a-z0-9]*)|(?:(?:xn--)[a-z0-9]+))(?:-+[a-z0-9]+)*)|(?:\[(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(?:(?!(?:.*[a-f0-9][:\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?)))?(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\.(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))\]))$/i