class Eco::API::UseCases::DefaultCases::RefreshAbilitiesCase < Eco::API::Common::Loaders::UseCase name "refresh-abilities" type :transform # Usecase to refresh the user's account abilities as defined in the org config for their usergroups. # @param people [Eco::API::Organization::People] target existing _People_ of the current update. # @param session [Eco::API::Session] the current session where the usecase kicks in. # @param options [Hash] the options that modify the case behaviour or bring some dependencies. # @return [Void] def main(people, session, options, usecase) users = require_users!(people, session.logger) update = session.new_job("main", "update", :update, usecase, :account) users.each do |person| person.account.permissions_custom = session.new_preset(person) update.add(person) end end private def require_users!(people, logger) people.users.tap do |users| unless users.length > 0 logger.warn("There are no people with account amoung your #{people.length} people") exit(1) end end end end