summaryrefslogtreecommitdiffstats
path: root/src/models/constants.ts
blob: d115b8290023a685c6db01f88f3049b70f5f6764 (plain)
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/**
 * @copyright Copyright (c) 2021 John Molakvoæ <skjnldsv@protonmail.com>
 *
 * @author John Molakvoæ <skjnldsv@protonmail.com>
 *
 * @license GNU AGPL version 3 or any later version
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 */
/// <reference types="@nextcloud/typings" />

import { translate as t } from '@nextcloud/l10n'
import { Type } from '@nextcloud/sharing'

export type DefaultGroup = string
export type DefaultChart = string
export type CircleConfig = number
export type MemberLevel = number
export type MemberType = number

// Global sizes
export const LIST_SIZE = 60

// Dynamic default groups
export const GROUP_ALL_CONTACTS: DefaultGroup = t('contacts', 'All contacts')
export const GROUP_NO_GROUP_CONTACTS: DefaultGroup = t('contacts', 'Not grouped')
export const GROUP_RECENTLY_CONTACTED: DefaultGroup = t('contactsinteraction', 'Recently contacted')

// Organization default chart for all contacts
export const CHART_ALL_CONTACTS: DefaultChart = t('contacts', 'Organization chart')

// Circle route, see vue-router conf
export const ROUTE_CIRCLE = 'circle'
export const ROUTE_CHART = 'chart'

//Contact settings
export const CONTACTS_SETTINGS: DefaultGroup = t('contacts', 'Contacts settings')

// Default max number of items to show in the navigation
export const ELLIPSIS_COUNT = 5

// Circles member levels
const MEMBER_LEVEL_NONE: MemberLevel = 0
const MEMBER_LEVEL_MEMBER: MemberLevel = 1
const MEMBER_LEVEL_MODERATOR: MemberLevel = 4
const MEMBER_LEVEL_ADMIN: MemberLevel = 8
const MEMBER_LEVEL_OWNER: MemberLevel = 9

// Circles member types
const MEMBER_TYPE_SINGLEID: MemberType = 0
const MEMBER_TYPE_USER: MemberType = 1
const MEMBER_TYPE_GROUP : MemberType= 2
const MEMBER_TYPE_MAIL: MemberType = 4
const MEMBER_TYPE_CONTACT: MemberType = 8
const MEMBER_TYPE_CIRCLE: MemberType = 16

export const CIRCLE_DESC = t('contacts', 'Circles are groups of people that you can create yourself and with whom you can share data. They can be made up of other accounts or groups of accounts of the Nextcloud instance, but also of contacts from your address book or even external people by simply entering their e-mail addresses.')

// Circles config flags
const CIRCLE_CONFIG_PERSONAL: CircleConfig = 2				// Personal circle, only the owner can see it.
const CIRCLE_CONFIG_SYSTEM: CircleConfig = 4				// System Circle (not managed by the official front-end). Meaning some config are limited
const CIRCLE_CONFIG_VISIBLE: CircleConfig = 8				// Visible to everyone, if not visible, people have to know its name to be able to find it
const CIRCLE_CONFIG_OPEN: CircleConfig = 16					// Circle is open, people can join
const CIRCLE_CONFIG_INVITE: CircleConfig = 32				// Adding a member generate an invitation that needs to be accepted
const CIRCLE_CONFIG_REQUEST: CircleConfig = 64				// Request to join Circles needs to be confirmed by a moderator
const CIRCLE_CONFIG_FRIEND: CircleConfig = 128				// Members of the circle can invite their friends
const CIRCLE_CONFIG_PROTECTED: CircleConfig = 256			// Password protected to join/request
const CIRCLE_CONFIG_NO_OWNER: CircleConfig = 512			// no owner, only members
const CIRCLE_CONFIG_HIDDEN: CircleConfig = 1024				// hidden from listing, but available as a share entity
const CIRCLE_CONFIG_BACKEND: CircleConfig = 2048			// Fully hidden, only backend Circles
const CIRCLE_CONFIG_LOCAL: CircleConfig = 4096				// Circle is not shared to other instance in globalscale
const CIRCLE_CONFIG_ROOT: CircleConfig = 8192				// Circle cannot be a member of another Circle
const CIRCLE_CONFIG_CIRCLE_INVITE: CircleConfig = 16384		// Circle must confirm when invited in another circle
const CIRCLE_CONFIG_FEDERATED: CircleConfig = 32768			// Federated

// Existing members types
export const CIRCLES_MEMBER_TYPES = {
	[MEMBER_TYPE_CIRCLE]: t('circles', 'Circle'),
	[MEMBER_TYPE_USER]: t('circles', 'User'),
	[MEMBER_TYPE_GROUP]: t('circles', 'Group'),
	[MEMBER_TYPE_MAIL]: t('circles', 'Email'),
	[MEMBER_TYPE_CONTACT]: t('circles', 'Contact'),
}

// Available circles promote/demote levels
export const CIRCLES_MEMBER_LEVELS = {
	// [MEMBER_LEVEL_NONE]: t('circles', 'Pending'),
	[MEMBER_LEVEL_MEMBER]: t('circles', 'Member'),
	[MEMBER_LEVEL_MODERATOR]: t('circles', 'Moderator'),
	[MEMBER_LEVEL_ADMIN]: t('circles', 'Admin'),
	[MEMBER_LEVEL_OWNER]: t('circles', 'Owner'),
}

