2020-05-19 05:02:56 -04:00
|
|
|
import App from '../../base'
|
2022-12-13 03:56:32 -05:00
|
|
|
import getMeta from '../../utils/meta'
|
2020-02-11 09:50:56 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
const ExposedSettings = window.ExposedSettings
|
2021-04-14 09:17:21 -04:00
|
|
|
App.controller('NotificationsController', function ($scope, $http) {
|
2021-05-05 09:05:04 -04:00
|
|
|
for (const notification of $scope.notifications || []) {
|
2020-05-19 05:02:56 -04:00
|
|
|
notification.hide = false
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.samlInitPath = ExposedSettings.samlInitPath
|
2019-10-21 12:02:01 -04:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.dismiss = notification => {
|
|
|
|
if (!notification._id) {
|
|
|
|
notification.hide = true
|
|
|
|
return
|
2020-05-06 06:27:19 -04:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
$http({
|
|
|
|
url: `/notifications/${notification._id}`,
|
|
|
|
method: 'DELETE',
|
|
|
|
headers: {
|
2021-04-27 03:52:58 -04:00
|
|
|
'X-Csrf-Token': window.csrfToken,
|
|
|
|
},
|
2020-05-19 05:02:56 -04:00
|
|
|
}).then(() => (notification.hide = true))
|
|
|
|
}
|
|
|
|
})
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2022-12-13 03:56:32 -05:00
|
|
|
App.controller(
|
|
|
|
'GroupsAndEnterpriseBannerController',
|
|
|
|
function ($scope, localStorage) {
|
|
|
|
$scope.hasDismissedGroupsAndEnterpriseBanner = localStorage(
|
|
|
|
'has_dismissed_groups_and_enterprise_banner'
|
|
|
|
)
|
|
|
|
|
|
|
|
$scope.dismiss = () => {
|
|
|
|
localStorage('has_dismissed_groups_and_enterprise_banner', true)
|
|
|
|
$scope.hasDismissedGroupsAndEnterpriseBanner = true
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.groupsAndEnterpriseBannerVariant = getMeta(
|
|
|
|
'ol-groupsAndEnterpriseBannerVariant'
|
|
|
|
)
|
|
|
|
|
|
|
|
$scope.isVariantValid =
|
|
|
|
$scope.groupsAndEnterpriseBannerVariant === 'save' ||
|
|
|
|
$scope.groupsAndEnterpriseBannerVariant === 'empower' ||
|
|
|
|
$scope.groupsAndEnterpriseBannerVariant === 'did-you-know'
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
App.controller('ProjectInviteNotificationController', function ($scope, $http) {
|
2020-05-19 05:02:56 -04:00
|
|
|
// Shortcuts for translation keys
|
|
|
|
$scope.projectName = $scope.notification.messageOpts.projectName
|
|
|
|
$scope.userName = $scope.notification.messageOpts.userName
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.accept = function () {
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.notification.inflight = true
|
|
|
|
return $http({
|
2020-12-15 05:23:54 -05:00
|
|
|
url: `/project/${$scope.notification.messageOpts.projectId}/invite/token/${$scope.notification.messageOpts.token}/accept`,
|
2020-05-19 05:02:56 -04:00
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
'X-Csrf-Token': window.csrfToken,
|
2021-04-27 03:52:58 -04:00
|
|
|
'X-Requested-With': 'XMLHttpRequest',
|
|
|
|
},
|
2020-05-19 05:02:56 -04:00
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
$scope.notification.accepted = true
|
2018-11-05 05:06:39 -05:00
|
|
|
})
|
2020-05-19 05:02:56 -04:00
|
|
|
.catch(({ status }) => {
|
|
|
|
if (status === 404) {
|
|
|
|
// 404 probably means the invite has already been accepted and
|
|
|
|
// deleted. Treat as success
|
2019-07-01 09:50:15 -04:00
|
|
|
$scope.notification.accepted = true
|
2020-05-19 05:02:56 -04:00
|
|
|
} else {
|
|
|
|
$scope.notification.error = true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
$scope.notification.inflight = false
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
App.controller(
|
|
|
|
'EmailNotificationController',
|
|
|
|
function ($scope, $http, UserAffiliationsDataService) {
|
|
|
|
$scope.userEmails = window.data.userEmails
|
|
|
|
const _ssoAvailable = email => {
|
|
|
|
if (!ExposedSettings.hasSamlFeature) return false
|
|
|
|
if (email.samlProviderId) return true
|
|
|
|
if (!email.affiliation || !email.affiliation.institution) return false
|
|
|
|
if (email.affiliation.institution.ssoEnabled) return true
|
|
|
|
if (
|
|
|
|
ExposedSettings.hasSamlBeta &&
|
|
|
|
email.affiliation.institution.ssoBeta
|
|
|
|
) {
|
|
|
|
return true
|
|
|
|
}
|
2020-01-02 14:22:06 -05:00
|
|
|
return false
|
|
|
|
}
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.showConfirmEmail = email => {
|
|
|
|
if (ExposedSettings.emailConfirmationDisabled) {
|
2019-12-18 04:46:27 -05:00
|
|
|
return false
|
|
|
|
}
|
2021-04-14 09:17:21 -04:00
|
|
|
if (!email.confirmedAt && !email.hide) {
|
|
|
|
if (_ssoAvailable(email)) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
2021-05-05 09:05:04 -04:00
|
|
|
for (const userEmail of $scope.userEmails) {
|
2021-04-14 09:17:21 -04:00
|
|
|
userEmail.hide = false
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.resendConfirmationEmail = function (userEmail) {
|
|
|
|
userEmail.confirmationInflight = true
|
|
|
|
userEmail.error = false
|
|
|
|
userEmail.errorMessage = null
|
|
|
|
UserAffiliationsDataService.resendConfirmationEmail(userEmail.email)
|
|
|
|
.then(() => {
|
|
|
|
userEmail.hide = true
|
|
|
|
$scope.$emit('project-list:notifications-received')
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
userEmail.error = true
|
|
|
|
userEmail.errorMessage = error.data.message
|
|
|
|
console.error(error)
|
|
|
|
$scope.$emit('project-list:notifications-received')
|
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
userEmail.confirmationInflight = false
|
|
|
|
})
|
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2021-04-14 09:17:21 -04:00
|
|
|
)
|