Check if user is bot before updateOrCreate bot user (#10178)

This commit is contained in:
Nahuel 2023-02-10 17:40:07 +01:00 committed by GitHub
parent 2a99114c94
commit fc78d03cc4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1138,7 +1138,9 @@ public class UserResource extends EntityResource<User, UserRepository> {
String botName = create.getBotName();
EntityInterface bot = retrieveBot(botName);
// check if the bot user exists
if (!botHasRelationshipWithUser(bot, original)
if (original != null && (original.getIsBot() == null || Boolean.FALSE.equals(original.getIsBot()))) {
throw new IllegalArgumentException(String.format("User [%s] already exists.", original.getName()));
} else if (!botHasRelationshipWithUser(bot, original)
&& original != null
&& userHasRelationshipWithAnyBot(original, bot)) {
// throw an exception if user already has a relationship with a bot