// Available circle configs in the circle details view
export const PUBLIC_CIRCLE_CONFIG = {
	[t('contacts', 'Invites')]: {
		[CIRCLE_CONFIG_OPEN]: t('contacts', 'Anyone can request membership'),
		[CIRCLE_CONFIG_INVITE]: t('contacts', 'Members need to accept invitation'),
		[CIRCLE_CONFIG_REQUEST]: t('contacts', 'Memberships must be confirmed/accepted by a Moderator (requires Open)'),
		[CIRCLE_CONFIG_FRIEND]: t('contacts', 'Members can also invite'),
		// Let's manage password protection independently as we also need a password
		// [CIRCLE_CONFIG_PROTECTED]: t('contacts', 'Password protect'),
	},

	[t('contacts', 'Visibility')]: {
		[CIRCLE_CONFIG_VISIBLE]: t('contacts', 'Visible to everyone'),
	},

	[t('contacts', 'Circle membership')]: {
		// TODO: implement backend
		// [CIRCLE_CONFIG_CIRCLE_INVITE]: t('contacts', 'Circle must confirm when invited in another circle'),
		[CIRCLE_CONFIG_ROOT]: t('contacts', 'Prevent circle from being a member of another circle'),
	},
}


// Represents the picker options but also the
// sorting of the members list
export const CIRCLES_MEMBER_GROUPING = [
	{
		id: `picker-${Type.SHARE_TYPE_USER}`,
		label: t('contacts', 'Users'),
		share: Type.SHARE_TYPE_USER,
		type: MEMBER_TYPE_USER
	},
	{
		id: `picker-${Type.SHARE_TYPE_GROUP}`,
		label: t('contacts', 'User groups'),
		share: Type.SHARE_TYPE_GROUP,
		type: MEMBER_TYPE_GROUP
	},
	// TODO: implement federated
	// {
	// 	id: `picker-${Type.SHARE_TYPE_REMOTE}`,
	// 	label: t('contacts', 'Federated users'),
	// 	share: Type.SHARE_TYPE_REMOTE,
	// 	type: MEMBER_TYPE_USER
	// },
	// {
	// 	id: `picker-${Type.SHARE_TYPE_REMOTE_GROUP}`,
	// 	label: t('contacts', 'Federated groups'),
	// 	share: Type.SHARE_TYPE_REMOTE_GROUP,
	// 	type: MEMBER_TYPE_GROUP
	// },
	{
		id: `picker-${Type.SHARE_TYPE_CIRCLE}`,
		label: t('contacts', 'Circles'),
		share: Type.SHARE_TYPE_CIRCLE,
		type: MEMBER_TYPE_CIRCLE
	},
	{
		id: `picker-${Type.SHARE_TYPE_EMAIL}`,
		label: t('contacts', 'Email addresses'),
		share: Type.SHARE_TYPE_EMAIL,
		type: MEMBER_TYPE_MAIL
	},
	// TODO: implement SHARE_TYPE_CONTACT
	{
		id: `picker-contact`,
		label: t('contacts', 'Contacts'),
		share: Type.SHARE_TYPE_EMAIL,
		type: MEMBER_TYPE_CONTACT
	},
]

// Generating a map between share types and circle member types
export const SHARES_TYPES_MEMBER_MAP = CIRCLES_MEMBER_GROUPING.reduce((list, entry) => {
	// ! Ignore duplicate share types
	if (!list[entry.share]) {
		list[entry.share] = entry.type
	}
	return list
}, {})

export enum MemberLevels {
	NONE = MEMBER_LEVEL_NONE,
	MEMBER = MEMBER_LEVEL_MEMBER,
	MODERATOR = MEMBER_LEVEL_MODERATOR,
	ADMIN = MEMBER_LEVEL_ADMIN,
	OWNER = MEMBER_LEVEL_OWNER,
}

export enum MemberTypes {
	CIRCLE = MEMBER_TYPE_CIRCLE,
	USER = MEMBER_TYPE_USER,
	GROUP = MEMBER_TYPE_GROUP,
	MAIL = MEMBER_TYPE_MAIL,
	CONTACT = MEMBER_TYPE_CONTACT,
}

export enum CircleConfigs {
	PERSONAL = CIRCLE_CONFIG_PERSONAL,
	SYSTEM = CIRCLE_CONFIG_SYSTEM,
	VISIBLE = CIRCLE_CONFIG_VISIBLE,
	OPEN = CIRCLE_CONFIG_OPEN,
	INVITE = CIRCLE_CONFIG_INVITE,
	REQUEST = CIRCLE_CONFIG_REQUEST,
	FRIEND = CIRCLE_CONFIG_FRIEND,
	PROTECTED = CIRCLE_CONFIG_PROTECTED,
	NO_OWNER = CIRCLE_CONFIG_NO_OWNER,
	HIDDEN = CIRCLE_CONFIG_HIDDEN,
	BACKEND = CIRCLE_CONFIG_BACKEND,
	LOCAL = CIRCLE_CONFIG_LOCAL,
	ROOT = CIRCLE_CONFIG_ROOT,
	CIRCLE_INVITE = CIRCLE_CONFIG_CIRCLE_INVITE,
	FEDERATED = CIRCLE_CONFIG_FEDERATED,
}

export enum MemberStatus {
	INVITED = 'Invited',
	MEMBER = 'Member',
	REQUESTING = 'Requesting',
}