cozy-sharing 19.0.0 → 20.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -166,70 +166,105 @@ export var forwardFile = /*#__PURE__*/function () {
166
166
  };
167
167
  }();
168
168
  /**
169
- * updatePermissions - Updates the permissions of a file
169
+ * createPermissions - Create the permissions of a file
170
170
  * @param {object} options
171
171
  * @param {import('cozy-client/types/types').IOCozyFile} options.file File to update permissions
172
172
  * @param {Function} options.t i18n function
173
- * @param {string} options.documentType - Type of the document
173
+ * @param {Date|string} options.ttl - Time to live of the sharing link
174
+ * @param {string} options.password - Password
174
175
  * @param {'readOnly'|'write'} options.editingRights - Editing rights
175
- * @param {Function} options.updateDocumentPermissions - Function to update permissions
176
+ * @param {string} options.documentType - Type of the document
177
+ * @param {Function} options.shareByLink - Function to create permissions
176
178
  * @param {Function} options.showAlert - Function to display an alert
177
179
  */
178
180
 
179
- export var updatePermissions = /*#__PURE__*/function () {
181
+ export var createPermissions = /*#__PURE__*/function () {
180
182
  var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(_ref5) {
181
- var file, t, editingRights, documentType, updateDocumentPermissions, showAlert;
183
+ var file, t, ttl, password, editingRights, documentType, shareByLink, showAlert, verbs;
182
184
  return _regeneratorRuntime.wrap(function _callee3$(_context3) {
183
185
  while (1) switch (_context3.prev = _context3.next) {
184
186
  case 0:
185
- file = _ref5.file, t = _ref5.t, editingRights = _ref5.editingRights, documentType = _ref5.documentType, updateDocumentPermissions = _ref5.updateDocumentPermissions, showAlert = _ref5.showAlert;
186
- _context3.t0 = editingRights;
187
- _context3.next = _context3.t0 === 'readOnly' ? 4 : _context3.t0 === 'write' ? 13 : 22;
188
- break;
189
-
190
- case 4:
191
- _context3.prev = 4;
192
- return _context3.abrupt("return", updateDocumentPermissions(file, READ_ONLY_PERMS));
187
+ file = _ref5.file, t = _ref5.t, ttl = _ref5.ttl, password = _ref5.password, editingRights = _ref5.editingRights, documentType = _ref5.documentType, shareByLink = _ref5.shareByLink, showAlert = _ref5.showAlert;
188
+ _context3.prev = 1;
189
+ verbs = editingRights === 'readOnly' ? READ_ONLY_PERMS : WRITE_PERMS;
190
+ return _context3.abrupt("return", shareByLink(file, {
191
+ verbs: verbs,
192
+ ttl: ttl,
193
+ password: password
194
+ }));
193
195
 
194
- case 8:
195
- _context3.prev = 8;
196
- _context3.t1 = _context3["catch"](4);
196
+ case 6:
197
+ _context3.prev = 6;
198
+ _context3.t0 = _context3["catch"](1);
197
199
  showAlert({
198
200
  message: t("".concat(documentType, ".share.shareByLink.permserror")),
199
201
  severity: 'error',
200
202
  variant: 'filled'
201
203
  });
202
- log.error("Error in 'readOnlyPermissionLink' function when trying to change permission", _context3.t1);
204
+ log.error("Error in 'readOnlyPermissionLink' function when trying to change permission", _context3.t0);
203
205
 
204
- case 12:
205
- return _context3.abrupt("break", 22);
206
+ case 10:
207
+ case "end":
208
+ return _context3.stop();
209
+ }
210
+ }, _callee3, null, [[1, 6]]);
211
+ }));
206
212
 
