Skip to content

Commit fcc3af0

Browse files
committed
refactor: clean up channel invitation models, serializers, and migration
Signed-off-by: Pranav dhiran <dhiranpranav72@gmail.com>
1 parent 45e08a0 commit fcc3af0

3 files changed

Lines changed: 63 additions & 120 deletions

File tree

src/api-engine/channel/migrations/0002_channel_invitation.py

Lines changed: 18 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# Generated by Django 4.2.16 on 2026-05-11
2-
31
import common.utils
42
from django.db import migrations, models
53
import django.db.models.deletion
@@ -19,11 +17,9 @@ class Migration(migrations.Migration):
1917
"id",
2018
models.UUIDField(
2119
default=common.utils.make_uuid,
22-
editable=False,
2320
help_text="Channel Invitation ID",
2421
primary_key=True,
2522
serialize=False,
26-
unique=True,
2723
),
2824
),
2925
(
@@ -47,7 +43,7 @@ class Migration(migrations.Migration):
4743
"artifact",
4844
models.FileField(
4945
blank=True,
50-
help_text="Stored channel update artifact",
46+
help_text="Update Artifact",
5147
null=True,
5248
upload_to="channel_invitations/",
5349
),
@@ -57,43 +53,37 @@ class Migration(migrations.Migration):
5753
models.CharField(
5854
blank=True,
5955
default="",
60-
help_text="SHA256 hash of the stored artifact",
56+
help_text="Artifact Hash",
6157
max_length=64,
6258
),
6359
),
6460
(
6561
"required_signatures",
6662
models.PositiveSmallIntegerField(
6763
default=0,
68-
help_text="Number of member signatures required",
64+
help_text="Required Signatures",
6965
),
7066
),
7167
(
7268
"error_message",
7369
models.TextField(
7470
blank=True,
7571
default="",
76-
help_text="Latest invitation processing error",
72+
help_text="Error Message",
7773
),
7874
),
7975
(
8076
"created_at",
81-
models.DateTimeField(
82-
auto_now_add=True,
83-
help_text="Channel Invitation Creation Timestamp",
84-
),
77+
models.DateTimeField(auto_now_add=True),
8578
),
8679
(
8780
"updated_at",
88-
models.DateTimeField(
89-
auto_now=True,
90-
help_text="Channel Invitation Update Timestamp",
91-
),
81+
models.DateTimeField(auto_now=True),
9282
),
9383
(
9484
"channel",
9585
models.ForeignKey(
96-
help_text="Channel to invite organizations into",
86+
help_text="Invitation Channel",
9787
on_delete=django.db.models.deletion.CASCADE,
9888
related_name="invitations",
9989
to="channel.channel",
@@ -102,9 +92,9 @@ class Migration(migrations.Migration):
10292
(
10393
"creator_organization",
10494
models.ForeignKey(
105-
help_text="Organization that created the invitation",
95+
help_text="Creator Organization",
10696
on_delete=django.db.models.deletion.CASCADE,
107-
related_name="created_channel_invitations",
97+
related_name="created_invitations",
10898
to="organization.organization",
10999
),
110100
),
@@ -120,31 +110,26 @@ class Migration(migrations.Migration):
120110
"id",
121111
models.UUIDField(
122112
default=common.utils.make_uuid,
123-
editable=False,
124113
help_text="Channel Invitation Signature ID",
125114
primary_key=True,
126115
serialize=False,
127-
unique=True,
128116
),
129117
),
130118
(
131119
"artifact_hash",
132120
models.CharField(
133-
help_text="SHA256 hash of the signed artifact",
121+
help_text="Artifact Hash",
134122
max_length=64,
135123
),
136124
),
137125
(
138126
"signed_at",
139-
models.DateTimeField(
140-
auto_now_add=True,
141-
help_text="Signature Timestamp",
142-
),
127+
models.DateTimeField(auto_now_add=True),
143128
),
144129
(
145130
"invitation",
146131
models.ForeignKey(
147-
help_text="Channel invitation",
132+
help_text="Invitation",
148133
on_delete=django.db.models.deletion.CASCADE,
149134
related_name="signatures",
150135
to="channel.channelinvitation",
@@ -153,11 +138,9 @@ class Migration(migrations.Migration):
153138
(
154139
"organization",
155140
models.ForeignKey(
156-
help_text=(
157-
"Organization that signed the invitation artifact"
158-
),
141+
help_text="Signing Organization",
159142
on_delete=django.db.models.deletion.CASCADE,
160-
related_name="channel_invitation_signatures",
143+
related_name="invitation_signatures",
161144
to="organization.organization",
162145
),
163146
),
@@ -173,11 +156,9 @@ class Migration(migrations.Migration):
173156
"id",
174157
models.UUIDField(
175158
default=common.utils.make_uuid,
176-
editable=False,
177159
help_text="Channel Invitation Invitee ID",
178160
primary_key=True,
179161
serialize=False,
180-
unique=True,
181162
),
182163
),
183164
(
@@ -189,22 +170,21 @@ class Migration(migrations.Migration):
189170
("REJECTED", "Rejected"),
190171
],
191172
default="PENDING",
192-
help_text="Invited organization response status",
173+
help_text="Invitee Status",
193174
max_length=32,
194175
),
195176
),
196177
(
197178
"responded_at",
198179
models.DateTimeField(
199180
blank=True,
200-
help_text="Invitee Response Timestamp",
201181
null=True,
202182
),
203183
),
204184
(
205185
"invitation",
206186
models.ForeignKey(
207-
help_text="Channel invitation",
187+
help_text="Invitation",
208188
on_delete=django.db.models.deletion.CASCADE,
209189
related_name="invitees",
210190
to="channel.channelinvitation",
@@ -213,9 +193,9 @@ class Migration(migrations.Migration):
213193
(
214194
"organization",
215195
models.ForeignKey(
216-
help_text="Invited organization",
196+
help_text="Invited Organization",
217197
on_delete=django.db.models.deletion.CASCADE,
218-
related_name="channel_invitations",
198+
related_name="invitee_invitations",
219199
to="organization.organization",
220200
),
221201
),

src/api-engine/channel/models.py

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,10 @@ class Meta:
3030

3131
class ChannelInvitationQuerySet(models.QuerySet):
3232
def visible_to_organization(self, organization: Organization):
33-
invitee_visible_statuses = (
34-
ChannelInvitation.Status.READY,
35-
ChannelInvitation.Status.ACCEPTED,
36-
ChannelInvitation.Status.REJECTED,
37-
ChannelInvitation.Status.FAILED,
38-
)
3933
return self.filter(
4034
Q(channel__organizations=organization)
4135
| Q(
42-
status__in=invitee_visible_statuses,
36+
status__in=("READY", "ACCEPTED", "REJECTED", "FAILED"),
4337
invitees__organization=organization,
4438
)
4539
).distinct()
@@ -59,19 +53,17 @@ class Status(models.TextChoices):
5953
primary_key=True,
6054
help_text="Channel Invitation ID",
6155
default=make_uuid,
62-
editable=False,
63-
unique=True,
6456
)
6557
channel = models.ForeignKey(
6658
Channel,
67-
help_text="Channel to invite organizations into",
59+
help_text="Invitation Channel",
6860
related_name="invitations",
6961
on_delete=models.CASCADE,
7062
)
7163
creator_organization = models.ForeignKey(
7264
Organization,
73-
help_text="Organization that created the invitation",
74-
related_name="created_channel_invitations",
65+
help_text="Creator Organization",
66+
related_name="created_invitations",
7567
on_delete=models.CASCADE,
7668
)
7769
status = models.CharField(
@@ -81,32 +73,30 @@ class Status(models.TextChoices):
8173
max_length=32,
8274
)
8375
artifact = models.FileField(
84-
help_text="Stored channel update artifact",
76+
help_text="Update Artifact",
8577
upload_to="channel_invitations/",
8678
null=True,
8779
blank=True,
8880
)
8981
artifact_hash = models.CharField(
90-
help_text="SHA256 hash of the stored artifact",
82+
help_text="Artifact Hash",
9183
max_length=64,
9284
blank=True,
9385
default="",
9486
)
9587
required_signatures = models.PositiveSmallIntegerField(
96-
help_text="Number of member signatures required",
88+
help_text="Required Signatures",
9789
default=0,
9890
)
9991
error_message = models.TextField(
100-
help_text="Latest invitation processing error",
92+
help_text="Error Message",
10193
blank=True,
10294
default="",
10395
)
10496
created_at = models.DateTimeField(
105-
help_text="Channel Invitation Creation Timestamp",
10697
auto_now_add=True,
10798
)
10899
updated_at = models.DateTimeField(
109-
help_text="Channel Invitation Update Timestamp",
110100
auto_now=True,
111101
)
112102

@@ -126,29 +116,26 @@ class Status(models.TextChoices):
126116
primary_key=True,
127117
help_text="Channel Invitation Invitee ID",
128118
default=make_uuid,
129-
editable=False,
130-
unique=True,
131119
)
132120
invitation = models.ForeignKey(
133121
ChannelInvitation,
134-
help_text="Channel invitation",
122+
help_text="Invitation",
135123
related_name="invitees",
136124
on_delete=models.CASCADE,
137125
)
138126
organization = models.ForeignKey(
139127
Organization,
140-
help_text="Invited organization",
141-
related_name="channel_invitations",
128+
help_text="Invited Organization",
129+
related_name="invitee_invitations",
142130
on_delete=models.CASCADE,
143131
)
144132
status = models.CharField(
145-
help_text="Invited organization response status",
133+
help_text="Invitee Status",
146134
choices=Status.choices,
147135
default=Status.PENDING,
148136
max_length=32,
149137
)
150138
responded_at = models.DateTimeField(
151-
help_text="Invitee Response Timestamp",
152139
null=True,
153140
blank=True,
154141
)
@@ -168,27 +155,24 @@ class ChannelInvitationSignature(models.Model):
168155
primary_key=True,
169156
help_text="Channel Invitation Signature ID",
170157
default=make_uuid,
171-
editable=False,
172-
unique=True,
173158
)
174159
invitation = models.ForeignKey(
175160
ChannelInvitation,
176-
help_text="Channel invitation",
161+
help_text="Invitation",
177162
related_name="signatures",
178163
on_delete=models.CASCADE,
179164
)
180165
organization = models.ForeignKey(
181166
Organization,
182-
help_text="Organization that signed the invitation artifact",
183-
related_name="channel_invitation_signatures",
167+
help_text="Signing Organization",
168+
related_name="invitation_signatures",
184169
on_delete=models.CASCADE,
185170
)
186171
artifact_hash = models.CharField(
187-
help_text="SHA256 hash of the signed artifact",
172+
help_text="Artifact Hash",
188173
max_length=64,
189174
)
190175
signed_at = models.DateTimeField(
191-
help_text="Signature Timestamp",
192176
auto_now_add=True,
193177
)
194178

0 commit comments

Comments
 (0)