Skip to content

Commit

Permalink
Merge branch 'refs/heads/main' into chore/rtk-identity-traits
Browse files Browse the repository at this point in the history
# Conflicts:
#	frontend/common/types/requests.ts
#	frontend/web/components/pages/UserPage.tsx
  • Loading branch information
kyle-ssg committed Feb 19, 2025
2 parents 0cf996a + 951b216 commit 23e3be4
Show file tree
Hide file tree
Showing 38 changed files with 1,316 additions and 1,027 deletions.
6 changes: 6 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Initial Mypy '# type: ignore' comments dump
# https://github.com/Flagsmith/flagsmith/pull/5119
5de0b425b0ee16b16bfb0fb33b067fa314d040fb
# Linting fixes for frontend
# https://github.com/Flagsmith/flagsmith/pull/5123
1f7083636d3b163588fe9a8b45af289bd40b1a8d
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repos:
exclude: migrations

- repo: https://github.com/pycqa/flake8
rev: 7.1.1
rev: 7.1.2
hooks:
- id: flake8
name: flake8
Expand Down Expand Up @@ -46,7 +46,7 @@ repos:
types: [python]

- repo: https://github.com/python-poetry/poetry
rev: 2.0.1
rev: 2.1.1
hooks:
- id: poetry-check
args: ["-C", "api"]
Expand Down
40 changes: 28 additions & 12 deletions api/audit/signals.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import typing

from django.conf import settings
from django.db.models.signals import post_save
Expand All @@ -18,6 +19,33 @@
logger = logging.getLogger(__name__)


AuditLogIntegrationAttrName = typing.Literal[
"data_dog_config",
"dynatrace_config",
"grafana_config",
"new_relic_config",
"slack_config",
]


def _get_integration_config(
instance: AuditLog,
integration_name: AuditLogIntegrationAttrName,
) -> IntegrationsModel | None:
for relation_name in ("project", "environment", "organisation"):
if hasattr(
related_object := getattr(instance, relation_name),
integration_name,
):
integration_config: IntegrationsModel = getattr(
related_object,
integration_name,
)
if not integration_config.deleted:
return integration_config
return None


@receiver(post_save, sender=AuditLog)
def call_webhooks(sender, instance, **kwargs): # type: ignore[no-untyped-def]
if settings.DISABLE_WEBHOOKS:
Expand All @@ -42,18 +70,6 @@ def call_webhooks(sender, instance, **kwargs): # type: ignore[no-untyped-def]
)


def _get_integration_config(
instance: AuditLog, integration_name: str
) -> IntegrationsModel | None:
if hasattr(project := instance.project, integration_name):
return getattr(project, integration_name) # type: ignore[no-any-return]
if hasattr(environment := instance.environment, integration_name):
return getattr(environment, integration_name) # type: ignore[no-any-return]
if hasattr(organisation := instance.organisation, integration_name):
return getattr(organisation, integration_name) # type: ignore[no-any-return]
return None


def track_only_feature_related_events(signal_function): # type: ignore[no-untyped-def]
def signal_wrapper(sender, instance, **kwargs): # type: ignore[no-untyped-def]
# Only handle Feature related changes
Expand Down
26 changes: 26 additions & 0 deletions api/tests/unit/audit/test_unit_audit_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,32 @@ def test_send_audit_log_event_to_grafana__organisation_grafana_config__calls_exp
)


def test_send_audit_log_event_to_grafana__organisation_grafana_config__deleted__doesnt_call(
mocker: MockerFixture,
organisation: Organisation,
project: Project,
) -> None:
# Given
audit_log_record = AuditLog.objects.create(
project=project,
related_object_type=RelatedObjectType.FEATURE.name,
)
grafana_wrapper_mock = mocker.patch("audit.signals.GrafanaWrapper", autospec=True)

grafana_config = GrafanaOrganisationConfiguration.objects.create(
organisation=organisation,
base_url="test.com",
api_key="test",
)
grafana_config.delete()

# When
send_audit_log_event_to_grafana(AuditLog, audit_log_record)

# Then
grafana_wrapper_mock.assert_not_called()


