Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(schedule flag changes): tweak frontend #19488

Merged
merged 105 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
9d277aa
add plain UI
jurajmajerik Dec 5, 2023
7d49c4c
Update UI snapshots for `chromium` (1)
github-actions[bot] Dec 5, 2023
7d51dbc
resolve conflict
jurajmajerik Dec 6, 2023
2563319
Merge branch 'master' into feat/schedule-feature-flag
jurajmajerik Dec 6, 2023
8496142
Merge branch 'master' into feat/schedule-feature-flag
jurajmajerik Dec 6, 2023
f72db3d
Merge branch 'master' into feat/schedule-feature-flag
jurajmajerik Dec 7, 2023
1d5c0ac
add schedule changes API
jurajmajerik Dec 8, 2023
2be18e8
Merge branch 'master' of https://github.com/PostHog/posthog into feat…
jurajmajerik Dec 8, 2023
473b9bd
add migrations
jurajmajerik Dec 8, 2023
92b4bad
adjust model
jurajmajerik Dec 12, 2023
59d9e00
Merge branch 'master' of https://github.com/PostHog/posthog into feat…
jurajmajerik Dec 12, 2023
232175b
adjust
jurajmajerik Dec 12, 2023
845bce5
connect frontend to the API
jurajmajerik Dec 13, 2023
10132ef
resolve conflict
jurajmajerik Dec 14, 2023
8bff377
clarify
jurajmajerik Dec 14, 2023
d00e33d
Update UI snapshots for `chromium` (2)
github-actions[bot] Dec 14, 2023
e317449
Update UI snapshots for `chromium` (2)
github-actions[bot] Dec 14, 2023
20b2a8e
Update UI snapshots for `chromium` (2)
github-actions[bot] Dec 14, 2023
2c7be9e
Update query snapshots
github-actions[bot] Dec 14, 2023
4cd2bcf
Update UI snapshots for `chromium` (2)
github-actions[bot] Dec 14, 2023
20fe30a
Update query snapshots
github-actions[bot] Dec 14, 2023
60fd6a2
rename setId -> setFeatureFlagId
jurajmajerik Dec 14, 2023
7b0b30e
Merge branch 'feat/schedule-feature-flag' of https://github.com/PostH…
jurajmajerik Dec 14, 2023
99099e2
Merge branch 'master' into feat/schedule-feature-flag
jurajmajerik Dec 15, 2023
a22e702
Merge branch 'master' into feat/schedule-feature-flag
jurajmajerik Dec 15, 2023
a5289e8
update latest migrations
jurajmajerik Dec 16, 2023
74f98dc
Merge branch 'feat/schedule-feature-flag' of https://github.com/PostH…
jurajmajerik Dec 16, 2023
7978672
Merge branch 'master' of https://github.com/PostHog/posthog into feat…
jurajmajerik Dec 18, 2023
5c71062
Merge branch 'master' of https://github.com/PostHog/posthog into feat…
jurajmajerik Dec 18, 2023
60ea996
implement scheduling of changes
jurajmajerik Dec 18, 2023
2cc0f5d
don't re-run failed changes
jurajmajerik Dec 18, 2023
3286b74
Update posthog/celery.py
jurajmajerik Dec 19, 2023
ac1d83b
process in chunks
jurajmajerik Dec 19, 2023
5fde0f0
add return type
jurajmajerik Dec 20, 2023
f3c283a
order queried changes by scheduled_at
jurajmajerik Dec 20, 2023
5fe726e
add test for multiple scheduled changes
jurajmajerik Dec 20, 2023
5cc9720
Merge branch 'master' into feat/schedule-feature-flag
jurajmajerik Dec 20, 2023
0d78d7a
adjust scheduled_change model
jurajmajerik Dec 21, 2023
bc842e4
limit query to 10,000 records
jurajmajerik Dec 21, 2023
d6b8a59
add query snapshot
jurajmajerik Dec 21, 2023
96131cd
fix conflict
jurajmajerik Dec 21, 2023
7ff2c44
use serializer to update the flag
jurajmajerik Dec 21, 2023
30e47a6
rename payload fields
jurajmajerik Dec 21, 2023
7e418ba
fix conflict
jurajmajerik Dec 21, 2023
acd5fc4
fix migrations
jurajmajerik Dec 21, 2023
f096549
add migrations manifest
jurajmajerik Dec 21, 2023
3059b90
Update query snapshots
github-actions[bot] Dec 21, 2023
049d4a2
Merge branch 'master' into feat/schedule-feature-flag
jurajmajerik Dec 21, 2023
2249402
Update query snapshots
github-actions[bot] Dec 21, 2023
5af6b0a
Update query snapshots
github-actions[bot] Dec 21, 2023
803418e
Update query snapshots
github-actions[bot] Dec 21, 2023
b4f6d2d
Update query snapshots
github-actions[bot] Dec 21, 2023
3e260ba
Update query snapshots
github-actions[bot] Dec 21, 2023
1a0f51a
Update query snapshots
github-actions[bot] Dec 21, 2023
6827222
Update query snapshots
github-actions[bot] Dec 21, 2023
4da809f
Update query snapshots
github-actions[bot] Dec 21, 2023
04a9bb5
fix migrations
jurajmajerik Dec 21, 2023
710cdb6
Merge branch 'feat/schedule-feature-flag' of https://github.com/PostH…
jurajmajerik Dec 21, 2023
edac981
Update query snapshots
github-actions[bot] Dec 21, 2023
c7f1a23
Update query snapshots
github-actions[bot] Dec 21, 2023
41da321
Update query snapshots
github-actions[bot] Dec 21, 2023
9cba2f1
final adjustments
jurajmajerik Dec 21, 2023
1cde7db
fix conflict
jurajmajerik Dec 21, 2023
c77f238
Merge branch 'master' of https://github.com/PostHog/posthog into feat…
jurajmajerik Dec 21, 2023
3c524ef
add index concurrently
jurajmajerik Dec 21, 2023
1ba4020
Merge branch 'master' into feat/schedule-feature-flag
jurajmajerik Dec 21, 2023
77dc563
import AddIndexConcurrently
jurajmajerik Dec 21, 2023
7353f82
Merge branch 'feat/schedule-feature-flag' of https://github.com/PostH…
jurajmajerik Dec 21, 2023
cf5862a
tweak migration
jurajmajerik Dec 21, 2023
674cc7d
Merge branch 'master' into feat/schedule-feature-flag
jurajmajerik Dec 21, 2023
4056337
tweak migration
jurajmajerik Dec 21, 2023
4f19320
Merge branch 'feat/schedule-feature-flag' of https://github.com/PostH…
jurajmajerik Dec 21, 2023
846dfcf
tweak migration
jurajmajerik Dec 21, 2023
dc05e1b
Merge branch 'master' into feat/schedule-feature-flag
jurajmajerik Dec 21, 2023
62340ed
fix API test
jurajmajerik Dec 21, 2023
679052d
Merge branch 'feat/schedule-feature-flag' of https://github.com/PostH…
jurajmajerik Dec 21, 2023
c1466fe
Merge branch 'feat/schedule-feature-flag' of https://github.com/PostH…
jurajmajerik Dec 21, 2023
ca435c2
Merge branch 'feat/schedule-feature-flag' of https://github.com/PostH…
jurajmajerik Dec 21, 2023
b15f114
Merge branch 'master' of https://github.com/PostHog/posthog into feat…
jurajmajerik Dec 21, 2023
b00bc9a
adjust frontend
jurajmajerik Dec 21, 2023
300f720
Update UI snapshots for `chromium` (1)
github-actions[bot] Dec 21, 2023
7eb3a1e
Update UI snapshots for `chromium` (1)
github-actions[bot] Dec 21, 2023
0290b83
don't show 'Now' in DatePicker
jurajmajerik Dec 22, 2023
6c837af
Merge branch 'feat/schedule-feature-flag' of https://github.com/PostH…
jurajmajerik Dec 22, 2023
588c3f6
Merge branch 'master' into feat/schedule-feature-flag
jurajmajerik Dec 22, 2023
2c10a83
construct context properly
jurajmajerik Dec 22, 2023
e106542
fix opacity
jurajmajerik Dec 22, 2023
ee11c1f
prefix 'Add release condition'
jurajmajerik Dec 22, 2023
201baf7
Merge branch 'feat/schedule-feature-flag' of https://github.com/PostH…
jurajmajerik Dec 22, 2023
335da0d
Update UI snapshots for `chromium` (2)
github-actions[bot] Dec 22, 2023
47a3f22
Update query snapshots
github-actions[bot] Dec 22, 2023
abb36bc
Update UI snapshots for `chromium` (2)
github-actions[bot] Dec 22, 2023
8539d7b
add tooltip to the status tag
jurajmajerik Dec 22, 2023
e15224f
Merge branch 'feat/schedule-feature-flag' of https://github.com/PostH…
jurajmajerik Dec 22, 2023
9f10f3b
Merge branch 'master' of https://github.com/PostHog/posthog into feat…
jurajmajerik Dec 22, 2023
9687b85
no tooltip without executed_at
jurajmajerik Dec 22, 2023
0c56473
Update UI snapshots for `chromium` (2)
github-actions[bot] Dec 22, 2023
c66ddb4
Update UI snapshots for `chromium` (1)
github-actions[bot] Dec 22, 2023
dc18728
Update UI snapshots for `chromium` (1)
github-actions[bot] Dec 22, 2023
858a302
Update UI snapshots for `chromium` (2)
github-actions[bot] Dec 22, 2023
4dd2589
Merge branch 'master' of https://github.com/PostHog/posthog into feat…
jurajmajerik Jan 3, 2024
9c9a618
preserve variants when adding a condition
jurajmajerik Jan 3, 2024
5cfc4c4
set aggregation group type index
jurajmajerik Jan 3, 2024
3677bb1
reset fields after change submitted
jurajmajerik Jan 3, 2024
f09eaae
Merge branch 'master' of https://github.com/PostHog/posthog into feat…
jurajmajerik Jan 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions frontend/src/scenes/feature-flags/FeatureFlag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,14 @@ export function FeatureFlag({ id }: { id?: string } = {}): JSX.Element {
})
}

