Merge pull request #15418 from overleaf/ds-managedUsersEnabled
Managed users - Adding a managedUsersEnabled flag on subscription model GitOrigin-RevId: a03dd169ba71255dd1bec5f7bee8ce9609d95a2f
This commit is contained in:
committed by
Copybot
parent
62765e0e14
commit
e322f4a31f
@@ -32,12 +32,14 @@ const logger = require('@overleaf/logger')
|
||||
*/
|
||||
async function enableManagedUsers(subscriptionId) {
|
||||
const subscription = await Subscription.findById(subscriptionId).exec()
|
||||
|
||||
// create a new Group policy with the default settings for managed users
|
||||
const policy = ManagedUsersPolicy.getDefaultPolicy()
|
||||
const groupPolicy = new GroupPolicy(policy)
|
||||
await groupPolicy.save()
|
||||
// update the subscription to use the new policy
|
||||
subscription.groupPolicy = groupPolicy._id
|
||||
subscription.managedUsersEnabled = true
|
||||
await subscription.save()
|
||||
|
||||
await _sendEmailToGroupMembers(subscriptionId)
|
||||
@@ -55,7 +57,6 @@ async function enableManagedUsers(subscriptionId) {
|
||||
*/
|
||||
async function disableManagedUsers(subscriptionId) {
|
||||
const subscription = await Subscription.findById(subscriptionId).exec()
|
||||
|
||||
for (const userId of subscription.member_ids || []) {
|
||||
const user = await UserGetter.promises.getUser(userId, { enrollment: 1 })
|
||||
if (
|
||||
@@ -68,6 +69,7 @@ async function disableManagedUsers(subscriptionId) {
|
||||
}
|
||||
|
||||
subscription.groupPolicy = undefined
|
||||
subscription.managedUsersEnabled = false
|
||||
await subscription.save()
|
||||
}
|
||||
|
||||
@@ -110,6 +112,7 @@ async function getEnrollmentForUser(requestedUser) {
|
||||
|
||||
return {
|
||||
groupPolicy,
|
||||
managedUsersEnabled: subscription.managedUsersEnabled,
|
||||
managedBy: user.enrollment.managedBy,
|
||||
isManagedGroupAdmin,
|
||||
}
|
||||
|
||||
@@ -230,7 +230,7 @@ async function updateSubscriptionFromRecurly(
|
||||
) {
|
||||
if (recurlySubscription.state === 'expired') {
|
||||
const hasManagedUsersFeature =
|
||||
Features.hasFeature('saas') && subscription?.groupPolicy != null
|
||||
Features.hasFeature('saas') && subscription?.managedUsersEnabled
|
||||
if (hasManagedUsersFeature) {
|
||||
// If a payment lapses and if the group is managed, as a temporary measure we need to
|
||||
// make sure that the group continues as-is and no destructive actions are taken.
|
||||
|
||||
@@ -71,7 +71,7 @@ async function acceptInvite(token, userId) {
|
||||
|
||||
await SubscriptionUpdater.promises.addUserToGroup(subscription._id, userId)
|
||||
|
||||
if (subscription.groupPolicy) {
|
||||
if (subscription.managedUsersEnabled) {
|
||||
await ManagedUsersHandler.promises.enrollInSubscription(
|
||||
userId,
|
||||
subscription
|
||||
@@ -164,12 +164,11 @@ async function _createInvite(subscription, email, inviter) {
|
||||
}
|
||||
|
||||
try {
|
||||
const managedUsersEnabled = Boolean(subscription.groupPolicy)
|
||||
await _sendNotificationToExistingUser(
|
||||
subscription,
|
||||
email,
|
||||
invite,
|
||||
managedUsersEnabled
|
||||
subscription.managedUsersEnabled
|
||||
)
|
||||
} catch (err) {
|
||||
logger.error(
|
||||
@@ -180,7 +179,7 @@ async function _createInvite(subscription, email, inviter) {
|
||||
|
||||
await subscription.save()
|
||||
|
||||
if (subscription.groupPolicy) {
|
||||
if (subscription.managedUsersEnabled) {
|
||||
let admin = {}
|
||||
try {
|
||||
admin = await SubscriptionLocator.promises.getAdminEmailAndName(
|
||||
|
||||
Reference in New Issue
Block a user