207
- case 13:
208
- _context3.prev = 13;
209
- return _context3.abrupt("return", updateDocumentPermissions(file, WRITE_PERMS));
213
+ return function createPermissions(_x3) {
214
+ return _ref6.apply(this, arguments);
215
+ };
216
+ }();
217
+ /**
218
+ * updatePermissions - Updates the permissions of a file
219
+ * @param {object} options
220
+ * @param {import('cozy-client/types/types').IOCozyFile} options.file File to update permissions
221
+ * @param {Function} options.t i18n function
222
+ * @param {boolean} options.dateToggle - Expiration date toggle
223
+ * @param {Date|null} options.selectedDate - Expiration date
224
+ * @param {boolean} options.passwordToggle - Password toggle
225
+ * @param {string} options.password - Password
226
+ * @param {string} options.documentType - Type of the document
227
+ * @param {'readOnly'|'write'} options.editingRights - Editing rights
228
+ * @param {Function} options.updateDocumentPermissions - Function to update permissions
229
+ * @param {Function} options.showAlert - Function to display an alert
230
+ */
231
+
232
+ export var updatePermissions = /*#__PURE__*/function () {
233
+ var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(_ref7) {
234
+ var file, t, dateToggle, selectedDate, passwordToggle, password, editingRights, documentType, updateDocumentPermissions, showAlert, expiresAt, ensurePassword, verbs;
235
+ return _regeneratorRuntime.wrap(function _callee4$(_context4) {
236
+ while (1) switch (_context4.prev = _context4.next) {
237
+ case 0:
238
+ file = _ref7.file, t = _ref7.t, dateToggle = _ref7.dateToggle, selectedDate = _ref7.selectedDate, passwordToggle = _ref7.passwordToggle, password = _ref7.password, editingRights = _ref7.editingRights, documentType = _ref7.documentType, updateDocumentPermissions = _ref7.updateDocumentPermissions, showAlert = _ref7.showAlert;
239
+ _context4.prev = 1;
240
+ expiresAt = dateToggle ? (selectedDate === null || selectedDate === void 0 ? void 0 : selectedDate.toISOString()) || undefined : '';
241
+ ensurePassword = passwordToggle ? password || undefined : '';
242
+ verbs = editingRights === 'readOnly' ? READ_ONLY_PERMS : WRITE_PERMS;
243
+ return _context4.abrupt("return", updateDocumentPermissions(file, {
244
+ verbs: verbs,
245
+ expiresAt: expiresAt,
246
+ password: ensurePassword
247
+ }));
210
248
 
211
- case 17:
212
- _context3.prev = 17;
213
- _context3.t2 = _context3["catch"](13);
249
+ case 8:
250
+ _context4.prev = 8;
251
+ _context4.t0 = _context4["catch"](1);
214
252
  showAlert({
215
253
  message: t("".concat(documentType, ".share.shareByLink.permserror")),
216
254
  severity: 'error',
217
255
  variant: 'filled'
218
256
  });
219
- log.error("Error in 'editPermissionLink' function when trying to change permission", _context3.t2);
257
+ log.error("Error in 'updateDocumentPermissions' function when trying to change permission", _context4.t0);
220
258
 
221
- case 21:
222
- return _context3.abrupt("break", 22);
223
-
224
- case 22:
259
+ case 12:
225
260
  case "end":
226
- return _context3.stop();
261
+ return _context4.stop();
227
262
  }
228
- }, _callee3, null, [[4, 8], [13, 17]]);
263
+ }, _callee4, null, [[1, 8]]);
229
264
  }));
230
265
 
231
- return function updatePermissions(_x3) {
232
- return _ref6.apply(this, arguments);
266
+ return function updatePermissions(_x4) {
267
+ return _ref8.apply(this, arguments);
233
268
  };
234
269
  }();
