Skip to content

Commit

Permalink
chore: Users with noTemplateLimit flag can use paid templates
Browse files Browse the repository at this point in the history
  • Loading branch information
Dschoordsch committed Nov 9, 2023
1 parent 43269bf commit 73bd520
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const ActivityDetailsSidebar = (props: Props) => {
featureFlags {
gcal
adHocTeams
noTemplateLimit
}
...AdhocTeamMultiSelect_viewer
organizations {
Expand Down Expand Up @@ -342,7 +343,9 @@ const ActivityDetailsSidebar = (props: Props) => {
/>
)}

{selectedTeam.tier === 'starter' && !selectedTemplate.isFree ? (
{selectedTeam.tier === 'starter' &&
!viewer.featureFlags.noTemplateLimit &&
!selectedTemplate.isFree ? (
<div className='flex grow flex-col'>
<div className='my-auto text-center'>
Upgrade to the <b>Team Plan</b> to create custom activities unlocking your team’s
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ const ReflectTemplateDetails = (props: Props) => {
id
orgId
tier
viewerTeamMember {
user {
id
featureFlags {
noTemplateLimit
}
}
}
}
}
`,
Expand All @@ -103,7 +111,8 @@ const ReflectTemplateDetails = (props: Props) => {
const {teamTemplates, team} = settings
const activeTemplate = settings.activeTemplate ?? settings.selectedTemplate
const {id: templateId, name: templateName, prompts, illustrationUrl} = activeTemplate
const {id: teamId, orgId, tier} = team
const {id: teamId, orgId, tier, viewerTeamMember} = team
const noTemplateLimit = viewerTeamMember?.user?.featureFlags?.noTemplateLimit
const lowestScope = getTemplateList(teamId, orgId, activeTemplate)
const isOwner = activeTemplate.teamId === teamId
const description = useTemplateDescription(lowestScope, activeTemplate, tier)
Expand Down Expand Up @@ -158,6 +167,7 @@ const ReflectTemplateDetails = (props: Props) => {
template={activeTemplate}
teamId={teamId}
tier={tier}
noTemplateLimit={noTemplateLimit}
orgId={orgId}
/>
)}
Expand Down
5 changes: 3 additions & 2 deletions packages/client/modules/meeting/components/SelectTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ interface Props {
template: SelectTemplate_template$key
teamId: string
tier?: TierEnum
noTemplateLimit?: boolean
orgId?: string
}

const SelectTemplate = (props: Props) => {
const {template: templateRef, closePortal, teamId, tier, orgId} = props
const {template: templateRef, closePortal, teamId, tier, noTemplateLimit, orgId} = props
const template = useFragment(
graphql`
fragment SelectTemplate_template on MeetingTemplate {
Expand Down Expand Up @@ -90,7 +91,7 @@ const SelectTemplate = (props: Props) => {
})
history.push(`/me/organizations/${orgId}`)
}
const showUpgradeCTA = !isFree && tier === 'starter' && scope === 'PUBLIC'
const showUpgradeCTA = !isFree && tier === 'starter' && scope === 'PUBLIC' && !noTemplateLimit
if (showUpgradeCTA) {
return (
<ButtonBlock>
Expand Down
13 changes: 9 additions & 4 deletions packages/server/graphql/mutations/selectTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ const selectTemplate = {
const viewerId = getUserId(authToken)

// AUTH
const template = (await dataLoader
.get('meetingTemplates')
.load(selectedTemplateId)) as MeetingTemplate
const [template, viewer] = await Promise.all([
dataLoader.get('meetingTemplates').load(selectedTemplateId) as Promise<MeetingTemplate>,
dataLoader.get('users').loadNonNull(viewerId)
])

if (!template || !template.isActive) {
console.log('no template', selectedTemplateId, template)
Expand All @@ -50,7 +51,11 @@ const selectTemplate = {
return standardError(new Error('Template is scoped to organization'), {userId: viewerId})
}
} else if (scope === 'PUBLIC') {
if (!isFree && viewerTeam.tier === 'starter') {
if (
!isFree &&
!viewer.featureFlags.includes('noTemplateLimit') &&
viewerTeam.tier === 'starter'
) {
return standardError(new Error('User does not have access to this premium template'), {
userId: viewerId
})
Expand Down
28 changes: 23 additions & 5 deletions packages/server/graphql/queries/helpers/resolveSelectedTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,40 @@ import getRethink from '../../../database/rethinkDriver'
import MeetingSettingsPoker from '../../../database/types/MeetingSettingsPoker'
import MeetingSettingsRetrospective from '../../../database/types/MeetingSettingsRetrospective'
import {GQLContext} from '../../graphql'
import {getUserId} from '../../../utils/authorization'
import isValid from '../../isValid'

const resolveSelectedTemplate =
(fallbackTemplateId: string) =>
async (
source: MeetingSettingsPoker | MeetingSettingsRetrospective,
_args: unknown,
{dataLoader}: GQLContext
{authToken, dataLoader}: GQLContext
) => {
const viewerId = getUserId(authToken)
const {id: settingsId, selectedTemplateId, teamId} = source
const [team, template] = await Promise.all([
const [team, template, viewer] = await Promise.all([
dataLoader.get('teams').loadNonNull(teamId),
dataLoader.get('meetingTemplates').load(selectedTemplateId)
dataLoader.get('meetingTemplates').load(selectedTemplateId),
dataLoader.get('users').loadNonNull(viewerId)
])
const {tier} = team
if (template?.isFree || template?.scope !== 'PUBLIC' || tier !== 'starter') {
return template
if (template) {
if (
template.isFree ||
template.scope !== 'PUBLIC' ||
tier !== 'starter' ||
viewer.featureFlags.includes('noTemplateLimit')
) {
return template
}
// if anyone on the team has the noTemplateLimit flag, they might have selected a non-starter template
const teamMembers = await dataLoader.get('teamMembersByTeamId').load(teamId)
const userIds = teamMembers.map(({userId}) => userId)
const users = (await dataLoader.get('users').loadMany(userIds)).filter(isValid)
if (users.some(({featureFlags}) => featureFlags.includes('noTemplateLimit'))) {
return template
}
}
// there may be holes in our template deletion or reselection logic, so doing this to be safe
source.selectedTemplateId = fallbackTemplateId
Expand Down

0 comments on commit 73bd520

Please sign in to comment.