Assignee can only be user who is not a bot or Team (#14251)

This commit is contained in:
Mohit Yadav 2023-12-05 21:04:18 +05:30 committed by GitHub
parent b3578cd496
commit 8486b351f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -280,6 +280,7 @@ public class FeedRepository {
private Thread createThread(ThreadContext threadContext) {
Thread thread = threadContext.getThread();
if (thread.getType() == ThreadType.Task) {
validateAssignee(thread);
thread.getTask().withId(getNextTaskId());
} else if (thread.getType() == ThreadType.Announcement) {
// Validate start and end time for announcement
@ -756,6 +757,30 @@ public class FeedRepository {
}
}
private void validateAssignee(Thread thread) {
if (thread != null && ThreadType.Task.equals(thread.getType())) {
List<EntityReference> assignees = thread.getTask().getAssignees();
// Assignees can only be user or teams
assignees.forEach(
assignee -> {
if (!assignee.getType().equals(Entity.USER) && !assignee.getType().equals(Entity.TEAM)) {
throw new IllegalArgumentException("Assignees can only be user or teams");
}
});
for (EntityReference ref : assignees) {
EntityRepository<?> repository = Entity.getEntityRepository(ref.getType());
if (ref.getType().equals(USER)) {
User user = (User) repository.get(null, ref.getId(), repository.getFields("id"));
if (Boolean.TRUE.equals(user.getIsBot())) {
throw new IllegalArgumentException("Assignees can not be bot");
}
}
}
}
}
private void restorePatchAttributes(Thread original, Thread updated) {
// Patch can't make changes to following fields. Ignore the changes
updated.withId(original.getId()).withAbout(original.getAbout()).withType(original.getType());