module Eco module API class UseCases class DefaultCases class AppendUsergroupsCase < DefaultCase def process @cases.define("append-usergroups", type: :sync) do |entries, people, session, options, usecase| update = session.job_group("main").new("update", usecase: usecase, type: :update, sets: [:core, :details, :account]) strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict)) pgs = session.policy_groups entries.each.with_index do |entry, i| if person = people.find(entry, strict: strict_search) if person.account ini_pg_ids = person.account&.policy_group_ids || [] add = entry.internal_entry["policy_group_ids"].split("|").compact person.account.policy_group_ids = (ini_pg_ids | add).uniq person.account.permissions_custom = session.new_preset(person) unless options.dig(:exclude, :abilities) update.add(person) end else session.logger.error("Entry(#{i}) - this person does not exist: #{entry.to_s(:identify)}") end end end end end end end end end