You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UserSettingsDialog.vue 8.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <!--
  2. - @copyright 2023 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. <template>
  23. <NcAppSettingsDialog :open.sync="isModalOpen"
  24. :show-navigation="true"
  25. :name="t('settings', 'Account management settings')">
  26. <NcAppSettingsSection id="visibility-settings"
  27. :name="t('settings', 'Visibility')">
  28. <NcCheckboxRadioSwitch type="switch"
  29. data-test="showLanguages"
  30. :checked.sync="showLanguages">
  31. {{ t('settings', 'Show language') }}
  32. </NcCheckboxRadioSwitch>
  33. <NcCheckboxRadioSwitch type="switch"
  34. data-test="showUserBackend"
  35. :checked.sync="showUserBackend">
  36. {{ t('settings', 'Show account backend') }}
  37. </NcCheckboxRadioSwitch>
  38. <NcCheckboxRadioSwitch type="switch"
  39. data-test="showStoragePath"
  40. :checked.sync="showStoragePath">
  41. {{ t('settings', 'Show storage path') }}
  42. </NcCheckboxRadioSwitch>
  43. <NcCheckboxRadioSwitch type="switch"
  44. data-test="showLastLogin"
  45. :checked.sync="showLastLogin">
  46. {{ t('settings', 'Show last login') }}
  47. </NcCheckboxRadioSwitch>
  48. </NcAppSettingsSection>
  49. <NcAppSettingsSection id="groups-sorting"
  50. :name="t('settings', 'Sorting')">
  51. <NcNoteCard v-if="isGroupSortingEnforced" type="warning">
  52. {{ t('settings', 'The system config enforces sorting the groups by name. This also disables showing the member count.') }}
  53. </NcNoteCard>
  54. <fieldset>
  55. <legend>{{ t('settings', 'Group list sorting') }}</legend>
  56. <NcCheckboxRadioSwitch type="radio"
  57. :checked.sync="groupSorting"
  58. data-test="sortGroupsByMemberCount"
  59. :disabled="isGroupSortingEnforced"
  60. name="group-sorting-mode"
  61. value="member-count">
  62. {{ t('settings', 'By member count') }}
  63. </NcCheckboxRadioSwitch>
  64. <NcCheckboxRadioSwitch type="radio"
  65. :checked.sync="groupSorting"
  66. data-test="sortGroupsByName"
  67. :disabled="isGroupSortingEnforced"
  68. name="group-sorting-mode"
  69. value="name">
  70. {{ t('settings', 'By name') }}
  71. </NcCheckboxRadioSwitch>
  72. </fieldset>
  73. </NcAppSettingsSection>
  74. <NcAppSettingsSection id="email-settings"
  75. :name="t('settings', 'Send email')">
  76. <NcCheckboxRadioSwitch type="switch"
  77. data-test="sendWelcomeMail"
  78. :checked.sync="sendWelcomeMail"
  79. :disabled="loadingSendMail">
  80. {{ t('settings', 'Send welcome email to new accounts') }}
  81. </NcCheckboxRadioSwitch>
  82. </NcAppSettingsSection>
  83. <NcAppSettingsSection id="default-settings"
  84. :name="t('settings', 'Defaults')">
  85. <NcSelect v-model="defaultQuota"
  86. :input-label="t('settings', 'Default quota')"
  87. placement="top"
  88. :taggable="true"
  89. :options="quotaOptions"
  90. :create-option="validateQuota"
  91. :placeholder="t('settings', 'Select default quota')"
  92. :clearable="false"
  93. @option:selected="setDefaultQuota" />
  94. </NcAppSettingsSection>
  95. </NcAppSettingsDialog>
  96. </template>
  97. <script>
  98. import { formatFileSize, parseFileSize } from '@nextcloud/files'
  99. import { generateUrl } from '@nextcloud/router'
  100. import axios from '@nextcloud/axios'
  101. import NcAppSettingsDialog from '@nextcloud/vue/dist/Components/NcAppSettingsDialog.js'
  102. import NcAppSettingsSection from '@nextcloud/vue/dist/Components/NcAppSettingsSection.js'
  103. import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadioSwitch.js'
  104. import NcNoteCard from '@nextcloud/vue/dist/Components/NcNoteCard.js'
  105. import NcSelect from '@nextcloud/vue/dist/Components/NcSelect.js'
  106. import { GroupSorting } from '../../constants/GroupManagement.ts'
  107. import { unlimitedQuota } from '../../utils/userUtils.ts'
  108. export default {
  109. name: 'UserSettingsDialog',
  110. components: {
  111. NcAppSettingsDialog,
  112. NcAppSettingsSection,
  113. NcCheckboxRadioSwitch,
  114. NcNoteCard,
  115. NcSelect,
  116. },
  117. props: {
  118. open: {
  119. type: Boolean,
  120. required: true,
  121. },
  122. },
  123. data() {
  124. return {
  125. selectedQuota: false,
  126. loadingSendMail: false,
  127. }
  128. },
  129. computed: {
  130. groupSorting: {
  131. get() {
  132. return this.$store.getters.getGroupSorting === GroupSorting.GroupName ? 'name' : 'member-count'
  133. },
  134. set(sorting) {
  135. this.$store.commit('setGroupSorting', sorting === 'name' ? GroupSorting.GroupName : GroupSorting.UserCount)
  136. },
  137. },
  138. /**
  139. * Admin has configured `sort_groups_by_name` in the system config
  140. */
  141. isGroupSortingEnforced() {
  142. return this.$store.getters.getServerData.forceSortGroupByName
  143. },
  144. isModalOpen: {
  145. get() {
  146. return this.open
  147. },
  148. set(open) {
  149. this.$emit('update:open', open)
  150. },
  151. },
  152. showConfig() {
  153. return this.$store.getters.getShowConfig
  154. },
  155. settings() {
  156. return this.$store.getters.getServerData
  157. },
  158. showLanguages: {
  159. get() {
  160. return this.showConfig.showLanguages
  161. },
  162. set(status) {
  163. this.setShowConfig('showLanguages', status)
  164. },
  165. },
  166. showLastLogin: {
  167. get() {
  168. return this.showConfig.showLastLogin
  169. },
  170. set(status) {
  171. this.setShowConfig('showLastLogin', status)
  172. },
  173. },
  174. showUserBackend: {
  175. get() {
  176. return this.showConfig.showUserBackend
  177. },
  178. set(status) {
  179. this.setShowConfig('showUserBackend', status)
  180. },
  181. },
  182. showStoragePath: {
  183. get() {
  184. return this.showConfig.showStoragePath
  185. },
  186. set(status) {
  187. this.setShowConfig('showStoragePath', status)
  188. },
  189. },
  190. quotaOptions() {
  191. // convert the preset array into objects
  192. const quotaPreset = this.settings.quotaPreset.reduce((acc, cur) => acc.concat({ id: cur, label: cur }), [])
  193. // add default presets
  194. if (this.settings.allowUnlimitedQuota) {
  195. quotaPreset.unshift(unlimitedQuota)
  196. }
  197. return quotaPreset
  198. },
  199. defaultQuota: {
  200. get() {
  201. if (this.selectedQuota !== false) {
  202. return this.selectedQuota
  203. }
  204. if (this.settings.defaultQuota !== unlimitedQuota.id && OC.Util.computerFileSize(this.settings.defaultQuota) >= 0) {
  205. // if value is valid, let's map the quotaOptions or return custom quota
  206. return { id: this.settings.defaultQuota, label: this.settings.defaultQuota }
  207. }
  208. return unlimitedQuota // unlimited
  209. },
  210. set(quota) {
  211. this.selectedQuota = quota
  212. },
  213. },
  214. sendWelcomeMail: {
  215. get() {
  216. return this.settings.newUserSendEmail
  217. },
  218. async set(value) {
  219. try {
  220. this.loadingSendMail = true
  221. this.$store.commit('setServerData', {
  222. ...this.settings,
  223. newUserSendEmail: value,
  224. })
  225. await axios.post(generateUrl('/settings/users/preferences/newUser.sendEmail'), { value: value ? 'yes' : 'no' })
  226. } catch (e) {
  227. console.error('could not update newUser.sendEmail preference: ' + e.message, e)
  228. } finally {
  229. this.loadingSendMail = false
  230. }
  231. },
  232. },
  233. },
  234. methods: {
  235. setShowConfig(key, status) {
  236. this.$store.commit('setShowConfig', { key, value: status })
  237. },
  238. /**
  239. * Validate quota string to make sure it's a valid human file size
  240. *
  241. * @param {string | object} quota Quota in readable format '5 GB' or Object {id: '5 GB', label: '5GB'}
  242. * @return {object} The validated quota object or unlimited quota if input is invalid
  243. */
  244. validateQuota(quota) {
  245. if (typeof quota === 'object') {
  246. quota = quota?.id || quota.label
  247. }
  248. // only used for new presets sent through @Tag
  249. const validQuota = parseFileSize(quota)
  250. if (validQuota === null) {
  251. return unlimitedQuota
  252. } else {
  253. // unify format output
  254. quota = formatFileSize(parseFileSize(quota))
  255. return { id: quota, label: quota }
  256. }
  257. },
  258. /**
  259. * Dispatch default quota set request
  260. *
  261. * @param {string | object} quota Quota in readable format '5 GB' or Object {id: '5 GB', label: '5GB'}
  262. */
  263. setDefaultQuota(quota = 'none') {
  264. // Make sure correct label is set for unlimited quota
  265. if (quota === 'none') {
  266. quota = unlimitedQuota
  267. }
  268. this.$store.dispatch('setAppConfig', {
  269. app: 'files',
  270. key: 'default_quota',
  271. // ensure we only send the preset id
  272. value: quota.id ? quota.id : quota,
  273. }).then(() => {
  274. if (typeof quota !== 'object') {
  275. quota = { id: quota, label: quota }
  276. }
  277. this.defaultQuota = quota
  278. })
  279. },
  280. },
  281. }
  282. </script>
  283. <style scoped lang="scss">
  284. fieldset {
  285. font-weight: bold;
  286. }
  287. </style>