@responses.activate
def test_send_environment_feature_version_audit_log_event_to_grafana(
tagged_feature: Feature,
Expand Down
11 changes: 10 additions & 1 deletion frontend/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ const Constants = {
},
},
exampleAuditWebhook: `{
"created_date": "2020-02-23T17:30:57.006318Z",
"created_date": "2020-02-23T17:30:57.006318Z",
"log": "New Flag / Remote Config created: my_feature",
"author": {
"id": 3,
Expand Down Expand Up @@ -435,6 +435,15 @@ const Constants = {
},
"event_type": "FLAG_UPDATED"
}`,
featurePanelTabs: {
ANALYTICS: 'analytics',
HISTORY: 'history',
IDENTITY_OVERRIDES: 'identity-overrides',
LINKS: 'links',
SEGMENT_OVERRIDES: 'segment-overrides',
SETTINGS: 'settings',
VALUE: 'value',
},
forms: {
maxLength: {
'FEATURE_ID': 150,
Expand Down
1 change: 0 additions & 1 deletion frontend/common/dispatcher/action-constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const Actions = Object.assign({}, require('./base/_action-constants'), {
'GET_FEATURE_USAGE': 'GET_FEATURE_USAGE',
'GET_FLAGS': 'GET_FLAGS',
'GET_IDENTITY': 'GET_IDENTITY',
'GET_IDENTITY_SEGMENTS': 'GET_IDENTITY_SEGMENTS',
'GET_ORGANISATION': 'GET_ORGANISATION',
'GET_PROJECT': 'GET_PROJECT',
'INVALIDATE_INVITE_LINK': 'INVALIDATE_INVITE_LINK',
Expand Down
7 changes: 0 additions & 7 deletions frontend/common/dispatcher/app-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,6 @@ const AppActions = Object.assign({}, require('./base/_app-actions'), {
id,
})
},
getIdentitySegments(projectId, id) {
Dispatcher.handleViewAction({
actionType: Actions.GET_IDENTITY_SEGMENTS,
id,
projectId,
})
},
getOrganisation(organisationId) {
Dispatcher.handleViewAction({
actionType: Actions.GET_ORGANISATION,
Expand Down
42 changes: 0 additions & 42 deletions frontend/common/providers/IdentitySegmentsProvider.js

This file was deleted.

59 changes: 59 additions & 0 deletions frontend/common/services/useIdentitySegment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { Res } from 'common/types/responses'
import { Req } from 'common/types/requests'
import { service } from 'common/service'
import Utils from 'common/utils/utils'
import transformCorePaging from 'common/transformCorePaging'
import { sortBy } from 'lodash'

export const identitySegmentService = service
.enhanceEndpoints({ addTagTypes: ['IdentitySegment'] })
.injectEndpoints({
endpoints: (builder) => ({
getIdentitySegments: builder.query<
Res['identitySegments'],
Req['getIdentitySegments']
>({
providesTags: (res) => [{ id: res?.id, type: 'IdentitySegment' }],
query: ({ projectId, ...query }: Req['getIdentitySegments']) => ({
url: `/projects/${projectId}/segments/?${Utils.toParam(query)}`,
}),
transformResponse: (
res: Res['identitySegments'],
_,
req: Req['getIdentitySegments'],
) =>
transformCorePaging(req, {
...res,
results: sortBy(res.results, 'name'),
}),
}),
// END OF ENDPOINTS
}),
})

export async function getIdentitySegments(
store: any,
data: Req['getIdentitySegments'],
options?: Parameters<
typeof identitySegmentService.endpoints.getIdentitySegments.initiate
>[1],
) {
return store.dispatch(
identitySegmentService.endpoints.getIdentitySegments.initiate(
data,
options,
),
)
}
// END OF FUNCTION_EXPORTS

export const {
useGetIdentitySegmentsQuery,
// END OF EXPORTS
} = identitySegmentService

/* Usage examples:
const { data, isLoading } = useGetIdentitySegmentsQuery({ id: 2 }, {}) //get hook
const [createIdentitySegments, { isLoading, data, isSuccess }] = useCreateIdentitySegmentsMutation() //create hook
identitySegmentService.endpoints.getIdentitySegments.select({id: 2})(store.getState()) //access data from any function
*/
11 changes: 8 additions & 3 deletions frontend/common/stores/feature-list-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -670,12 +670,17 @@ const controller = {
)
}
})
return updatedChangeRequest
},
)
})

Promise.all([prom]).then(() => {
store.saved({ changeRequest: true, isCreate: true })
Promise.all([prom]).then(([updatedChangeRequest]) => {
store.saved({
changeRequest: true,
isCreate: true,
updatedChangeRequest,
})
})
} catch (e) {
API.ajaxHandler(store, e)
Expand Down Expand Up @@ -975,7 +980,7 @@ const controller = {

const store = Object.assign({}, BaseStore, {
getEnvironmentFlags() {
return store.model && store.model.keyedEnvironmentFeatures
return store?.model?.keyedEnvironmentFeatures
},
getFeatureUsage() {
return store.model && store.model.usageData
Expand Down
46 changes: 0 additions & 46 deletions frontend/common/stores/identity-segments-store.js

This file was deleted.

5 changes: 5 additions & 0 deletions frontend/common/types/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -593,5 +593,10 @@ export type Req = {
use_edge_identities: boolean
data: Omit<IdentityTrait, 'trait_value'>
}
getIdentitySegments: PagedRequest<{
q?: string
identity: string
projectId: string
}>
// END OF TYPES
}
12 changes: 6 additions & 6 deletions frontend/common/types/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,18 +456,17 @@ export type ProjectFlag = {

export type FeatureListProviderData = {
projectFlags: ProjectFlag[] | null
environmentFlags: FeatureState[] | null
environmentFlags: Record<number, FeatureState> | undefined
error: boolean
isLoading: boolean
}

export type FeatureListProviderActions = {
toggleFlag: (
index: number,
environments: Environment[],
comment: string | null,
environmentFlags: FeatureState[],
projectFlags: ProjectFlag[],
projectId: string,
environmentId: string,
projectFlag: ProjectFlag,
environmentFlags: FeatureState | undefined,
) => void
removeFlag: (projectId: string, projectFlag: ProjectFlag) => void
}
Expand Down Expand Up @@ -802,6 +801,7 @@ export type Res = {
metadata_xml: string
}
samlAttributeMapping: PagedResponse<SAMLAttributeMapping>
identitySegments: PagedResponse<Segment>
organisationWebhooks: PagedResponse<Webhook>
identityTrait: { id: string }
identityTraits: IdentityTrait[]
Expand Down
Loading

0 comments on commit 23e3be4

Please sign in to comment.