Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion migrations_lockfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ hybridcloud: 0016_add_control_cacheversion
nodestore: 0002_nodestore_no_dictfield
remote_subscriptions: 0003_drop_remote_subscription
replays: 0004_index_together
sentry: 0745_add_prevent_superuser_access_bitflag
sentry: 0746_add_bitflags_to_hybrid_cloud
social_auth: 0002_default_auto_field
uptime: 0006_projectuptimesubscription_name_owner
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ def upsert(self, organization_id: int, update: RpcOrganizationMappingUpdate) ->
disable_new_visibility_features=update.disable_new_visibility_features,
require_email_verification=update.require_email_verification,
codecov_access=update.codecov_access,
disable_member_project_creation=update.disable_member_project_creation,
prevent_superuser_access=update.prevent_superuser_access,
)
if isinstance(update.customer_id, CustomerId):
update_dict["customer_id"] = update.customer_id.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ class RpcOrganizationMappingUpdate(RpcModel):
disable_new_visibility_features: bool = False
enhanced_privacy: bool = False
require_email_verification: bool = False
disable_member_project_creation: bool = False
prevent_superuser_access: bool = False
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ def update_organization_mapping_from_instance(
disable_new_visibility_features=bool(organization.flags.disable_new_visibility_features),
enhanced_privacy=bool(organization.flags.enhanced_privacy),
require_email_verification=bool(organization.flags.require_email_verification),
disable_member_project_creation=bool(organization.flags.disable_member_project_creation),
prevent_superuser_access=bool(organization.flags.prevent_superuser_access),
customer_id=customer_id,
)

Expand Down Expand Up @@ -56,4 +58,6 @@ def serialize_organization_mapping_flags(
disable_new_visibility_features=org_mapping.disable_new_visibility_features,
require_email_verification=org_mapping.require_email_verification,
codecov_access=org_mapping.codecov_access,
disable_member_project_creation=org_mapping.disable_member_project_creation,
prevent_superuser_access=org_mapping.prevent_superuser_access,
)
57 changes: 57 additions & 0 deletions src/sentry/migrations/0746_add_bitflags_to_hybrid_cloud.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Generated by Django 5.0.6 on 2024-07-24 21:03

from django.db import migrations, models

from sentry.new_migrations.migrations import CheckedMigration


class Migration(CheckedMigration):
# This flag is used to mark that a migration shouldn't be automatically run in production.
# This should only be used for operations where it's safe to run the migration after your
# code has deployed. So this should not be used for most operations that alter the schema
# of a table.
# Here are some things that make sense to mark as post deployment:
# - Large data migrations. Typically we want these to be run manually so that they can be
# monitored and not block the deploy for a long period of time while they run.
# - Adding indexes to large tables. Since this can take a long time, we'd generally prefer to
# run this outside deployments so that we don't block them. Note that while adding an index
# is a schema change, it's completely safe to run the operation after the code has deployed.
# Once deployed, run these manually via: https://develop.sentry.dev/database-migrations/#migration-deployment

is_post_deployment = False

dependencies = [
("sentry", "0745_add_prevent_superuser_access_bitflag"),
]

operations = [
migrations.SeparateDatabaseAndState(
database_operations=[
migrations.RunSQL(
"""
ALTER TABLE "sentry_organizationmapping"
ADD COLUMN "disable_member_project_creation" boolean NOT NULL DEFAULT false,
ADD COLUMN "prevent_superuser_access" boolean NOT NULL DEFAULT false;
""",
reverse_sql="""
ALTER TABLE "sentry_organizationmapping"
DROP COLUMN "disable_member_project_creation",
DROP COLUMN "prevent_superuser_access";
""",
hints={"tables": ["sentry_organizationmapping"]},
),
],
state_operations=[
migrations.AddField(
model_name="organizationmapping",
name="disable_member_project_creation",
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name="organizationmapping",
name="prevent_superuser_access",
field=models.BooleanField(default=False),
),
],
)
]
2 changes: 2 additions & 0 deletions src/sentry/models/organizationmapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class OrganizationMapping(Model):
disable_new_visibility_features = models.BooleanField(default=False)
require_email_verification = models.BooleanField(default=False)
codecov_access = models.BooleanField(default=False)
disable_member_project_creation = models.BooleanField(default=False)
prevent_superuser_access = models.BooleanField(default=False)

class Meta:
app_label = "sentry"
Expand Down
4 changes: 4 additions & 0 deletions src/sentry/organizations/services/organization/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ class RpcOrganizationMappingFlags(RpcModel):
disable_new_visibility_features: bool = False
require_email_verification: bool = False
codecov_access: bool = False
disable_member_project_creation: bool = False
prevent_superuser_access: bool = False


class RpcOrganizationFlags(RpcOrganizationMappingFlags):
Expand All @@ -187,6 +189,8 @@ def as_int(self) -> int:
self.disable_new_visibility_features,
self.require_email_verification,
self.codecov_access,
self.disable_member_project_creation,
self.prevent_superuser_access,
)


Expand Down
4 changes: 4 additions & 0 deletions tests/sentry/hybridcloud/test_organizationmapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def assert_matching_organization_mapping(
)
assert org_mapping.require_email_verification == bool(org.flags.require_email_verification)
assert org_mapping.codecov_access == bool(org.flags.codecov_access)
assert org_mapping.disable_member_project_creation == bool(
org.flags.disable_member_project_creation
)
assert org_mapping.prevent_superuser_access == bool(org.flags.prevent_superuser_access)


@control_silo_test(regions=create_test_regions("us"), include_monolith_run=True)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pytest

from sentry.models.groupsearchview import GroupSearchView
from sentry.models.savedsearch import SavedSearch
from sentry.testutils.cases import TestMigrations
Expand All @@ -19,6 +21,7 @@ def setup_initial_state(self):
sort="date",
)

@pytest.mark.skip(reason="old migration test")
Copy link
Member

Choose a reason for hiding this comment

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

If these tests don't work anymore, why not delete them?

Copy link
Member

Choose a reason for hiding this comment

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

I think it's helpful to keep some around as an example, but we could delete old skipped tests after a while

def test(self):
custom_views = GroupSearchView.objects.filter(organization=self.org, user_id=self.user.id)
assert custom_views.count() == 2
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pytest
from django.conf import settings
from snuba_sdk.legacy import json_to_snql

Expand Down Expand Up @@ -49,6 +50,7 @@ def setup_initial_state(self):

self.group.update(first_release=release)

@pytest.mark.skip(reason="old migration test")
def test(self):
run_test([self.group, self.group_2])

Expand All @@ -63,5 +65,6 @@ def setup_initial_state(self):
redis_client = redis.redis_clusters.get(settings.SENTRY_MONITORS_REDIS_CLUSTER)
redis_client.set("backfill_group_info_to_group_attributes", self.group.id)

@pytest.mark.skip(reason="old migration test")
def test_restart(self):
run_test([self.group_2])