3636 State ,
3737 IssueVersion ,
3838 IssueDescriptionVersion ,
39+ ProjectMember ,
3940)
4041
4142
@@ -119,6 +120,17 @@ def validate(self, data):
119120 raise serializers .ValidationError ("Start date cannot exceed target date" )
120121 return data
121122
123+ def get_valid_assignees (self , assignees , project_id ):
124+ if not assignees :
125+ return []
126+
127+ return ProjectMember .objects .filter (
128+ project_id = project_id ,
129+ role__gte = 15 ,
130+ is_active = True ,
131+ member_id__in = assignees
132+ ).values_list ('member_id' , flat = True )
133+
122134 def create (self , validated_data ):
123135 assignees = validated_data .pop ("assignee_ids" , None )
124136 labels = validated_data .pop ("label_ids" , None )
@@ -134,27 +146,33 @@ def create(self, validated_data):
134146 created_by_id = issue .created_by_id
135147 updated_by_id = issue .updated_by_id
136148
137- if assignees is not None and len (assignees ):
149+ valid_assignee_ids = self .get_valid_assignees (assignees , project_id )
150+ if valid_assignee_ids is not None and len (valid_assignee_ids ):
138151 try :
139152 IssueAssignee .objects .bulk_create (
140153 [
141154 IssueAssignee (
142- assignee = user ,
155+ assignee_id = user_id ,
143156 issue = issue ,
144157 project_id = project_id ,
145158 workspace_id = workspace_id ,
146159 created_by_id = created_by_id ,
147160 updated_by_id = updated_by_id ,
148161 )
149- for user in assignees
162+ for user_id in valid_assignee_ids
150163 ],
151164 batch_size = 10 ,
152165 )
153166 except IntegrityError :
154167 pass
155168 else :
156- # Then assign it to default assignee
157- if default_assignee_id is not None :
169+ # Then assign it to default assignee, if it is a valid assignee
170+ if default_assignee_id is not None and ProjectMember .objects .filter (
171+ member_id = default_assignee_id ,
172+ project_id = project_id ,
173+ role__gte = 15 ,
174+ is_active = True
175+ ).exists ():
158176 try :
159177 IssueAssignee .objects .create (
160178 assignee_id = default_assignee_id ,
@@ -198,20 +216,21 @@ def update(self, instance, validated_data):
198216 created_by_id = instance .created_by_id
199217 updated_by_id = instance .updated_by_id
200218
201- if assignees is not None :
219+ valid_assignee_ids = self .get_valid_assignees (assignees , project_id )
220+ if valid_assignee_ids is not None and len (valid_assignee_ids ):
202221 IssueAssignee .objects .filter (issue = instance ).delete ()
203222 try :
204223 IssueAssignee .objects .bulk_create (
205224 [
206225 IssueAssignee (
207- assignee = user ,
226+ assignee_id = user_id ,
208227 issue = instance ,
209228 project_id = project_id ,
210229 workspace_id = workspace_id ,
211230 created_by_id = created_by_id ,
212231 updated_by_id = updated_by_id ,
213232 )
214- for user in assignees
233+ for user_id in valid_assignee_ids
215234 ],
216235 batch_size = 10 ,
217236 ignore_conflicts = True ,
0 commit comments