mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 22:23:42 +01:00
Merge pull request #33247 from overleaf/rh-cio-fix-ai-group-enabled
Base group ai enabled cio attribute on group policy GitOrigin-RevId: 2b2411aec3ffc694d2570e6031e9a876a1575e2c
This commit is contained in:
@@ -250,7 +250,8 @@ function hasPlanAiEnabled(plan) {
|
||||
function getGroupAiEnabled(
|
||||
memberGroupSubscriptions = [],
|
||||
managedGroupSubscriptions = [],
|
||||
userIsMemberOfGroupSubscription
|
||||
userIsMemberOfGroupSubscription,
|
||||
aiBlockedByPolicyId = new Map()
|
||||
) {
|
||||
if (!userIsMemberOfGroupSubscription) {
|
||||
return null
|
||||
@@ -261,12 +262,12 @@ function getGroupAiEnabled(
|
||||
...managedGroupSubscriptions,
|
||||
]
|
||||
|
||||
return allGroupSubscriptions.some(subscription => {
|
||||
const plan = Settings.plans.find(
|
||||
candidate => candidate.planCode === subscription.planCode
|
||||
)
|
||||
return hasPlanAiEnabled(plan)
|
||||
const someBlocked = allGroupSubscriptions.some(subscription => {
|
||||
const policyId = subscription.groupPolicy?.toString()
|
||||
return policyId ? aiBlockedByPolicyId.get(policyId) : false
|
||||
})
|
||||
|
||||
return !someBlocked
|
||||
}
|
||||
|
||||
function getGroupSize(
|
||||
@@ -373,6 +374,7 @@ function getPlanProperties({
|
||||
userIsMemberOfGroupSubscription,
|
||||
hasCommons,
|
||||
writefullData,
|
||||
aiBlockedByPolicyId,
|
||||
}) {
|
||||
const planType = normalizePlanType(bestSubscription)
|
||||
const displayPlanType = getFriendlyPlanName(planType)
|
||||
@@ -392,7 +394,8 @@ function getPlanProperties({
|
||||
const groupAiEnabled = getGroupAiEnabled(
|
||||
memberGroupSubscriptions,
|
||||
managedGroupSubscriptions,
|
||||
userIsMemberOfGroupSubscription
|
||||
userIsMemberOfGroupSubscription,
|
||||
aiBlockedByPolicyId
|
||||
)
|
||||
const nextRenewalDate = getNextRenewalDateFromPaymentRecord(
|
||||
individualPaymentRecord
|
||||
|
||||
@@ -17,6 +17,7 @@ import Queues from '../../infrastructure/Queues.mjs'
|
||||
import Modules from '../../infrastructure/Modules.mjs'
|
||||
import SubscriptionViewModelBuilder from './SubscriptionViewModelBuilder.mjs'
|
||||
import CustomerIoPlanHelpers from './CustomerIoPlanHelpers.mjs'
|
||||
import { GroupPolicy } from '../../models/GroupPolicy.mjs'
|
||||
import { AI_ADD_ON_CODE } from './AiHelper.mjs'
|
||||
import { fetchNothing } from '@overleaf/fetch-utils'
|
||||
import SplitTestHandler from '../SplitTests/SplitTestHandler.mjs'
|
||||
@@ -169,6 +170,11 @@ async function _updateCustomerIoSubscriptionProperties(user, features) {
|
||||
)
|
||||
}
|
||||
|
||||
const aiBlockedByPolicyId = await _loadAiBlockedByPolicyId([
|
||||
...memberGroupSubscriptions,
|
||||
...managedGroupSubscriptions,
|
||||
])
|
||||
|
||||
const planProperties = CustomerIoPlanHelpers.getPlanProperties({
|
||||
bestSubscription,
|
||||
individualSubscription,
|
||||
@@ -178,6 +184,7 @@ async function _updateCustomerIoSubscriptionProperties(user, features) {
|
||||
userIsMemberOfGroupSubscription,
|
||||
hasCommons,
|
||||
writefullData,
|
||||
aiBlockedByPolicyId,
|
||||
})
|
||||
|
||||
await Modules.promises.hooks.fire('setUserProperties', userId, {
|
||||
@@ -188,6 +195,29 @@ async function _updateCustomerIoSubscriptionProperties(user, features) {
|
||||
})
|
||||
}
|
||||
|
||||
async function _loadAiBlockedByPolicyId(groupSubscriptions) {
|
||||
const policyIds = [
|
||||
...new Set(
|
||||
groupSubscriptions.map(sub => sub.groupPolicy?.toString()).filter(Boolean)
|
||||
),
|
||||
]
|
||||
|
||||
if (policyIds.length === 0) {
|
||||
return new Map()
|
||||
}
|
||||
|
||||
const policies = await GroupPolicy.find(
|
||||
{ _id: { $in: policyIds } },
|
||||
{ _id: 1, userCannotUseAIFeatures: 1 }
|
||||
).exec()
|
||||
return new Map(
|
||||
policies.map(policy => [
|
||||
policy._id.toString(),
|
||||
Boolean(policy.userCannotUseAIFeatures),
|
||||
])
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the features that the given user should have.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user