Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

let user choose notification email in user settings #28840

Merged
merged 6 commits into from
Sep 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions apps/settings/js/vue-settings-admin-security.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/settings/js/vue-settings-admin-security.js.map

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions apps/settings/js/vue-settings-apps-users-management.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/settings/js/vue-settings-apps-users-management.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions apps/settings/js/vue-settings-nextcloud-pdf.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/settings/js/vue-settings-nextcloud-pdf.js.map

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions apps/settings/js/vue-settings-personal-info.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/settings/js/vue-settings-personal-info.js.map

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions apps/settings/js/vue-settings-personal-security.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/settings/js/vue-settings-personal-security.js.map

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions apps/settings/js/vue-settings-personal-webauthn.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/settings/js/vue-settings-personal-webauthn.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions apps/settings/js/vue-settings-users.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/settings/js/vue-settings-users.js.map

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions apps/settings/js/vue-vendors-settings-apps-settings-users.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions apps/settings/js/vue-vendors-settings-users.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/settings/js/vue-vendors-settings-users.js.map

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions apps/settings/lib/Settings/Personal/PersonalInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ private function getDisplayNames(IAccount $account): array {
* @return array
*/
private function getEmails(IAccount $account): array {
$primaryEmail = [
$systemEmail = [
'value' => $account->getProperty(IAccountManager::PROPERTY_EMAIL)->getValue(),
'scope' => $account->getProperty(IAccountManager::PROPERTY_EMAIL)->getScope(),
'verified' => $account->getProperty(IAccountManager::PROPERTY_EMAIL)->getVerified(),
Expand All @@ -243,14 +243,16 @@ function (IAccountProperty $property) {
'value' => $property->getValue(),
'scope' => $property->getScope(),
'verified' => $property->getVerified(),
'locallyVerified' => $property->getLocallyVerified(),
];
},
$account->getPropertyCollection(IAccountManager::COLLECTION_EMAIL)->getProperties()
);

$emails = [
'primaryEmail' => $primaryEmail,
'primaryEmail' => $systemEmail,
'additionalEmails' => $additionalEmails,
'notificationEmail' => (string)$account->getUser()->getPrimaryEMailAddress(),
];

return $emails;
Expand Down
71 changes: 66 additions & 5 deletions apps/settings/src/components/PersonalInfo/EmailSection/Email.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,19 @@
@click.stop.prevent="deleteEmail">
{{ deleteEmailLabel }}
</ActionButton>
<ActionButton v-if="!primary || !isNotificationEmail"
:aria-label="setNotificationMailLabel"
:close-after-click="true"
:disabled="setNotificationMailDisabled"
icon="icon-favorite"
@click.stop.prevent="setNotificationMail">
{{ setNotificationMailLabel }}
</ActionButton>
</Actions>
</div>
</div>

<em v-if="primary">
<em v-if="isNotificationEmail">
{{ t('settings', 'Primary email for password reset and notifications') }}
</em>
</div>
Expand All @@ -83,8 +91,15 @@ import debounce from 'debounce'

import FederationControl from '../shared/FederationControl'

import { ACCOUNT_PROPERTY_READABLE_ENUM } from '../../../constants/AccountPropertyConstants'
import { savePrimaryEmail, saveAdditionalEmail, saveAdditionalEmailScope, updateAdditionalEmail, removeAdditionalEmail } from '../../../service/PersonalInfo/EmailService'
import { ACCOUNT_PROPERTY_READABLE_ENUM, VERIFICATION_ENUM } from '../../../constants/AccountPropertyConstants'
import {
removeAdditionalEmail,
saveAdditionalEmail,
saveAdditionalEmailScope,
saveNotificationEmail,
savePrimaryEmail,
updateAdditionalEmail,
} from '../../../service/PersonalInfo/EmailService'
import { validateEmail } from '../../../utils/validate'

export default {
Expand Down Expand Up @@ -113,6 +128,14 @@ export default {
type: String,
required: true,
},
activeNotificationEmail: {
type: String,
default: '',
},
localVerificationState: {
type: Number,
default: VERIFICATION_ENUM.NOT_VERIFIED,
},
},

data() {
Expand Down Expand Up @@ -145,6 +168,19 @@ export default {
return t('settings', 'Delete email')
},

setNotificationMailDisabled() {
return !this.primary && this.localVerificationState !== VERIFICATION_ENUM.VERIFIED
},

setNotificationMailLabel() {
if (this.isNotificationEmail) {
return t('settings', 'Unset as primary email')
} else if (!this.primary && this.localVerificationState !== VERIFICATION_ENUM.VERIFIED) {
blizzz marked this conversation as resolved.
Show resolved Hide resolved
return t('settings', 'This address is not confirmed')
}
return t('settings', 'Set as primary mail')
},

federationDisabled() {
return !this.initialEmail
},
Expand All @@ -162,6 +198,11 @@ export default {
}
return t('settings', 'Additional email address {index}', { index: this.index + 1 })
},

isNotificationEmail() {
return (this.email === this.activeNotificationEmail)
|| (this.primary && this.activeNotificationEmail === '')
},
},

mounted() {
Expand Down Expand Up @@ -239,6 +280,22 @@ export default {
}
},

async setNotificationMail() {
try {
const newNotificationMailValue = (this.primary || this.isNotificationEmail) ? '' : this.initialEmail
const responseData = await saveNotificationEmail(newNotificationMailValue)
this.handleResponse({
notificationEmail: newNotificationMailValue,
status: responseData.ocs?.meta?.status,
})
} catch (e) {
this.handleResponse({
errorMessage: 'Unable to choose this email for notifications',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be translated ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imo yes, but the existing messages were not translated either, so i kept consistency. Would leave it as follow up.

error: e,
})
}
},

async updateAdditionalEmail(email) {
try {
const responseData = await updateAdditionalEmail(this.initialEmail, email)
Expand Down Expand Up @@ -276,10 +333,14 @@ export default {
}
},

handleResponse({ email, status, errorMessage, error }) {
handleResponse({ email, notificationEmail, status, errorMessage, error }) {
if (status === 'ok') {
// Ensure that local state reflects server state
this.initialEmail = email
if (email) {
this.initialEmail = email
} else if (notificationEmail !== undefined) {
this.$emit('update:notification-email', notificationEmail)
}
this.showCheckmarkIcon = true
setTimeout(() => { this.showCheckmarkIcon = false }, 2000)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
:primary="true"
:scope.sync="primaryEmail.scope"
:email.sync="primaryEmail.value"
@update:email="onUpdateEmail" />
:active-notification-email.sync="notificationEmail"
@update:email="onUpdateEmail"
@update:notification-email="onUpdateNotificationEmail" />
</template>
<span v-else>
{{ primaryEmail.value || t('settings', 'No email address set') }}
Expand All @@ -46,7 +48,10 @@
:index="index"
:scope.sync="additionalEmail.scope"
:email.sync="additionalEmail.value"
:local-verification-state="parseInt(additionalEmail.locallyVerified, 10)"
:active-notification-email.sync="notificationEmail"
@update:email="onUpdateEmail"
@update:notification-email="onUpdateNotificationEmail"
@delete-additional-email="onDeleteAdditionalEmail(index)" />
</section>
</template>
Expand All @@ -62,7 +67,7 @@ import { ACCOUNT_PROPERTY_READABLE_ENUM, DEFAULT_ADDITIONAL_EMAIL_SCOPE } from '
import { savePrimaryEmail, savePrimaryEmailScope, removeAdditionalEmail } from '../../../service/PersonalInfo/EmailService'
import { validateEmail } from '../../../utils/validate'

const { emails: { additionalEmails, primaryEmail } } = loadState('settings', 'personalInfoParameters', {})
const { emails: { additionalEmails, primaryEmail, notificationEmail } } = loadState('settings', 'personalInfoParameters', {})
const { displayNameChangeSupported } = loadState('settings', 'accountParameters', {})

export default {
Expand All @@ -80,6 +85,7 @@ export default {
displayNameChangeSupported,
primaryEmail,
savePrimaryEmailScope,
notificationEmail,
}
},

Expand Down Expand Up @@ -126,6 +132,10 @@ export default {
}
},

async onUpdateNotificationEmail(email) {
this.notificationEmail = email
},

async updatePrimaryEmail() {
try {
const responseData = await savePrimaryEmail(this.primaryEmailValue)
Expand Down
8 changes: 8 additions & 0 deletions apps/settings/src/constants/AccountPropertyConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const ACCOUNT_PROPERTY_ENUM = Object.freeze({
DISPLAYNAME: 'displayname',
EMAIL: 'email',
EMAIL_COLLECTION: 'additional_mail',
NOTIFICATION_EMAIL: 'notify_email',
PHONE: 'phone',
TWITTER: 'twitter',
WEBSITE: 'website',
Expand Down Expand Up @@ -118,6 +119,13 @@ export const SCOPE_PROPERTY_ENUM = Object.freeze({
/** Default additional email scope */
export const DEFAULT_ADDITIONAL_EMAIL_SCOPE = SCOPE_ENUM.LOCAL

/** Enum of verification constants, according to IAccountManager */
export const VERIFICATION_ENUM = Object.freeze({
NOT_VERIFIED: 0,
VERIFICATION_IN_PROGRESS: 1,
VERIFIED: 2,
})

/**
* Email validation regex
*
Expand Down
20 changes: 20 additions & 0 deletions apps/settings/src/service/PersonalInfo/EmailService.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,26 @@ export const saveAdditionalEmail = async(email) => {
return res.data
}

/**
* Save the notification email of the user
*
* @param {string} email the notification email
* @returns {object}
*/
export const saveNotificationEmail = async(email) => {
const userId = getCurrentUser().uid
const url = generateOcsUrl('cloud/users/{userId}', { userId })

await confirmPassword()

const res = await axios.put(url, {
key: ACCOUNT_PROPERTY_ENUM.NOTIFICATION_EMAIL,
value: email,
})

return res.data
}

/**
* Remove an additional email of the user
*
Expand Down