SharingEntry.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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. <template>
  23. <li class="sharing-entry">
  24. <Avatar class="sharing-entry__avatar"
  25. :user="share.shareWith"
  26. :display-name="share.shareWithDisplayName"
  27. :url="share.shareWithAvatar" />
  28. <div v-tooltip.auto="tooltip" class="sharing-entry__desc">
  29. <h5>{{ title }}</h5>
  30. </div>
  31. <Actions menu-align="right" class="sharing-entry__actions">
  32. <!-- edit permission -->
  33. <ActionCheckbox
  34. ref="canEdit"
  35. :checked.sync="canEdit"
  36. :value="permissionsEdit"
  37. :disabled="saving">
  38. {{ t('files_sharing', 'Allow editing') }}
  39. </ActionCheckbox>
  40. <!-- reshare permission -->
  41. <ActionCheckbox
  42. ref="canReshare"
  43. :checked.sync="canReshare"
  44. :value="permissionsShare"
  45. :disabled="saving">
  46. {{ t('files_sharing', 'Can reshare') }}
  47. </ActionCheckbox>
  48. <!-- expiration date -->
  49. <ActionCheckbox :checked.sync="hasExpirationDate"
  50. :disabled="config.isDefaultExpireDateEnforced || saving"
  51. @uncheck="onExpirationDisable">
  52. {{ config.isDefaultExpireDateEnforced
  53. ? t('files_sharing', 'Expiration date enforced')
  54. : t('files_sharing', 'Set expiration date') }}
  55. </ActionCheckbox>
  56. <ActionInput v-if="hasExpirationDate"
  57. ref="expireDate"
  58. v-tooltip.auto="{
  59. content: errors.expireDate,
  60. show: errors.expireDate,
  61. trigger: 'manual'
  62. }"
  63. :class="{ error: errors.expireDate}"
  64. :disabled="saving"
  65. :first-day-of-week="firstDay"
  66. :lang="lang"
  67. :value="share.expireDate"
  68. icon="icon-calendar-dark"
  69. type="date"
  70. :not-before="dateTomorrow"
  71. :not-after="dateMaxEnforced"
  72. @update:value="onExpirationChange">
  73. {{ t('files_sharing', 'Enter a date') }}
  74. </ActionInput>
  75. <!-- note -->
  76. <template v-if="canHaveNote">
  77. <ActionCheckbox
  78. :checked.sync="hasNote"
  79. :disabled="saving"
  80. @uncheck="queueUpdate('note')">
  81. {{ t('files_sharing', 'Note to recipient') }}
  82. </ActionCheckbox>
  83. <ActionTextEditable v-if="hasNote"
  84. ref="note"
  85. v-tooltip.auto="{
  86. content: errors.note,
  87. show: errors.note,
  88. trigger: 'manual'
  89. }"
  90. :class="{ error: errors.note}"
  91. :disabled="saving"
  92. :value.sync="share.note"
  93. icon="icon-edit"
  94. @update:value="debounceQueueUpdate('note')" />
  95. </template>
  96. <ActionButton icon="icon-delete" :disabled="saving" @click.prevent="onDelete">
  97. {{ t('files_sharing', 'Unshare') }}
  98. </ActionButton>
  99. </Actions>
  100. </li>
  101. </template>
  102. <script>
  103. import Avatar from 'nextcloud-vue/dist/Components/Avatar'
  104. import Actions from 'nextcloud-vue/dist/Components/Actions'
  105. import ActionButton from 'nextcloud-vue/dist/Components/ActionButton'
  106. import ActionCheckbox from 'nextcloud-vue/dist/Components/ActionCheckbox'
  107. import ActionInput from 'nextcloud-vue/dist/Components/ActionInput'
  108. import ActionTextEditable from 'nextcloud-vue/dist/Components/ActionTextEditable'
  109. import Tooltip from 'nextcloud-vue/dist/Directives/Tooltip'
  110. // eslint-disable-next-line no-unused-vars
  111. import Share from '../models/Share'
  112. import SharesMixin from '../mixins/SharesMixin'
  113. export default {
  114. name: 'SharingEntry',
  115. components: {
  116. Actions,
  117. ActionButton,
  118. ActionCheckbox,
  119. ActionInput,
  120. ActionTextEditable,
  121. Avatar
  122. },
  123. directives: {
  124. Tooltip
  125. },
  126. mixins: [SharesMixin],
  127. data() {
  128. return {
  129. permissionsEdit: OC.PERMISSION_UPDATE,
  130. permissionsRead: OC.PERMISSION_READ,
  131. permissionsShare: OC.PERMISSION_SHARE
  132. }
  133. },
  134. computed: {
  135. title() {
  136. let title = this.share.shareWithDisplayName
  137. if (this.share.type === this.SHARE_TYPES.SHARE_TYPE_GROUP) {
  138. title += ` (${t('files_sharing', 'group')})`
  139. } else if (this.share.type === this.SHARE_TYPES.SHARE_TYPE_ROOM) {
  140. title += ` (${t('files_sharing', 'conversation')})`
  141. } else if (this.share.type === this.SHARE_TYPES.SHARE_TYPE_REMOTE) {
  142. title += ` (${t('files_sharing', 'remote')})`
  143. } else if (this.share.type === this.SHARE_TYPES.SHARE_TYPE_REMOTE_GROUP) {
  144. title += ` (${t('files_sharing', 'remote group')})`
  145. } else if (this.share.type === this.SHARE_TYPES.SHARE_TYPE_GUEST) {
  146. title += ` (${t('files_sharing', 'guest')})`
  147. }
  148. return title
  149. },
  150. tooltip() {
  151. if (this.share.owner !== this.share.uidFileOwner) {
  152. const data = {
  153. // todo: strong or italic?
  154. // but the t function escape any html from the data :/
  155. user: this.share.shareWithDisplayName,
  156. owner: this.share.owner
  157. }
  158. if (this.share.type === this.SHARE_TYPES.SHARE_TYPE_GROUP) {
  159. return t('files_sharing', 'Shared with the group {user} by {owner}', data)
  160. } else if (this.share.type === this.SHARE_TYPES.SHARE_TYPE_ROOM) {
  161. return t('files_sharing', 'Shared with the conversation {user} by {owner}', data)
  162. }
  163. return t('files_sharing', 'Shared with {user} by {owner}', data)
  164. }
  165. return null
  166. },
  167. canHaveNote() {
  168. return this.share.type !== this.SHARE_TYPES.SHARE_TYPE_REMOTE
  169. && this.share.type !== this.SHARE_TYPES.SHARE_TYPE_REMOTE_GROUP
  170. },
  171. /**
  172. * Can the sharee edit the shared file ?
  173. */
  174. canEdit: {
  175. get: function() {
  176. return this.share.hasUpdatePermission
  177. },
  178. set: function(checked) {
  179. this.updatePermissions(checked, this.canReshare)
  180. }
  181. },
  182. /**
  183. * Can the sharee reshare the file ?
  184. */
  185. canReshare: {
  186. get: function() {
  187. return this.share.hasSharePermission
  188. },
  189. set: function(checked) {
  190. this.updatePermissions(this.canEdit, checked)
  191. }
  192. }
  193. },
  194. methods: {
  195. updatePermissions(isEditChecked, isReshareChecked) {
  196. // calc permissions if checked
  197. const permissions = this.permissionsRead
  198. | (isEditChecked ? this.permissionsEdit : 0)
  199. | (isReshareChecked ? this.permissionsShare : 0)
  200. this.share.permissions = permissions
  201. this.queueUpdate('permissions')
  202. }
  203. }
  204. }
  205. </script>
  206. <style lang="scss" scoped>
  207. .sharing-entry {
  208. display: flex;
  209. align-items: center;
  210. height: 44px;
  211. &__desc {
  212. display: flex;
  213. flex-direction: column;
  214. justify-content: space-between;
  215. padding: 8px;
  216. line-height: 1.2em;
  217. p {
  218. color: var(--color-text-maxcontrast);
  219. }
  220. }
  221. &__actions {
  222. margin-left: auto;
  223. }
  224. }
  225. </style>