235
270
  /**
@@ -243,33 +278,33 @@ export var updatePermissions = /*#__PURE__*/function () {
243
278
  */
244
279
 
245
280
  export var revokePermissions = /*#__PURE__*/function () {
246
- var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(_ref7) {
281
+ var _ref10 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(_ref9) {
247
282
  var file, t, documentType, revokeSharingLink, showAlert;
248
- return _regeneratorRuntime.wrap(function _callee4$(_context4) {
249
- while (1) switch (_context4.prev = _context4.next) {
283
+ return _regeneratorRuntime.wrap(function _callee5$(_context5) {
284
+ while (1) switch (_context5.prev = _context5.next) {
250
285
  case 0:
251
- file = _ref7.file, t = _ref7.t, documentType = _ref7.documentType, revokeSharingLink = _ref7.revokeSharingLink, showAlert = _ref7.showAlert;
252
- _context4.prev = 1;
253
- return _context4.abrupt("return", revokeSharingLink(file));
286
+ file = _ref9.file, t = _ref9.t, documentType = _ref9.documentType, revokeSharingLink = _ref9.revokeSharingLink, showAlert = _ref9.showAlert;
287
+ _context5.prev = 1;
288
+ return _context5.abrupt("return", revokeSharingLink(file));
254
289
 
255
290
  case 5:
256
- _context4.prev = 5;
257
- _context4.t0 = _context4["catch"](1);
291
+ _context5.prev = 5;
292
+ _context5.t0 = _context5["catch"](1);
258
293
  showAlert({
259
294
  message: t("".concat(documentType, ".share.error.revoke")),
260
295
  severity: 'error',
261
296
  variant: 'filled'
262
297
  });
263
- log.error("Error in 'revokePermissions' function when trying to revoke sharing link", _context4.t0);
298
+ log.error("Error in 'revokePermissions' function when trying to revoke sharing link", _context5.t0);
264
299
 
265
300
  case 9:
266
301
  case "end":
267
- return _context4.stop();
302
+ return _context5.stop();
268
303
  }
269
- }, _callee4, null, [[1, 5]]);
304
+ }, _callee5, null, [[1, 5]]);
270
305
  }));
271
306
 
272
- return function revokePermissions(_x4) {
273
- return _ref8.apply(this, arguments);
307
+ return function revokePermissions(_x5) {
308
+ return _ref10.apply(this, arguments);
274
309
  };
275
310
  }();
@@ -19,7 +19,7 @@ describe('ShareRestrictionModal/helpers', function () {
19
19
  describe('updatePermissions', function () {
20
20
  var documentType = 'Files';
21
21
  it('should call updateDocumentPermissions with "readOnly" permission', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
22
- var updateDocumentPermissions, file, editingRights;
22
+ var updateDocumentPermissions, file;
23
23
  return _regeneratorRuntime.wrap(function _callee$(_context) {
24
24
  while (1) switch (_context.prev = _context.next) {
25
25
  case 0:
@@ -27,28 +27,35 @@ describe('ShareRestrictionModal/helpers', function () {
27
27
  file = {
28
28
  _id: '123'
29
29
  };
30
- editingRights = 'readOnly';
31
- _context.next = 5;
30
+ _context.next = 4;
32
31
  return updatePermissions({
33
32
  file: file,
34
33
  t: jest.fn(),
35
- editingRights: editingRights,
34
+ dateToggle: false,
35
+ selectedDate: null,
36
+ passwordToggle: false,
37
+ password: '',
38
+ editingRights: 'readOnly',
36
39
  documentType: documentType,
37
40
  updateDocumentPermissions: updateDocumentPermissions,
38
41
  showAlert: jest.fn()
39
42
  });
40
43
 
41
- case 5:
42
- expect(updateDocumentPermissions).toHaveBeenCalledWith(file, ['GET']);
44
+ case 4:
45
+ expect(updateDocumentPermissions).toHaveBeenCalledWith(file, {
46
+ expiresAt: '',
47
+ password: '',
48
+ verbs: ['GET']
49
+ });
43
50
 
44
- case 6:
51
+ case 5:
45
52
  case "end":
46
53
  return _context.stop();
47
54
  }
48
55
  }, _callee);
49
56
  })));
50
57
  it('should call updateDocumentPermissions with "write" permissions', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
51
- var updateDocumentPermissions, file, editingRights;
58
+ var updateDocumentPermissions, file;
52
59
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
53
60
  while (1) switch (_context2.prev = _context2.next) {
54
61
  case 0:
@@ -56,39 +63,154 @@ describe('ShareRestrictionModal/helpers', function () {
56
63
  file = {
57
64
  _id: '123'
58
65
  };
59
- editingRights = 'write';
60
- _context2.next = 5;
66
+ _context2.next = 4;
61
67
  return updatePermissions({
62
68
  file: file,
63
69
  t: jest.fn(),
64
- editingRights: editingRights,
70
+ dateToggle: false,
71
+ selectedDate: null,
72
+ passwordToggle: false,
73
+ password: '',
74
+ editingRights: 'write',
65
75
  documentType: documentType,
66
76
  updateDocumentPermissions: updateDocumentPermissions,
67
77
  showAlert: jest.fn()
68
78
  });
69
79
 
70
- case 5:
71
- expect(updateDocumentPermissions).toHaveBeenCalledWith(file, ['GET', 'POST', 'PUT', 'PATCH']);
80
+ case 4:
81
+ expect(updateDocumentPermissions).toHaveBeenCalledWith(file, {
82
+ expiresAt: '',
83
+ password: '',
84
+ verbs: ['GET', 'POST', 'PUT', 'PATCH']
85
+ });
72
86
 
73
- case 6:
87
+ case 5:
74
88
  case "end":
75
89
  return _context2.stop();
76
90
  }
77
91
  }, _callee2);
78
92
  })));
93
+ it('should call updateDocumentPermissions with empty date & password if their switches are false', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
94
+ var updateDocumentPermissions, file;
95
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
96
+ while (1) switch (_context3.prev = _context3.next) {
97
+ case 0:
98
+ updateDocumentPermissions = jest.fn();
99
+ file = {
100
+ _id: '123'
101
+ };
102
+ _context3.next = 4;
103
+ return updatePermissions({
104
+ file: file,
105
+ t: jest.fn(),
106
+ dateToggle: false,
107
+ selectedDate: null,
108
+ passwordToggle: false,
109
+ password: '',
110
+ editingRights: 'readOnly',
111
+ documentType: documentType,
112
+ updateDocumentPermissions: updateDocumentPermissions,
113
+ showAlert: jest.fn()
114
+ });
115
+
116
+ case 4:
117
+ expect(updateDocumentPermissions).toHaveBeenCalledWith(file, {
118
+ expiresAt: '',
119
+ password: '',
120
+ verbs: ['GET']
121
+ });
122
+
123
+ case 5:
124
+ case "end":
125
+ return _context3.stop();
126
+ }
127
+ }, _callee3);
128
+ })));
129
+ it('should call updateDocumentPermissions with "undefined" date & password if their switches are true but the permission doesn\'t yet have these values', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
130
+ var updateDocumentPermissions, file;
131
+ return _regeneratorRuntime.wrap(function _callee4$(_context4) {
132
+ while (1) switch (_context4.prev = _context4.next) {
133
+ case 0:
134
+ updateDocumentPermissions = jest.fn();
135
+ file = {
136
+ _id: '123'
137
+ };
138
+ _context4.next = 4;
139
+ return updatePermissions({
140
+ file: file,
141
+ t: jest.fn(),
142
+ dateToggle: true,
143
+ selectedDate: null,
144
+ passwordToggle: true,
145
+ password: '',
146
+ editingRights: 'readOnly',
147
+ documentType: documentType,
148
+ updateDocumentPermissions: updateDocumentPermissions,
149
+ showAlert: jest.fn()
150
+ });
151
+
152
+ case 4:
153
+ expect(updateDocumentPermissions).toHaveBeenCalledWith(file, {
154
+ expiresAt: undefined,
155
+ password: undefined,
156
+ verbs: ['GET']
157
+ });
158
+
159
+ case 5:
160
+ case "end":
161
+ return _context4.stop();
162
+ }
163
+ }, _callee4);
164
+ })));
165
+ it('should call updateDocumentPermissions with expected date & password if their switches are true', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
166
+ var updateDocumentPermissions, file;
167
+ return _regeneratorRuntime.wrap(function _callee5$(_context5) {
168
+ while (1) switch (_context5.prev = _context5.next) {
169
+ case 0:
170
+ updateDocumentPermissions = jest.fn();
171
+ file = {
172
+ _id: '123'
173
+ };
174
+ _context5.next = 4;
175
+ return updatePermissions({
176
+ file: file,
177
+ t: jest.fn(),
178
+ dateToggle: true,
179
+ selectedDate: new Date('2100-01-01T00:00:00.000Z'),
180
+ passwordToggle: true,
181
+ password: '1234',
182
+ editingRights: 'readOnly',
183
+ documentType: documentType,
184
+ updateDocumentPermissions: updateDocumentPermissions,
185
+ showAlert: jest.fn()
186
+ });
187
+
188
+ case 4:
189
+ expect(updateDocumentPermissions).toHaveBeenCalledWith(file, {
190
+ expiresAt: '2100-01-01T00:00:00.000Z',
191
+ password: '1234',
192
+ verbs: ['GET']
193
+ });
194
+
195
+ case 5:
196
+ case "end":
197
+ return _context5.stop();
198
+ }
199
+ }, _callee5);
200
+ })));
79
201
  });
