Welcome to mirror list, hosted at ThFree Co, Russian Federation.

FederationControl.vue « EmailSection « PersonalInfo « components « src « settings « apps - github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6d48c157d6bdd17486a15872b0ac32e54c6e61e9 (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
<!--
	- @copyright 2021, Christopher Ng <chrng8@gmail.com>
	-
	- @author Christopher Ng <chrng8@gmail.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/>.
-->

<template>
	<Actions
		class="actions-federation"
		:aria-label="t('settings', 'Change privacy level of email')"
		:default-icon="scopeIcon"
		:disabled="disabled">
		<ActionButton v-for="federationScope in federationScopes"
			:key="federationScope.name"
			class="forced-action"
			:class="{ 'forced-active': scope === federationScope.name }"
			:aria-label="federationScope.tooltip"
			:close-after-click="true"
			:icon="federationScope.iconClass"
			:title="federationScope.displayName"
			@click.stop.prevent="changeScope(federationScope.name)">
			{{ federationScope.tooltip }}
		</ActionButton>
	</Actions>
</template>

<script>
import Actions from '@nextcloud/vue/dist/Components/Actions'
import ActionButton from '@nextcloud/vue/dist/Components/ActionButton'
import { loadState } from '@nextcloud/initial-state'
import { showError } from '@nextcloud/dialogs'

import { SCOPE_ENUM, SCOPE_PROPERTY_ENUM } from '../../../constants/AccountPropertyConstants'
import { savePrimaryEmailScope, saveAdditionalEmailScope } from '../../../service/PersonalInfoService'

const { lookupServerUploadEnabled } = loadState('settings', 'accountParameters', {})

// TODO hardcoded for email, should abstract this for other sections
const excludedScopes = [SCOPE_ENUM.PRIVATE]

export default {
	name: 'FederationControl',

	components: {
		Actions,
		ActionButton,
	},

	props: {
		primary: {
			type: Boolean,
			default: false,
		},
		email: {
			type: String,
			default: '',
		},
		scope: {
			type: String,
			required: true,
		},
		disabled: {
			type: Boolean,
			default: false,
		},
	},

	data() {
		return {
			initialScope: this.scope,
		}
	},

	computed: {
		federationScopes() {
			return Object.values(SCOPE_PROPERTY_ENUM).filter(({ name }) => !this.unsupportedScopes.includes(name))
		},

		unsupportedScopes() {
			if (!lookupServerUploadEnabled) {
				return [
					...excludedScopes,
					SCOPE_ENUM.FEDERATED,
					SCOPE_ENUM.PUBLISHED,
				]
			}

			return excludedScopes
		},

		scopeIcon() {
			return SCOPE_PROPERTY_ENUM[this.scope].iconClass
		},
	},

	methods: {
		async changeScope(scope) {
			this.$emit('update:scope', scope)

			this.$nextTick(async() => {
				if (this.primary) {
					await this.updatePrimaryEmailScope()
				} else {
					await this.updateAdditionalEmailScope()
				}
			})
		},

		async updatePrimaryEmailScope() {
			try {
				const responseData = await savePrimaryEmailScope(this.scope)
				this.handleResponse(responseData.ocs?.meta?.status)
			} catch (e) {
				this.handleResponse('error', 'Unable to update federation scope of the primary email', e)
			}
		},

		async updateAdditionalEmailScope() {
			try {
				const responseData = await saveAdditionalEmailScope(this.email, this.scope)
				this.handleResponse(responseData.ocs?.meta?.status)
			} catch (e) {
				this.handleResponse('error', 'Unable to update federation scope of additional email', e)
			}
		},

		handleResponse(status, errorMessage, error) {
			if (status === 'ok') {
				this.initialScope = this.scope
			} else {
				this.$emit('update:scope', this.initialScope)
				showError(t('settings', errorMessage))
				this.logger.error(errorMessage, error)
			}
		},
	},
}
</script>

<style lang="scss" scoped>
	.actions-federation {
		opacity: 0.4 !important;

		&:hover {
			opacity: 0.8 !important;
		}
	}

	.forced-active {
		background-color: var(--color-primary-light) !important;
		box-shadow: inset 2px 0 var(--color-primary) !important;
	}

	.forced-action {
		&::v-deep p {
			width: 150px !important;
			padding: 8px 0 !important;
			color: var(--color-main-text) !important;
			font-size: 12.8px !important;
			line-height: 1.5em !important;
		}
	}
</style>