Skip to content

Commit

Permalink
Merge branch 'staging' into 'master'
Browse files Browse the repository at this point in the history
Staging

See merge request flagsmith/bullet-train-api!313
  • Loading branch information
dabeeeenster committed Mar 11, 2021
2 parents db9a3ac + 7afd9f8 commit 49080f7
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 35 deletions.
1 change: 1 addition & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ build-dockerhub:
- flagsmith-shell-runner
script:
- if [ "$CI_COMMIT_REF_NAME" == "master" ]; then IMAGE_TAG="latest"; else IMAGE_TAG=$CI_COMMIT_REF_SLUG; fi
- if [ "$CI_COMMIT_REF_NAME" == "master" ]; then IMAGE_TAG="latest"; elif [ "$CI_COMMIT_REF_NAME" == "develop" ]; then IMAGE_TAG="develop"; else IMAGE_TAG=$CI_COMMIT_TAG; fi
- echo $CI_COMMIT_REF_NAME > $CI_PROJECT_DIR/src/CI_COMMIT_REF_NAME
- echo $CI_COMMIT_SHA > $CI_PROJECT_DIR/src/CI_COMMIT_SHA
- echo $IMAGE_TAG > $CI_PROJECT_DIR/src/IMAGE_TAG
Expand Down
2 changes: 1 addition & 1 deletion .isort.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ multi_line_output=3
include_trailing_comma=true
line_length=79
known_first_party=analytics,app,custom_auth,environments,integrations,organisations,projects,segments,users,webhooks,api,audit,e2etests,features,permissions,util
known_third_party=apiclient,app_analytics,axes,chargebee,coreapi,corsheaders,dj_database_url,django,djoser,drf_yasg2,environs,google,influxdb_client,ordered_model,pyotp,pytest,pytz,requests,rest_framework,rest_framework_nested,rest_framework_recursive,sentry_sdk,shortuuid,simple_history,six,trench,whitenoise
known_third_party=apiclient,app_analytics,axes,chargebee,core,coreapi,corsheaders,dj_database_url,django,djoser,drf_yasg2,environs,google,influxdb_client,ordered_model,pyotp,pytest,pytz,requests,rest_framework,rest_framework_nested,rest_framework_recursive,sentry_sdk,shortuuid,simple_history,six,trench,whitenoise
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ You can also provide individual variables as below. Note that if a `DATABASE_URL
* `ENV`: string representing the current running environment, e.g. 'local', 'dev', 'prod'. Defaults to 'local'
* `DJANGO_SECRET_KEY`: secret key required by Django, if one isn't provided one will be created using `django.core.management.utilsget_random_secret_key`
* `LOG_LEVEL`: DJANGO logging level. Can be one of `DEBUG`, `INFO`, `WARNING`, `ERROR`, `CRITICAL`
* `ACCESS_LOG_LOCATION`: The location to store web logs generated by gunicorn if running as a Docker container. If not set, no logs will be stored. If set to `-` the logs will be sent to `stdout`.
* `DJANGO_ALLOWED_HOSTS`: comma separated list of hosts the application will run on in the given environment
* `DJANGO_CSRF_TRUSTED_ORIGINS`: comma separated list of hosts to allow unsafe (POST, PUT) requests from. Useful for allowing localhost to set traits in development.
* `DJANGO_SETTINGS_MODULE`: python path to settings file for the given environment, e.g. "app.settings.develop"
Expand Down
2 changes: 0 additions & 2 deletions src/api/urls/v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from environments.identities.views import SDKIdentities
from features.views import SDKFeatureStates
from organisations.views import chargebee_webhook
from segments.views import SDKSegments

schema_view = get_schema_view(
openapi.Info(
Expand Down Expand Up @@ -44,7 +43,6 @@
url(r"^flags/$", SDKFeatureStates.as_view(), name="flags"),
url(r"^identities/$", SDKIdentities.as_view(), name="sdk-identities"),
url(r"^traits/", include(traits_router.urls), name="traits"),
url(r"^segments/$", SDKSegments.as_view()),
url(r"^analytics/flags/$", SDKAnalyticsFlags.as_view()),
# API documentation
url(
Expand Down
2 changes: 1 addition & 1 deletion src/environments/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def _create_audit_log(self, instance, created):
) % instance.name
request = self.context.get("request")
AuditLog.objects.create(
author=request.user if request else None,
author=getattr(request, "user", None),
related_object_id=instance.id,
related_object_type=RelatedObjectType.ENVIRONMENT.name,
environment=instance,
Expand Down
4 changes: 2 additions & 2 deletions src/features/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def _create_audit_log(self, instance, created):
)
request = self.context.get("request")
AuditLog.objects.create(
author=request.user if request else None,
author=getattr(request, "user", None),
related_object_id=instance.id,
related_object_type=RelatedObjectType.FEATURE.name,
project=instance.project,
Expand Down Expand Up @@ -296,7 +296,7 @@ def create_feature_state_audit_log(feature_state, request):
message = FEATURE_STATE_UPDATED_MESSAGE % feature_state.feature.name

AuditLog.objects.create(
author=request.user if request else None,
author=getattr(request, "user", None),
related_object_id=feature_state.id,
related_object_type=RelatedObjectType.FEATURE_STATE.name,
environment=feature_state.environment,
Expand Down
6 changes: 4 additions & 2 deletions src/features/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,9 @@ def create(self, request, *args, **kwargs):
if identity_pk:
data["identity"] = identity_pk

serializer = FeatureStateSerializerBasic(data=data)
serializer = FeatureStateSerializerBasic(
data=data, context=self.get_serializer_context()
)
if serializer.is_valid():
feature_state = serializer.save()
headers = self.get_success_headers(serializer.data)
Expand Down Expand Up @@ -284,7 +286,7 @@ def _create_deleted_feature_state_audit_log(self, feature_state):
)

AuditLog.objects.create(
author=self.request.user if self.request else None,
author=getattr(self.request, "user", None),
related_object_id=feature_state.id,
related_object_type=RelatedObjectType.FEATURE_STATE.name,
environment=feature_state.environment,
Expand Down
2 changes: 1 addition & 1 deletion src/segments/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def _create_audit_log(self, instance, created):
)
request = self.context.get("request")
AuditLog.objects.create(
author=request.user if request else None,
author=getattr(request, "user", None),
related_object_id=instance.id,
related_object_type=RelatedObjectType.SEGMENT.name,
project=instance.project,
Expand Down
30 changes: 4 additions & 26 deletions src/segments/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,18 @@
from drf_yasg2.utils import swagger_auto_schema
from rest_framework import status, viewsets
from rest_framework.generics import get_object_or_404
from rest_framework.permissions import AllowAny
from rest_framework.permissions import AllowAny, IsAuthenticated
from rest_framework.response import Response

from environments.exceptions import EnvironmentHeaderNotPresentError
from environments.identities.models import Identity
from environments.models import Environment
from segments.serializers import SegmentSerializer
from util.views import SDKAPIView

from . import serializers
from .serializers import SegmentSerializer
from .permissions import SegmentPermissions

logger = logging.getLogger()
logger.setLevel(logging.INFO)


@method_decorator(
Expand All @@ -37,8 +35,8 @@
),
)
class SegmentViewSet(viewsets.ModelViewSet):
serializer_class = serializers.SegmentSerializer
permission_classes = [SegmentPermissions]
serializer_class = SegmentSerializer
permission_classes = [IsAuthenticated, SegmentPermissions]

def get_queryset(self):
project = get_object_or_404(
Expand All @@ -55,23 +53,3 @@ def get_queryset(self):
)

return queryset


class SDKSegments(SDKAPIView):
serializer_class = SegmentSerializer
permission_classes = (AllowAny,)

def get(self, request):
try:
environment = Environment.get_environment_from_request(request)
except EnvironmentHeaderNotPresentError:
error = {"detail": "Environment Key header not provided"}
return Response(error, status=status.HTTP_400_BAD_REQUEST)
except ObjectDoesNotExist:
error_response = {"error": "Environment not found for provided key"}
return Response(error_response, status=status.HTTP_400_BAD_REQUEST)

return Response(
self.get_serializer(environment.project.segments.all(), many=True).data,
status=status.HTTP_200_OK,
)

0 comments on commit 49080f7

Please sign in to comment.