mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	Users wanted a feature where they could specify which users can create public streams and which users can create private streams. This splits stream creation code into two parts, public and private stream creation. Fixes #17009.
		
			
				
	
	
		
			47 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			47 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
from django.db import migrations, models
 | 
						|
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
 | 
						|
from django.db.migrations.state import StateApps
 | 
						|
from django.db.models import F
 | 
						|
 | 
						|
 | 
						|
def copy_stream_policy_field(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
 | 
						|
    Realm = apps.get_model("zerver", "Realm")
 | 
						|
    Realm.objects.all().update(create_public_stream_policy=F("create_stream_policy"))
 | 
						|
    Realm.objects.all().update(create_private_stream_policy=F("create_stream_policy"))
 | 
						|
 | 
						|
 | 
						|
# When reversing the migration, we have to pick one of the new fields
 | 
						|
# to store in the original field name. This does destroy information,
 | 
						|
# but in most cases downgrades that would reverse migrations happen
 | 
						|
# before any real usage, so it's very likely that both values are
 | 
						|
# identical.
 | 
						|
def reverse_code(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
 | 
						|
    Realm = apps.get_model("zerver", "Realm")
 | 
						|
    Realm.objects.all().update(create_stream_policy=F("create_public_stream_policy"))
 | 
						|
 | 
						|
 | 
						|
class Migration(migrations.Migration):
 | 
						|
    atomic = False
 | 
						|
 | 
						|
    dependencies = [
 | 
						|
        ("zerver", "0357_remove_realm_allow_message_deleting"),
 | 
						|
    ]
 | 
						|
 | 
						|
    operations = [
 | 
						|
        migrations.AddField(
 | 
						|
            model_name="realm",
 | 
						|
            name="create_private_stream_policy",
 | 
						|
            field=models.PositiveSmallIntegerField(default=1),
 | 
						|
        ),
 | 
						|
        migrations.AddField(
 | 
						|
            model_name="realm",
 | 
						|
            name="create_public_stream_policy",
 | 
						|
            field=models.PositiveSmallIntegerField(default=1),
 | 
						|
        ),
 | 
						|
        migrations.RunPython(copy_stream_policy_field, reverse_code=reverse_code, elidable=True),
 | 
						|
        migrations.RemoveField(
 | 
						|
            model_name="realm",
 | 
						|
            name="create_stream_policy",
 | 
						|
        ),
 | 
						|
    ]
 |