80
202
  describe('revokePermissions', function () {
81
203
  var documentType = 'Files';
82
- it('should call revokeSharingLink', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
204
+ it('should call revokeSharingLink', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
83
205
  var revokeSharingLink, file;
84
- return _regeneratorRuntime.wrap(function _callee3$(_context3) {
85
- while (1) switch (_context3.prev = _context3.next) {
206
+ return _regeneratorRuntime.wrap(function _callee6$(_context6) {
207
+ while (1) switch (_context6.prev = _context6.next) {
86
208
  case 0:
87
209
  revokeSharingLink = jest.fn();
88
210
  file = {
89
211
  _id: '123'
90
212
  };
91
- _context3.next = 4;
213
+ _context6.next = 4;
92
214
  return revokePermissions({
93
215
  file: file,
94
216
  t: jest.fn(),
@@ -102,9 +224,9 @@ describe('ShareRestrictionModal/helpers', function () {
102
224
 
103
225
  case 5:
104
226
  case "end":
105
- return _context3.stop();
227
+ return _context6.stop();
106
228
  }
107
- }, _callee3);
229
+ }, _callee6);
108
230
  })));
109
231
  });
110
232
  });
@@ -5,4 +5,19 @@ export var checkIsReadOnlyPermissions = function checkIsReadOnlyPermissions(perm
5
5
  return Object.values(permissionCategories).filter(function (permissionCategory) {
6
6
  return models.permission.isReadOnly(permissionCategory);
7
7
  }).length > 0;
8
+ };
9
+ export var checkIsPermissionHasExpiresDate = function checkIsPermissionHasExpiresDate(permissions) {
10
+ var _permissions$;
11
+
12
+ return Boolean(permissions === null || permissions === void 0 || (_permissions$ = permissions[0]) === null || _permissions$ === void 0 || (_permissions$ = _permissions$.attributes) === null || _permissions$ === void 0 ? void 0 : _permissions$.expires_at);
13
+ };
14
+ export var getPermissionExpiresDate = function getPermissionExpiresDate(permissions) {
15
+ var _permissions$2;
16
+
17
+ return permissions === null || permissions === void 0 || (_permissions$2 = permissions[0]) === null || _permissions$2 === void 0 || (_permissions$2 = _permissions$2.attributes) === null || _permissions$2 === void 0 ? void 0 : _permissions$2.expires_at;
18
+ };
19
+ export var checkIsPermissionHasPassword = function checkIsPermissionHasPassword(permissions) {
20
+ var _permissions$3;
21
+
22
+ return Boolean(permissions === null || permissions === void 0 || (_permissions$3 = permissions[0]) === null || _permissions$3 === void 0 || (_permissions$3 = _permissions$3.attributes) === null || _permissions$3 === void 0 ? void 0 : _permissions$3.password);
8
23
  };
package/locales/en.json CHANGED
@@ -26,6 +26,8 @@
26
26
  "recipients": {
27
27
  "you": "You",
28
28
  "anyoneWithTheLink": "Anyone with the link",
29
+ "linkWithPassword": "Anyone with a password",
30
+ "expires": "Until %{date}",
29
31
  "accessCount": "%{count} people have access"
30
32
  },
31
33
  "create-cozy": "Create |||| Create my cozy",
package/locales/fr.json CHANGED
@@ -26,6 +26,8 @@
26
26
  "recipients": {
27
27
  "you": "Vous",
28
28
  "anyoneWithTheLink": "N'importe qui avec le lien",
29
+ "linkWithPassword": "N'importe qui avec un mot de passe",
30
+ "expires": "Jusqu'au %{date}",
29
31
  "accessCount": "%{count} personnes y ont accès"
30
32
  },
31
33
  "create-cozy": "Créer |||| Créer mon Cozy",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-sharing",
3
- "version": "19.0.0",
3
+ "version": "20.0.0",
4
4
  "description": "Provides sharing login for React applications.",
5
5
  "main": "dist/index.js",
6
6
  "author": "Cozy",
@@ -53,7 +53,7 @@
53
53
  "babel-jest": "26.6.3",
54
54
  "babel-plugin-css-modules-transform": "1.6.2",
55
55
  "babel-plugin-inline-react-svg": "1.1.2",
56
- "cozy-client": "^52.1.0",
56
+ "cozy-client": "^53.0.0",
57
57
  "cozy-device-helper": "^3.7.1",
58
58
  "cozy-intent": "^2.29.1",
59
59
  "cozy-minilog": "^3.9.1",
@@ -66,7 +66,7 @@
66
66
  "storybook": "7.6.0"
67
67
  },