if (featureFlags[FEATURE_FLAGS.SCHEDULED_CHANGES_FEATURE_FLAGS]) {
tabs.push({
label: 'Schedule',
key: FeatureFlagsTab.SCHEDULE,
content: <FeatureFlagSchedule />,
})
}

if (featureFlags[FEATURE_FLAGS.FF_DASHBOARD_TEMPLATES] && featureFlag.key && id) {
tabs.push({
label: (
Expand Down Expand Up @@ -222,14 +230,6 @@ export function FeatureFlag({ id }: { id?: string } = {}): JSX.Element {
})
}

if (featureFlags[FEATURE_FLAGS.SCHEDULED_CHANGES_FEATURE_FLAGS]) {
tabs.push({
label: 'Schedule',
key: FeatureFlagsTab.SCHEDULE,
content: <FeatureFlagSchedule />,
})
}

return (
<>
<div className="feature-flag">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ export function FeatureFlagReleaseConditions({
</LemonBanner>
)}
</div>
{!readOnly && showGroupsOptions && (
{!readOnly && showGroupsOptions && usageContext !== 'schedule' && (
<div className="centered">
Match by
<Select
Expand Down
128 changes: 100 additions & 28 deletions frontend/src/scenes/feature-flags/FeatureFlagSchedule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,49 @@ import {
LemonTable,
LemonTableColumn,
LemonTableColumns,
LemonTag,
LemonTagType,
} from '@posthog/lemon-ui'
import { useActions, useValues } from 'kea'
import { DatePicker } from 'lib/components/DatePicker'
import { dayjs } from 'lib/dayjs'
import { More } from 'lib/lemon-ui/LemonButton/More'
import { atColumn, createdAtColumn, createdByColumn } from 'lib/lemon-ui/LemonTable/columnUtils'
import { Tooltip } from 'lib/lemon-ui/Tooltip'
import { useEffect } from 'react'

import { ScheduledChangeType } from '~/types'
import { groupsModel } from '~/models/groupsModel'
import { ScheduledChangeOperationType, ScheduledChangeType } from '~/types'

import { featureFlagLogic } from './featureFlagLogic'
import { FeatureFlagReleaseConditions } from './FeatureFlagReleaseConditions'
import { groupFilters } from './FeatureFlags'

const featureFlagScheduleLogic = featureFlagLogic({ id: 'schedule' })
export const DAYJS_FORMAT = 'MMMM DD, YYYY h:mm A'

export default function FeatureFlagSchedule(): JSX.Element {
const { featureFlag, scheduledChanges, scheduledChangeField, scheduleDateMarker } =
const { featureFlag, scheduledChanges, scheduledChangeOperation, scheduleDateMarker } =
useValues(featureFlagScheduleLogic)
const {
setFeatureFlagId,
setFeatureFlag,
setAggregationGroupTypeIndex,
loadScheduledChanges,
createScheduledChange,
deleteScheduledChange,
setScheduleDateMarker,
setScheduledChangeField,
setScheduledChangeOperation,
} = useActions(featureFlagScheduleLogic)
const { aggregationLabel } = useValues(groupsModel)

const featureFlagId = useValues(featureFlagLogic).featureFlag.id
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keeping consistent, easier to read 😅

const { featureFlag } = useValues(featureFlagLogic)
const featureFlagId = featureFlagId
const aggregationGroupTypeIndex = ....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is featureFlag is already destructured from featureFlagScheduleLogic, hence accessing the id here directly with the dot notation 😬

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh, I see, minor nit, you can rename it when destructuring to prevent conflicts

const { featureFlag: originalFlag } = useValues(...)
const id = originalFlag.id

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh I didn't know this was possible, thanks!

const aggregationGroupTypeIndex = useValues(featureFlagLogic).featureFlag.filters.aggregation_group_type_index

useEffect(() => {
// Set the feature flag ID from the main flag logic to the current logic
setFeatureFlagId(featureFlagId)
setAggregationGroupTypeIndex(aggregationGroupTypeIndex || null)

loadScheduledChanges()
}, [])
Expand All @@ -47,35 +57,89 @@ export default function FeatureFlagSchedule(): JSX.Element {
{
title: 'Change',
dataIndex: 'payload',
render: (dataValue) => {
return JSON.stringify(dataValue)
render: function Render(_, scheduledChange: ScheduledChangeType) {
const { payload } = scheduledChange

if (payload.operation === ScheduledChangeOperationType.UpdateStatus) {
const isEnabled = payload.value
return (
<LemonTag type={isEnabled ? 'success' : 'default'} className="uppercase">
{isEnabled ? 'Enable' : 'Disable'}
</LemonTag>
)
} else if (payload.operation === ScheduledChangeOperationType.AddReleaseCondition) {
const releaseText = groupFilters(payload.value, undefined, aggregationLabel)
return (
<div className="inline-flex leading-8">
<span className="mr-2">
<b>Add release condition:</b>
</span>
{typeof releaseText === 'string' && releaseText.startsWith('100% of') ? (
<LemonTag type="highlight">{releaseText}</LemonTag>
) : (
releaseText
)}
</div>
)
}

return JSON.stringify(payload)
},
},
atColumn('scheduled_at', 'Scheduled at') as LemonTableColumn<
ScheduledChangeType,
keyof ScheduledChangeType | undefined
>,
atColumn('executed_at', 'Executed at') as LemonTableColumn<
ScheduledChangeType,
keyof ScheduledChangeType | undefined
>,
createdByColumn() as LemonTableColumn<ScheduledChangeType, keyof ScheduledChangeType | undefined>,
createdAtColumn() as LemonTableColumn<ScheduledChangeType, keyof ScheduledChangeType | undefined>,
createdByColumn() as LemonTableColumn<ScheduledChangeType, keyof ScheduledChangeType | undefined>,
{
width: 0,
render: function Render(_: any, scheduledChange: ScheduledChangeType) {
title: 'Status',
dataIndex: 'executed_at',
render: function Render(_, scheduledChange: ScheduledChangeType) {
const { executed_at, failure_reason } = scheduledChange

function getStatus(): { type: LemonTagType; text: string } {
if (failure_reason) {
return { type: 'danger', text: 'Error' }
} else if (executed_at) {
return { type: 'completion', text: 'Complete' }
} else {
return { type: 'default', text: 'Scheduled' }
}
}
const { type, text } = getStatus()
return (
<More
overlay={
<LemonButton
status="danger"
onClick={() => deleteScheduledChange(scheduledChange.id)}
fullWidth
>
Delete scheduled change
</LemonButton>
<Tooltip
title={
failure_reason
? `Failed: ${failure_reason}`
: executed_at && `Completed: ${dayjs(executed_at).format('MMMM D, YYYY h:mm A')}`
}
/>
>
<LemonTag type={type}>
<b className="uppercase">{text}</b>
</LemonTag>{' '}
</Tooltip>
)
},
},
{
width: 0,
render: function Render(_, scheduledChange: ScheduledChangeType) {
return (
!scheduledChange.executed_at && (
<More
overlay={
<LemonButton
status="danger"
onClick={() => deleteScheduledChange(scheduledChange.id)}
fullWidth
>
Delete scheduled change
</LemonButton>
}
/>
)
)
},
},
Expand All @@ -91,30 +155,35 @@ export default function FeatureFlagSchedule(): JSX.Element {
<LemonSelect
className="w-50"
placeholder="Select variant"
value={scheduledChangeField}
onChange={(value) => setScheduledChangeField(value)}
value={scheduledChangeOperation}
onChange={(value) => setScheduledChangeOperation(value)}
options={[
{ label: 'Change status', value: 'active' },
{ label: 'Add a condition', value: 'filters' },
{ label: 'Change status', value: ScheduledChangeOperationType.UpdateStatus },
{ label: 'Add a condition', value: ScheduledChangeOperationType.AddReleaseCondition },
]}
/>
</div>
<div>
<div className="font-semibold leading-6 h-6 mb-1">Date and time</div>
<DatePicker
disabledDate={(dateMarker) => {
const now = new Date()
return dateMarker.toDate().getTime() < now.getTime()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not obvious that the date is in the past, need a disabled reason to explain 😅

}}
value={scheduleDateMarker}
onChange={(value) => setScheduleDateMarker(value)}
className="h-10 w-60"
allowClear={false}
showTime
showSecond={false}
format={DAYJS_FORMAT}
showNow={false}
/>
</div>
</div>

<div className="space-y-4">
{scheduledChangeField === 'active' && (
{scheduledChangeOperation === ScheduledChangeOperationType.UpdateStatus && (
<>
<div className="border rounded p-4">
<LemonCheckbox
Expand All @@ -129,7 +198,9 @@ export default function FeatureFlagSchedule(): JSX.Element {
</div>
</>
)}
{scheduledChangeField === 'filters' && <FeatureFlagReleaseConditions usageContext="schedule" />}
{scheduledChangeOperation === ScheduledChangeOperationType.AddReleaseCondition && (
<FeatureFlagReleaseConditions usageContext="schedule" />
)}
<div className="flex items-center justify-end">
<LemonButton
disabledReason={!scheduleDateMarker ? 'Select the scheduled date and time' : null}
Expand All @@ -142,6 +213,7 @@ export default function FeatureFlagSchedule(): JSX.Element {
<LemonDivider className="" />
</div>
<LemonTable
rowClassName={(record) => (record.executed_at ? 'opacity-75' : '')}
className="mt-8"
loading={false}
dataSource={scheduledChanges}
Expand Down
28 changes: 19 additions & 9 deletions frontend/src/scenes/feature-flags/featureFlagLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
PropertyFilterType,
PropertyOperator,
RolloutConditionType,
ScheduledChangeOperationType,
ScheduledChangeType,
Survey,
SurveyQuestionType,
Expand Down Expand Up @@ -233,7 +234,7 @@ export const featureFlagLogic = kea<featureFlagLogicType>([
setFeatureFlagId: (id: number | null) => ({ id }),
setCopyDestinationProject: (id: number | null) => ({ id }),
setScheduleDateMarker: (dateMarker: any) => ({ dateMarker }),
setScheduledChangeField: (changeType: string | null) => ({ changeType }),
setScheduledChangeOperation: (changeType: string | null) => ({ changeType }),
}),
forms(({ actions, values }) => ({
featureFlag: {
Expand Down Expand Up @@ -493,10 +494,10 @@ export const featureFlagLogic = kea<featureFlagLogicType>([
setScheduleDateMarker: (_, { dateMarker }) => dateMarker,
},
],
scheduledChangeField: [
'active' as string | null,
scheduledChangeOperation: [
ScheduledChangeOperationType.AddReleaseCondition as string | null,
{
setScheduledChangeField: (_, { changeType }) => changeType,
setScheduledChangeOperation: (_, { changeType }) => changeType,
},
],
}),
Expand Down Expand Up @@ -657,16 +658,20 @@ export const featureFlagLogic = kea<featureFlagLogicType>([
scheduledChange: {
__default: {} as ScheduledChangeType,
createScheduledChange: async () => {
const { featureFlag, scheduledChangeField, scheduleDateMarker, currentTeamId } = values
const { featureFlag, scheduledChangeOperation, scheduleDateMarker, currentTeamId } = values

if (currentTeamId && scheduledChangeField) {
const fields = {
[ScheduledChangeOperationType.UpdateStatus]: 'active',
[ScheduledChangeOperationType.AddReleaseCondition]: 'filters',
}

if (currentTeamId && scheduledChangeOperation) {
const data = {
record_id: values.featureFlag.id,
model_name: 'FeatureFlag',
operation: scheduledChangeField,
payload: {
field: scheduledChangeField,
value: featureFlag[scheduledChangeField],
operation: scheduledChangeOperation,
value: featureFlag[fields[scheduledChangeOperation]],
},
scheduled_at: scheduleDateMarker.toISOString(),
}
Expand Down Expand Up @@ -873,6 +878,11 @@ export const featureFlagLogic = kea<featureFlagLogicType>([
if (scheduledChange && scheduledChange) {
lemonToast.success('Change scheduled successfully')
actions.loadScheduledChanges()
actions.setFeatureFlag({
...values.featureFlag,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this happens only on the keyed logic with id 'schedule' right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct!

filters: NEW_FLAG.filters,
active: NEW_FLAG.active,
})
}
},
deleteScheduledChangeSuccess: ({ scheduledChange }) => {
Expand Down
11 changes: 10 additions & 1 deletion frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2449,12 +2449,21 @@ export enum ScheduledChangeModels {
FeatureFlag = 'FeatureFlag',
}

export enum ScheduledChangeOperationType {
UpdateStatus = 'update_status',
AddReleaseCondition = 'add_release_condition',
}

export type ScheduledChangePayload =
| { operation: ScheduledChangeOperationType.UpdateStatus; value: boolean }
| { operation: ScheduledChangeOperationType.AddReleaseCondition; value: FeatureFlagFilters }

export interface ScheduledChangeType {
id: number
team_id: number
record_id: number | string
model_name: ScheduledChangeModels
payload: Record<string, any>
payload: ScheduledChangePayload
scheduled_at: string
executed_at: string | null
failure_reason: string | null
Expand Down
12 changes: 9 additions & 3 deletions posthog/models/feature_flag/feature_flag.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
from django.http import HttpRequest
import structlog
from typing import Dict, List, Optional, cast

Expand Down Expand Up @@ -303,16 +304,21 @@ def scheduled_changes_dispatcher(self, payload):
if "operation" not in payload or "value" not in payload:
raise Exception("Invalid payload")

http_request = HttpRequest()
http_request.user = self.created_by
context = {
"request": {"user": self.created_by},
"request": http_request,
"team_id": self.team_id,
}

serializer_data = {}

if payload["operation"] == "add_release_condition":
existing_groups = self.get_filters().get("groups", [])
current_filters = self.get_filters()
current_groups = current_filters.get("groups", [])
new_groups = payload["value"].get("groups", [])
serializer_data["filters"] = {"groups": existing_groups + new_groups}

serializer_data["filters"] = {**current_filters, "groups": current_groups + new_groups}
elif payload["operation"] == "update_status":
serializer_data["active"] = payload["value"]
else:
Expand Down
Loading
Loading