mirror of
https://github.com/nextcloud/server.git
synced 2026-04-25 16:19:06 -04:00
Create display name service and update constants
Signed-off-by: Christopher Ng <chrng8@gmail.com>
This commit is contained in:
parent
d4d59493a2
commit
db182d6517
3 changed files with 110 additions and 18 deletions
|
|
@ -26,24 +26,48 @@
|
|||
|
||||
/** Enum of account properties */
|
||||
export const ACCOUNT_PROPERTY_ENUM = Object.freeze({
|
||||
ADDRESS: 'address',
|
||||
AVATAR: 'avatar',
|
||||
DISPLAYNAME: 'displayname',
|
||||
PHONE: 'phone',
|
||||
EMAIL: 'email',
|
||||
WEBSITE: 'website',
|
||||
ADDRESS: 'address',
|
||||
TWITTER: 'twitter',
|
||||
EMAIL_COLLECTION: 'additional_mail',
|
||||
PHONE: 'phone',
|
||||
TWITTER: 'twitter',
|
||||
WEBSITE: 'website',
|
||||
})
|
||||
|
||||
/** Enum of account properties to human readable account properties */
|
||||
export const ACCOUNT_PROPERTY_READABLE_ENUM = Object.freeze({
|
||||
ADDRESS: 'Address',
|
||||
AVATAR: 'Avatar',
|
||||
DISPLAYNAME: 'Full name',
|
||||
EMAIL: 'Email',
|
||||
EMAIL_COLLECTION: 'Additional Email',
|
||||
PHONE: 'Phone',
|
||||
TWITTER: 'Twitter',
|
||||
WEBSITE: 'Website',
|
||||
})
|
||||
|
||||
/** Enum of scopes */
|
||||
export const SCOPE_ENUM = Object.freeze({
|
||||
PRIVATE: 'v2-private',
|
||||
LOCAL: 'v2-local',
|
||||
PRIVATE: 'v2-private',
|
||||
FEDERATED: 'v2-federated',
|
||||
PUBLISHED: 'v2-published',
|
||||
})
|
||||
|
||||
/** Enum of readable account properties to supported scopes */
|
||||
export const PROPERTY_READABLE_SUPPORTED_SCOPES_ENUM = Object.freeze({
|
||||
[ACCOUNT_PROPERTY_READABLE_ENUM.ADDRESS]: [SCOPE_ENUM.LOCAL, SCOPE_ENUM.PRIVATE],
|
||||
[ACCOUNT_PROPERTY_READABLE_ENUM.AVATAR]: [SCOPE_ENUM.LOCAL, SCOPE_ENUM.PRIVATE],
|
||||
[ACCOUNT_PROPERTY_READABLE_ENUM.DISPLAYNAME]: [SCOPE_ENUM.LOCAL],
|
||||
[ACCOUNT_PROPERTY_READABLE_ENUM.EMAIL]: [SCOPE_ENUM.LOCAL],
|
||||
[ACCOUNT_PROPERTY_READABLE_ENUM.EMAIL_COLLECTION]: [SCOPE_ENUM.LOCAL],
|
||||
[ACCOUNT_PROPERTY_READABLE_ENUM.PHONE]: [SCOPE_ENUM.LOCAL, SCOPE_ENUM.PRIVATE],
|
||||
[ACCOUNT_PROPERTY_READABLE_ENUM.TWITTER]: [SCOPE_ENUM.LOCAL, SCOPE_ENUM.PRIVATE],
|
||||
[ACCOUNT_PROPERTY_READABLE_ENUM.WEBSITE]: [SCOPE_ENUM.LOCAL, SCOPE_ENUM.PRIVATE],
|
||||
})
|
||||
|
||||
/** Scope suffix */
|
||||
export const SCOPE_SUFFIX = 'Scope'
|
||||
|
||||
|
|
@ -56,18 +80,18 @@ export const DEFAULT_ADDITIONAL_EMAIL_SCOPE = SCOPE_ENUM.LOCAL
|
|||
* *Used for federation control*
|
||||
*/
|
||||
export const SCOPE_PROPERTY_ENUM = Object.freeze({
|
||||
[SCOPE_ENUM.PRIVATE]: {
|
||||
name: SCOPE_ENUM.PRIVATE,
|
||||
displayName: t('settings', 'Private'),
|
||||
tooltip: t('settings', 'Only visible to people matched via phone number integration through Talk on mobile'),
|
||||
iconClass: 'icon-phone',
|
||||
},
|
||||
[SCOPE_ENUM.LOCAL]: {
|
||||
name: SCOPE_ENUM.LOCAL,
|
||||
displayName: t('settings', 'Local'),
|
||||
tooltip: t('settings', 'Only visible to people on this instance and guests'),
|
||||
iconClass: 'icon-password',
|
||||
},
|
||||
[SCOPE_ENUM.PRIVATE]: {
|
||||
name: SCOPE_ENUM.PRIVATE,
|
||||
displayName: t('settings', 'Private'),
|
||||
tooltip: t('settings', 'Only visible to people matched via phone number integration through Talk on mobile'),
|
||||
iconClass: 'icon-phone',
|
||||
},
|
||||
[SCOPE_ENUM.FEDERATED]: {
|
||||
name: SCOPE_ENUM.FEDERATED,
|
||||
displayName: t('settings', 'Federated'),
|
||||
|
|
|
|||
68
apps/settings/src/service/PersonalInfo/DisplayNameService.js
Normal file
68
apps/settings/src/service/PersonalInfo/DisplayNameService.js
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
/**
|
||||
* @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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
import axios from '@nextcloud/axios'
|
||||
import { getCurrentUser } from '@nextcloud/auth'
|
||||
import { generateOcsUrl } from '@nextcloud/router'
|
||||
import confirmPassword from '@nextcloud/password-confirmation'
|
||||
|
||||
import { ACCOUNT_PROPERTY_ENUM, SCOPE_SUFFIX } from '../../constants/AccountPropertyConstants'
|
||||
|
||||
/**
|
||||
* Save the primary display name of the user
|
||||
*
|
||||
* @param {string} displayName the primary display name
|
||||
* @returns {object}
|
||||
*/
|
||||
export const savePrimaryDisplayName = async(displayName) => {
|
||||
const userId = getCurrentUser().uid
|
||||
const url = generateOcsUrl('cloud/users/{userId}', { userId })
|
||||
|
||||
await confirmPassword()
|
||||
|
||||
const res = await axios.put(url, {
|
||||
key: ACCOUNT_PROPERTY_ENUM.DISPLAYNAME,
|
||||
value: displayName,
|
||||
})
|
||||
|
||||
return res.data
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the federation scope for the primary display name of the user
|
||||
*
|
||||
* @param {string} scope the federation scope
|
||||
* @returns {object}
|
||||
*/
|
||||
export const savePrimaryDisplayNameScope = async(scope) => {
|
||||
const userId = getCurrentUser().uid
|
||||
const url = generateOcsUrl('cloud/users/{userId}', { userId })
|
||||
|
||||
await confirmPassword()
|
||||
|
||||
const res = await axios.put(url, {
|
||||
key: `${ACCOUNT_PROPERTY_ENUM.DISPLAYNAME}${SCOPE_SUFFIX}`,
|
||||
value: scope,
|
||||
})
|
||||
|
||||
return res.data
|
||||
}
|
||||
|
|
@ -25,13 +25,13 @@ import { getCurrentUser } from '@nextcloud/auth'
|
|||
import { generateOcsUrl } from '@nextcloud/router'
|
||||
import confirmPassword from '@nextcloud/password-confirmation'
|
||||
|
||||
import { ACCOUNT_PROPERTY_ENUM, SCOPE_SUFFIX } from '../constants/AccountPropertyConstants'
|
||||
import { ACCOUNT_PROPERTY_ENUM, SCOPE_SUFFIX } from '../../constants/AccountPropertyConstants'
|
||||
|
||||
/**
|
||||
* Save the primary email of the user
|
||||
*
|
||||
* @param {string} email the primary email
|
||||
* @returns {Object}
|
||||
* @returns {object}
|
||||
*/
|
||||
export const savePrimaryEmail = async(email) => {
|
||||
const userId = getCurrentUser().uid
|
||||
|
|
@ -53,7 +53,7 @@ export const savePrimaryEmail = async(email) => {
|
|||
* *Will be appended to the user's additional emails*
|
||||
*
|
||||
* @param {string} email the additional email
|
||||
* @returns {Object}
|
||||
* @returns {object}
|
||||
*/
|
||||
export const saveAdditionalEmail = async(email) => {
|
||||
const userId = getCurrentUser().uid
|
||||
|
|
@ -73,7 +73,7 @@ export const saveAdditionalEmail = async(email) => {
|
|||
* Remove an additional email of the user
|
||||
*
|
||||
* @param {string} email the additional email
|
||||
* @returns {Object}
|
||||
* @returns {object}
|
||||
*/
|
||||
export const removeAdditionalEmail = async(email) => {
|
||||
const userId = getCurrentUser().uid
|
||||
|
|
@ -94,7 +94,7 @@ export const removeAdditionalEmail = async(email) => {
|
|||
*
|
||||
* @param {string} prevEmail the additional email to be updated
|
||||
* @param {string} newEmail the new additional email
|
||||
* @returns {Object}
|
||||
* @returns {object}
|
||||
*/
|
||||
export const updateAdditionalEmail = async(prevEmail, newEmail) => {
|
||||
const userId = getCurrentUser().uid
|
||||
|
|
@ -114,7 +114,7 @@ export const updateAdditionalEmail = async(prevEmail, newEmail) => {
|
|||
* Save the federation scope for the primary email of the user
|
||||
*
|
||||
* @param {string} scope the federation scope
|
||||
* @returns {Object}
|
||||
* @returns {object}
|
||||
*/
|
||||
export const savePrimaryEmailScope = async(scope) => {
|
||||
const userId = getCurrentUser().uid
|
||||
|
|
@ -135,7 +135,7 @@ export const savePrimaryEmailScope = async(scope) => {
|
|||
*
|
||||
* @param {string} email the additional email
|
||||
* @param {string} scope the federation scope
|
||||
* @returns {Object}
|
||||
* @returns {object}
|
||||
*/
|
||||
export const saveAdditionalEmailScope = async(email, scope) => {
|
||||
const userId = getCurrentUser().uid
|
||||
Loading…
Reference in a new issue