68
68
  "peerDependencies": {
69
- "cozy-client": ">=52.1.0",
69
+ "cozy-client": ">=53.0.0",
70
70
  "cozy-device-helper": ">=3.7.1",
71
71
  "cozy-intent": ">=2.29.1",
72
72
  "cozy-minilog": ">=3.9.1",
@@ -78,5 +78,5 @@
78
78
  "sideEffects": [
79
79
  "*.css"
80
80
  ],
81
- "gitHead": "74889d160e15166c4aa132e4fc8c77ebe95c62ae"
81
+ "gitHead": "7dbd527d95ca869695120926125905fdcc2413b0"
82
82
  }
@@ -331,25 +331,30 @@ export class SharingProvider extends Component {
331
331
  * updateDocumentPermissions - Description
332
332
  *
333
333
  * @param {Object} document A shared document
334
- * @param {Array} newVerbs The new verbs to use for the permission, eg. ['GET']
334
+ * @param {object} options The new verbs to use for the permission, eg. ['GET']
335
+ * @param {string[]} options.verbs The new verbs to use for the permission, eg. ['GET']
336
+ * @param {string} [options.expiresAt] The new expiration date for the permission
337
+ * @param {string} [options.password] The new password for the permission
335
338
  *
336
339
  * @return {Array}
337
340
  */
338
- updateDocumentPermissions = async (document, newVerbs) => {
341
+ updateDocumentPermissions = async (document, options) => {
342
+ const { verbs, expiresAt, password } = options
339
343
  const permissions = getDocumentPermissions(this.state, document.id)
340
344
 
341
345
  const responses = await Promise.all(
342
346
  permissions.map(async permissionDocument => {
343
347
  const updatedPermissions = permissionDocument.attributes.permissions
344
348
  Object.keys(updatedPermissions).map(permType => {
345
- updatedPermissions[permType].verbs = newVerbs
349
+ updatedPermissions[permType].verbs = verbs
346
350
  })
347
351
 
348
352
  const resp = await this.permissionCol.add(
349
353
  permissionDocument,
350
- updatedPermissions
354
+ updatedPermissions,
355
+ { expiresAt, password }
351
356
  )
352
- this.dispatch(updateSharingLink(resp))
357
+ this.dispatch(updateSharingLink(resp.data))
353
358
  return resp
354
359
  })
355
360
  )
@@ -14,14 +14,38 @@ import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n'
14
14
 
15
15
  import LinkRecipientPermissions from './LinkRecipientPermissions'
16
16
  import RecipientConfirm from './RecipientConfirm'
17
+ import {
18
+ checkIsPermissionHasPassword,
19
+ getPermissionExpiresDate
20
+ } from '../../helpers/permissions'
17
21
  import { FADE_IN_DURATION } from '../../helpers/recipients'
22
+ import { useSharingContext } from '../../hooks/useSharingContext'
18
23
  import styles from '../../styles/recipient.styl'
19
24
 
20
25
  const LinkRecipient = props => {
21
- const { t } = useI18n()
26
+ const { t, f, lang } = useI18n()
22
27
  const { isMobile } = useBreakpoints()
28
+ const { getDocumentPermissions } = useSharingContext()
23
29
 
24
- const { recipientConfirmationData, verifyRecipient, link, fadeIn } = props
30
+ const { recipientConfirmationData, verifyRecipient, link, fadeIn, document } =
31
+ props
32
+
33
+ const permissions = getDocumentPermissions(document._id)
34
+ const hasPassword = checkIsPermissionHasPassword(permissions)
35
+ const expiresDate = getPermissionExpiresDate(permissions)
36
+ const dateFormatted = expiresDate
37
+ ? f(expiresDate, lang === 'fr' ? 'dd/LL/yyyy' : 'LL/dd/yyyy')
38
+ : null
39
+
40
+ const textPrimary = hasPassword
41
+ ? t('Share.recipients.linkWithPassword')
42
+ : t('Share.recipients.anyoneWithTheLink')
43
+
44
+ const textSecondary = expiresDate
45
+ ? t('Share.recipients.expires', {
46
+ date: dateFormatted
47
+ })
48
+ : link
25
49
 
26
50
  const RightPart = recipientConfirmationData ? (
27
51
  <RecipientConfirm
@@ -43,10 +67,10 @@ const LinkRecipient = props => {
43
67
  <ListItemText
44
68
  primary={
45
69
  <Typography className="u-ellipsis" variant="body1">
46
- {t('Share.recipients.anyoneWithTheLink')}
70
+ {textPrimary}
47
71
  </Typography>
48
72
  }
49
- secondary={link}
73
+ secondary={textSecondary}
50
74
  />
51
75
  {RightPart}
52
76
  </ListItem>
@@ -15,8 +15,11 @@ import { useAlert } from 'cozy-ui/transpiled/react/providers/Alert'
15
15
  import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n'
16
16
 
17
17
  import { copyToClipboard } from './helpers'
18
+ import { checkIsPermissionHasPassword } from '../../helpers/permissions'
19
+ import { useSharingContext } from '../../hooks/useSharingContext'
18
20
 
19
21
  export const BoxPassword = ({
22
+ file,
20
23
  onChange,
21
24
  password,
22
25
  onToggle,
@@ -28,6 +31,10 @@ export const BoxPassword = ({
28
31
  const { showAlert } = useAlert()
29
32
  const [displayHelper, setDisplayHelper] = useState(false)
30
33
  const inputRef = React.useRef()
34
+ const { getDocumentPermissions } = useSharingContext()
35
+
36
+ const permissions = getDocumentPermissions(file._id)
37
+ const hasPassword = checkIsPermissionHasPassword(permissions)
31
38
 
32
39
  const handlePasswordToggle = val => {
33
40
  const value = val?.target?.checked ?? val
@@ -77,7 +84,14 @@ export const BoxPassword = ({
77
84
  <div className="u-pt-half u-ph-1 u-pb-1">
78
85
  <TextField
79
86
  inputRef={inputRef}
87
+ autoFocus
80
88
  label={t('BoxPassword.label')}
89
+ {...(hasPassword && {
90
+ placeholder: '****',
91
+ InputLabelProps: {
92
+ shrink: true
93
+ }
94
+ })}
81
95
  value={password}
82
96
  error={displayHelper && !!helperText}
83
97
  helperText={displayHelper && helperText}