1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* Helpers for permission checks and other ACL features
*/
// NOTE: This module should not be loaded directly, it is available when
// including calUtils.jsm under the cal.acl namespace.
const EXPORTED_SYMBOLS = ["calacl"];
var calacl = {
/**
* Check if the specified calendar is writable. This is the case when it is
* not marked readOnly, we are not offline, or we are offline and the
* calendar is local.
*
* @param aCalendar The calendar to check
* @returns True if the calendar is writable
*/
isCalendarWritable(aCalendar) {
return (
!aCalendar.getProperty("disabled") &&
!aCalendar.readOnly &&
(!Services.io.offline ||
aCalendar.getProperty("cache.enabled") ||
aCalendar.getProperty("cache.always") ||
aCalendar.getProperty("requiresNetwork") === false)
);
},
/**
* Check if the specified calendar is writable from an ACL point of view.
*
* @param aCalendar The calendar to check
* @returns True if the calendar is writable
*/
userCanAddItemsToCalendar(aCalendar) {
let aclEntry = aCalendar.aclEntry;
return (
!aclEntry || !aclEntry.hasAccessControl || aclEntry.userIsOwner || aclEntry.userCanAddItems
);
},
/**
* Check if the user can delete items from the specified calendar, from an
* ACL point of view.
*
* @param aCalendar The calendar to check
* @returns True if the calendar is writable
*/
userCanDeleteItemsFromCalendar(aCalendar) {
let aclEntry = aCalendar.aclEntry;
return (
!aclEntry || !aclEntry.hasAccessControl || aclEntry.userIsOwner || aclEntry.userCanDeleteItems
);
},
/**
* Check if the user can fully modify the specified item, from an ACL point
* of view. Note to be confused with the right to respond to an
* invitation, which is handled instead by userCanRespondToInvitation.
*
* @param aItem The calendar item to check
* @returns True if the item is modifiable
*/
userCanModifyItem(aItem) {
let aclEntry = aItem.aclEntry;
return (
!aclEntry ||
!aclEntry.calendarEntry.hasAccessControl ||
aclEntry.calendarEntry.userIsOwner ||
aclEntry.userCanModify
);
},
/**
* Checks if the user can modify the item and has the right to respond to
* invitations for the item.
*
* @param aItem The calendar item to check
* @returns True if the invitation w.r.t. the item can be
* responded to.
*/
userCanRespondToInvitation(aItem) {
let aclEntry = aItem.aclEntry;
// TODO check if || is really wanted here
return calacl.userCanModifyItem(aItem) || aclEntry.userCanRespond;
},
};
|