app/controllers/groups_controller.rb
# Add/edit/remove users from group membership
Add/edit/remove users from group membership
Add / edit / remove users from group membership
def update_members(members)
    @group.users -= (@group.users - members.keys)
    members.each do |user, role|
      creator = [:creator].include?(role)
      owner = %i[creator owner].include?(role)
      editor = %i[creator owner editor].include?(role)
      gm = @group.membership.where(user: user).first
      update = gm&.owner != owner || gm&.editor != editor
      if !gm || update
        @group.users -= [user] if update
        @group.membership << GroupMembership.new(
          user: user,
          group: @group,
          creator: creator,
          owner: owner,
          editor: editor
        )
      end
    end
  end
def update_members ( members ) @group . users -= ( @group . users - members . keys ) members . each do | user , role | creator = [ :creator ] . include? ( role ) owner = %i[ creator owner ] . include? ( role ) editor = %i[ creator owner editor ] . include? ( role ) gm = @group . membership . where ( user : user ) . first update = gm &. owner != owner || gm &. editor != editor if ! gm || update @group . users -= [ user ] if update @group . membership << GroupMembership . new ( user : user , group : @group , creator : creator , owner : owner , editor : editor ) end end end
Add/edit/remove users from group membership
Add / edit / remove users from group membership
# Remove any users no longer listed # Add/edit the new list of users # Existing user - remove old membership before re-adding
members
<not_specific>