FIX: Prevent from creation of duplicated TopicAllowedUsers (PR #8169)

Something changed in Rails6 and now it behaves correctly. When we try to build a collection object with the same params it creates duplication which later we try to save.

Besides, building that object in the loop when we are doing the same thing 2 lines later is not necessary. (please extend file to see it)

Related to

Screenshot from 2019-10-08 15-42-00


You’ve signed the CLA, lis2. Thank you! This pull request is ready for review.

This is adding not this is the user associated with the post.

So instead, keep track of all the new users in a hash or array and do the addition the end.

users = {}
if ...  
     # allows for deleted users
     user = users[p.user_id] ||= User.find_by(id: p.user_id)
     if user

finally ensuring al these new users exist in topic allowed users...

You are right, my bad. What do you think of instead of building a hash of users, remove duplications just before creation?

does this fix it? Can you add a failing test case here?

@SamSaffron fixed -

OK lets give this a shot!