mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
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:
parent
62765e0e14
commit
e322f4a31f
9 changed files with 17 additions and 12 deletions
|
@ -70,10 +70,10 @@ function requirePermission(...requiredCapabilities) {
|
|||
}
|
||||
try {
|
||||
// get the group policy applying to the user
|
||||
const { groupPolicy } =
|
||||
const { groupPolicy, managedUsersEnabled } =
|
||||
await ManagedUsersHandler.promises.getEnrollmentForUser(req.user)
|
||||
// if there is no group policy, the user is not managed
|
||||
if (!groupPolicy) {
|
||||
|
||||
if (!managedUsersEnabled) {
|
||||
return next()
|
||||
}
|
||||
// check that the user has all the required capabilities
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -46,7 +46,7 @@ async function manageGroupMembers(req, res, next) {
|
|||
groupId: entityPrimaryKey,
|
||||
users,
|
||||
groupSize: entity.membersLimit,
|
||||
managedUsersActive: entity.groupPolicy != null,
|
||||
managedUsersActive: entity.managedUsersEnabled,
|
||||
groupSSOActive: ssoConfig?.enabled,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ const SubscriptionSchema = new Schema(
|
|||
teamNotice: { type: String },
|
||||
planCode: { type: String },
|
||||
groupPlan: { type: Boolean, default: false },
|
||||
managedUsersEnabled: { type: Boolean, default: false },
|
||||
membersLimit: { type: Number, default: 0 },
|
||||
customAccount: Boolean,
|
||||
features: {
|
||||
|
|
|
@ -279,7 +279,7 @@ describe('SubscriptionUpdater', function () {
|
|||
|
||||
it('should not remove the subscription when expired if it has "managedUsers" feature', async function () {
|
||||
this.Features.hasFeature.withArgs('saas').returns(true)
|
||||
this.subscription.groupPolicy = { policy: true }
|
||||
this.subscription.managedUsersEnabled = true
|
||||
|
||||
this.recurlySubscription.state = 'expired'
|
||||
await this.SubscriptionUpdater.promises.updateSubscriptionFromRecurly(
|
||||
|
|
|
@ -121,6 +121,7 @@ describe('UserMembershipController', function () {
|
|||
})
|
||||
|
||||
it('render group view', async function () {
|
||||
this.subscription.managedUsersEnabled = false
|
||||
return await this.UserMembershipController.manageGroupMembers(this.req, {
|
||||
render: (viewPath, viewParams) => {
|
||||
expect(viewPath).to.equal('user_membership/group-members-react')
|
||||
|
@ -132,7 +133,7 @@ describe('UserMembershipController', function () {
|
|||
})
|
||||
|
||||
it('render group view with managed users', async function () {
|
||||
this.req.entity.groupPolicy = { somePolicy: true }
|
||||
this.subscription.managedUsersEnabled = true
|
||||
return await this.UserMembershipController.manageGroupMembers(this.req, {
|
||||
render: (viewPath, viewParams) => {
|
||||
expect(viewPath).to.equal('user_membership/group-members-react')
|
||||
|
|
|
@ -9,4 +9,5 @@ export type Subscription = {
|
|||
groupPlan: boolean
|
||||
customAccount: boolean
|
||||
ssoConfig: object
|
||||
managedUsersEnabled: boolean
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue