eco-helpers 1.3.7 → 1.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +35 -0
- data/lib/eco/api/common/people/person_entry.rb +5 -1
- data/lib/eco/api/policies.rb +2 -1
- data/lib/eco/api/session/batch/job.rb +1 -1
- data/lib/eco/api/session/config/people.rb +8 -0
- data/lib/eco/api/usecases/default_cases/create_case.rb +26 -6
- data/lib/eco/api/usecases/default_cases/hris_case.rb +18 -4
- data/lib/eco/api/usecases/default_cases/reinvite_case.rb +5 -3
- data/lib/eco/api/usecases/default_cases/update_case.rb +2 -1
- data/lib/eco/api/usecases/default_cases/upsert_case.rb +16 -2
- data/lib/eco/api/usecases/use_case_io.rb +5 -9
- data/lib/eco/version.rb +1 -1
- metadata +2 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 4eb9a6d4fc09ab97362ab384856a32562c1f61321277e2537f1cc6859a5a4d54
         | 
| 4 | 
            +
              data.tar.gz: 550fd9ce9a7510dca05bbcd80c153d7c114a25798e5d5af89059351db13f4b7d
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: ef1c26368f22e5b06ead30ab4aeb042d337fbfb5cd2b68369aa1407350993e38109e7cfde86295e046fcbcc5295a87a97da3cefd91873460cd7a3e535471afb1
         | 
| 7 | 
            +
              data.tar.gz: 84f36840162ec228b41a923476aae26917ab1254c4c4e86e848b9b276ea84f0e1a33a69f9c0e8c15497262cebfd99151b91a6dd7a2b7779105096ee97593285d
         | 
    
        data/CHANGELOG.md
    ADDED
    
    | @@ -0,0 +1,35 @@ | |
| 1 | 
            +
            # Change Log
         | 
| 2 | 
            +
            All notable changes to this project will be documented in this file.
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            ## [1.3.8] - 2020-05-DD (Unreleased)
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            ### Added
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            - this change log file
         | 
| 9 | 
            +
            - `config.people.default_usergroup`, when defined, will have effect on usecases: `create`, `upsert` and `hris`
         | 
| 10 | 
            +
              * on account creation, if the input file did not specify `policy_group_ids`
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            ### Changed
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            - `policy` callback to receive new parameter with the `Batch::Job` that it is currently processing/checking
         | 
| 15 | 
            +
             | 
| 16 | 
            +
            **Example of usage**
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            ```ruby
         | 
| 19 | 
            +
            ASSETS.config.policies do |policies|
         | 
| 20 | 
            +
              policies.define("update-status") do |people, session, options, policy, job|
         | 
| 21 | 
            +
                if job.type == :create
         | 
| 22 | 
            +
                  people.each do |person|
         | 
| 23 | 
            +
                    person.details["status"] = "Active" if person.details
         | 
| 24 | 
            +
                  end
         | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
                if job.name == "leavers"
         | 
| 27 | 
            +
                  person.details["status"] = "Inactive" if person.details
         | 
| 28 | 
            +
                end
         | 
| 29 | 
            +
              end
         | 
| 30 | 
            +
            end
         | 
| 31 | 
            +
            ```
         | 
| 32 | 
            +
             | 
| 33 | 
            +
            ### Fixed
         | 
| 34 | 
            +
             | 
| 35 | 
            +
            - `reinvite` `:sync` native usecase (`-reinvite-from`): should skip people with no account.
         | 
| @@ -106,6 +106,10 @@ module Eco | |
| 106 106 | 
             
                        @internal_entry.key?("filter_tags")
         | 
| 107 107 | 
             
                      end
         | 
| 108 108 |  | 
| 109 | 
            +
                      def policy_group_ids?
         | 
| 110 | 
            +
                        @internal_entry.key?("policy_group_ids")
         | 
| 111 | 
            +
                      end
         | 
| 112 | 
            +
             | 
| 109 113 | 
             
                      def default_tag?
         | 
| 110 114 | 
             
                        @internal_entry.key?("default_tag")
         | 
| 111 115 | 
             
                      end
         | 
| @@ -113,7 +117,7 @@ module Eco | |
| 113 117 | 
             
                      def default_tag
         | 
| 114 118 | 
             
                        @internal_entry["default_tag"]
         | 
| 115 119 | 
             
                      end
         | 
| 116 | 
            -
             | 
| 120 | 
            +
             | 
| 117 121 | 
             
                      # Provides a reference of this person.
         | 
| 118 122 | 
             
                      # @return [String] string summary of this person identity.
         | 
| 119 123 | 
             
                      def to_s(options)
         | 
    
        data/lib/eco/api/policies.rb
    CHANGED
    
    
| @@ -229,7 +229,7 @@ module Eco | |
| 229 229 | 
             
                        people(pre_queue).tap do |entries|
         | 
| 230 230 | 
             
                          policies = session.config.policies
         | 
| 231 231 | 
             
                          unless policies.empty? || options.dig(:skip, :api_policies)
         | 
| 232 | 
            -
                            policies.launch(people: entries, session: session, options: options)
         | 
| 232 | 
            +
                            policies.launch(people: entries, session: session, options: options, job: self)
         | 
| 233 233 | 
             
                          end
         | 
| 234 234 | 
             
                        end
         | 
| 235 235 | 
             
                      end
         | 
| @@ -71,6 +71,10 @@ module Eco | |
| 71 71 | 
             
                        self["default_usergroup"]
         | 
| 72 72 | 
             
                      end
         | 
| 73 73 |  | 
| 74 | 
            +
                      def default_usergroup?
         | 
| 75 | 
            +
                        !!self["default_usergroup"]
         | 
| 76 | 
            +
                      end
         | 
| 77 | 
            +
             | 
| 74 78 | 
             
                      def default_schema=(name)
         | 
| 75 79 | 
             
                        self["default_schema"] = name
         | 
| 76 80 | 
             
                      end
         | 
| @@ -79,6 +83,10 @@ module Eco | |
| 79 83 | 
             
                        self["default_schema"]
         | 
| 80 84 | 
             
                      end
         | 
| 81 85 |  | 
| 86 | 
            +
                      def default_schema?
         | 
| 87 | 
            +
                        !!self["default_schema"]
         | 
| 88 | 
            +
                      end
         | 
| 89 | 
            +
             | 
| 82 90 | 
             
                      def presets_custom=(file)
         | 
| 83 91 | 
             
                        self["presets_custom"] = file
         | 
| 84 92 | 
             
                      end
         | 
| @@ -12,6 +12,10 @@ module Eco | |
| 12 12 | 
             
                          strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
         | 
| 13 13 | 
             
                          pgs = session.policy_groups
         | 
| 14 14 |  | 
| 15 | 
            +
                          if session.config.people.default_usergroup?
         | 
| 16 | 
            +
                            def_id  = pgs.to_id(session.config.people.default_usergroup)
         | 
| 17 | 
            +
                          end
         | 
| 18 | 
            +
             | 
| 15 19 | 
             
                          entries.each.with_index do |entry, i|
         | 
| 16 20 | 
             
                            if person = people.find(entry, strict: strict_search)
         | 
| 17 21 | 
             
                              session.logger.error("Entry(#{i}) - this person (id: '#{person.id}') already exists: #{entry.to_s(:identify)}")
         | 
| @@ -34,15 +38,31 @@ module Eco | |
| 34 38 | 
             
                              entry.set_details(person) unless options.dig(:exclude, :details)
         | 
| 35 39 |  | 
| 36 40 | 
             
                              unless options.dig(:exclude, :account)
         | 
| 37 | 
            -
                                 | 
| 38 | 
            -
                                 | 
| 41 | 
            +
                                add_account = !person.account
         | 
| 42 | 
            +
                                ini_pg_ids  = person.account&.policy_group_ids || []
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                                account_excluded = []
         | 
| 45 | 
            +
                                account_excluded.push("policy_group_ids") if options.dig(:exclude, :policy_groups) && !create
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                                entry.set_account(person, exclude: account_excluded)
         | 
| 39 48 |  | 
| 40 49 | 
             
                                person.account&.send_invites = options[:send_invites] if options.key?(:send_invites)
         | 
| 41 50 |  | 
| 42 | 
            -
                                 | 
| 43 | 
            -
                                   | 
| 44 | 
            -
             | 
| 45 | 
            -
             | 
| 51 | 
            +
                                unless options.dig(:exclude, :policy_groups) && !create
         | 
| 52 | 
            +
                                  end_pg_ids = person.account.policy_group_ids || []
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                                  unless entry.policy_group_ids? && !add_account && !def_id
         | 
| 55 | 
            +
                                    # on account creation, if missing policy_group_ids column in the input
         | 
| 56 | 
            +
                                    # use default_usergroup, if it's defined
         | 
| 57 | 
            +
                                    end_pg_ids = [def_id]
         | 
| 58 | 
            +
                                  end
         | 
| 59 | 
            +
             | 
| 60 | 
            +
                                  # avoid false updates by preserving the original order
         | 
| 61 | 
            +
                                  person.account.policy_group_ids   = pgs.user_pg_ids(
         | 
| 62 | 
            +
                                    initial:         ini_pg_ids,
         | 
| 63 | 
            +
                                    final:           end_pg_ids
         | 
| 64 | 
            +
                                  )
         | 
| 65 | 
            +
                                end
         | 
| 46 66 |  | 
| 47 67 | 
             
                                person.account.permissions_custom = session.new_preset(person)
         | 
| 48 68 |  | 
| @@ -9,11 +9,11 @@ module Eco | |
| 9 9 | 
             
                          creation = session.job_group("main").new("create", usecase: usecase, type: :create, sets: [:core, :details, :account])
         | 
| 10 10 | 
             
                          update   = session.job_group("main").new("update", usecase: usecase, type: :update, sets: [:core, :details, :account])
         | 
| 11 11 | 
             
                          supers   = session.job_group("post").new("supers", usecase: usecase, type: :update, sets: :core)
         | 
| 12 | 
            -
                           | 
| 12 | 
            +
                          leavers  = session.job_group("post").new("leavers", usecase: usecase, type: :update, sets: :account)
         | 
| 13 13 |  | 
| 14 14 | 
             
                          people.users.each_with_index  do |person, i|
         | 
| 15 15 | 
             
                            if !entries.find(person)
         | 
| 16 | 
            -
                               | 
| 16 | 
            +
                              leavers.add(person) do |person|
         | 
| 17 17 | 
             
                                person.supervisor_id = nil
         | 
| 18 18 | 
             
                                person.account       = nil
         | 
| 19 19 | 
             
                              end
         | 
| @@ -23,6 +23,10 @@ module Eco | |
| 23 23 | 
             
                          strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
         | 
| 24 24 | 
             
                          pgs           = session.policy_groups
         | 
| 25 25 |  | 
| 26 | 
            +
                          if session.config.people.default_usergroup?
         | 
| 27 | 
            +
                            def_id  = pgs.to_id(session.config.people.default_usergroup)
         | 
| 28 | 
            +
                          end
         | 
| 29 | 
            +
             | 
| 26 30 | 
             
                          entries.each_with_index do |entry, i|
         | 
| 27 31 | 
             
                            person = people.find(entry, strict: strict_search)
         | 
| 28 32 | 
             
                            person = session.new_person if create = !person
         | 
| @@ -48,7 +52,8 @@ module Eco | |
| 48 52 | 
             
                            entry.set_details(person) unless options.dig(:exclude, :details)
         | 
| 49 53 |  | 
| 50 54 | 
             
                            unless options.dig(:exclude, :account)
         | 
| 51 | 
            -
                               | 
| 55 | 
            +
                              add_account = !person.account
         | 
| 56 | 
            +
                              ini_pg_ids  = person.account&.policy_group_ids || []
         | 
| 52 57 |  | 
| 53 58 | 
             
                              account_excluded = []
         | 
| 54 59 | 
             
                              account_excluded.push("policy_group_ids") if options.dig(:exclude, :policy_groups) && !create
         | 
| @@ -58,9 +63,18 @@ module Eco | |
| 58 63 | 
             
                              person.account.send_invites = options[:send_invites] if options.key?(:send_invites)
         | 
| 59 64 |  | 
| 60 65 | 
             
                              unless options.dig(:exclude, :policy_groups) && !create
         | 
| 66 | 
            +
                                end_pg_ids = person.account.policy_group_ids || []
         | 
| 67 | 
            +
             | 
| 68 | 
            +
                                unless entry.policy_group_ids? && !add_account && !def_id
         | 
| 69 | 
            +
                                  # on account creation, if missing policy_group_ids column in the input
         | 
| 70 | 
            +
                                  # use default_usergroup, if it's defined
         | 
| 71 | 
            +
                                  end_pg_ids = [def_id]
         | 
| 72 | 
            +
                                end
         | 
| 73 | 
            +
             | 
| 74 | 
            +
                                # avoid false updates by preserving the original order
         | 
| 61 75 | 
             
                                person.account.policy_group_ids   = pgs.user_pg_ids(
         | 
| 62 76 | 
             
                                  initial:         ini_pg_ids,
         | 
| 63 | 
            -
                                  final:            | 
| 77 | 
            +
                                  final:           end_pg_ids
         | 
| 64 78 | 
             
                                )
         | 
| 65 79 | 
             
                              end
         | 
| 66 80 |  | 
| @@ -22,13 +22,15 @@ module Eco | |
| 22 22 |  | 
| 23 23 | 
             
                          entries.each_with_index do |entry, i|
         | 
| 24 24 | 
             
                            if person = people.find(entry, strict: strict_search)
         | 
| 25 | 
            -
                              person.account | 
| 26 | 
            -
             | 
| 25 | 
            +
                              if person.account
         | 
| 26 | 
            +
                                person.account.send_invites = true
         | 
| 27 | 
            +
                                invite.add(person)
         | 
| 28 | 
            +
                              end
         | 
| 27 29 | 
             
                            else
         | 
| 28 30 | 
             
                              session.logger.error("Entry(#{i}) - this person does not exist: #{entry.to_s(:identify)}")
         | 
| 29 31 | 
             
                            end
         | 
| 30 32 | 
             
                          end
         | 
| 31 | 
            -
             | 
| 33 | 
            +
             | 
| 32 34 | 
             
                        end
         | 
| 33 35 | 
             
                      end
         | 
| 34 36 |  | 
| @@ -10,7 +10,7 @@ module Eco | |
| 10 10 | 
             
                          supers   = session.job_group("post").new("supers", usecase: usecase, type: :update, sets: :core)
         | 
| 11 11 |  | 
| 12 12 | 
             
                          strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
         | 
| 13 | 
            -
                          pgs | 
| 13 | 
            +
                          pgs           = session.policy_groups
         | 
| 14 14 |  | 
| 15 15 | 
             
                          entries.each.with_index do |entry, i|
         | 
| 16 16 | 
             
                            if person = people.find(entry, strict: strict_search)
         | 
| @@ -47,6 +47,7 @@ module Eco | |
| 47 47 | 
             
                                person.account.send_invites = options[:send_invites] if options.key?(:send_invites)
         | 
| 48 48 |  | 
| 49 49 | 
             
                                unless options.dig(:exclude, :policy_groups)
         | 
| 50 | 
            +
                                  # avoid false updates by preserving the original order
         | 
| 50 51 | 
             
                                  person.account.policy_group_ids   = pgs.user_pg_ids(
         | 
| 51 52 | 
             
                                    initial:         ini_pg_ids,
         | 
| 52 53 | 
             
                                    final:           person.account.policy_group_ids
         | 
| @@ -13,6 +13,10 @@ module Eco | |
| 13 13 | 
             
                          strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
         | 
| 14 14 | 
             
                          pgs           = session.policy_groups
         | 
| 15 15 |  | 
| 16 | 
            +
                          if session.config.people.default_usergroup?
         | 
| 17 | 
            +
                            def_id  = pgs.to_id(session.config.people.default_usergroup)
         | 
| 18 | 
            +
                          end
         | 
| 19 | 
            +
             | 
| 16 20 | 
             
                          entries.each_with_index do |entry, i|
         | 
| 17 21 | 
             
                            person = people.find(entry, strict: strict_search)
         | 
| 18 22 | 
             
                            person = session.new_person if create = !person
         | 
| @@ -41,7 +45,8 @@ module Eco | |
| 41 45 | 
             
                            entry.set_details(person) unless options.dig(:exclude, :details)
         | 
| 42 46 |  | 
| 43 47 | 
             
                            unless options.dig(:exclude, :account)
         | 
| 44 | 
            -
                               | 
| 48 | 
            +
                              add_account = !person.account
         | 
| 49 | 
            +
                              ini_pg_ids  = person.account&.policy_group_ids || []
         | 
| 45 50 |  | 
| 46 51 | 
             
                              account_excluded = []
         | 
| 47 52 | 
             
                              account_excluded.push("policy_group_ids") if options.dig(:exclude, :policy_groups) && !create
         | 
| @@ -51,9 +56,18 @@ module Eco | |
| 51 56 | 
             
                              person.account.send_invites = options[:send_invites] if options.key?(:send_invites)
         | 
| 52 57 |  | 
| 53 58 | 
             
                              unless options.dig(:exclude, :policy_groups) && !create
         | 
| 59 | 
            +
                                end_pg_ids = person.account.policy_group_ids || []
         | 
| 60 | 
            +
             | 
| 61 | 
            +
                                unless entry.policy_group_ids? && !add_account && !def_id
         | 
| 62 | 
            +
                                  # on account creation, if missing policy_group_ids column in the input
         | 
| 63 | 
            +
                                  # use default_usergroup, if it's defined
         | 
| 64 | 
            +
                                  end_pg_ids = [def_id]
         | 
| 65 | 
            +
                                end
         | 
| 66 | 
            +
             | 
| 67 | 
            +
                                # avoid false updates by preserving the original order
         | 
| 54 68 | 
             
                                person.account.policy_group_ids   = pgs.user_pg_ids(
         | 
| 55 69 | 
             
                                  initial:         ini_pg_ids,
         | 
| 56 | 
            -
                                  final:            | 
| 70 | 
            +
                                  final:           end_pg_ids
         | 
| 57 71 | 
             
                                )
         | 
| 58 72 | 
             
                              end
         | 
| 59 73 |  | 
| @@ -25,10 +25,8 @@ module Eco | |
| 25 25 | 
             
                    # @param usecase [Eco::API::UseCases::UseCase] target usecase
         | 
| 26 26 | 
             
                    # @return [Eco::API::UseCases::UseCaseIO]
         | 
| 27 27 | 
             
                    def new(usecase:, **kargs)
         | 
| 28 | 
            -
                      default = {
         | 
| 29 | 
            -
             | 
| 30 | 
            -
                        job:     @job
         | 
| 31 | 
            -
                      }
         | 
| 28 | 
            +
                      default = { usecase: usecase }
         | 
| 29 | 
            +
                      default.merge!(job: @job) if @job
         | 
| 32 30 | 
             
                      super(**default.merge(kargs))
         | 
| 33 31 | 
             
                    end
         | 
| 34 32 |  | 
| @@ -53,12 +51,10 @@ module Eco | |
| 53 51 | 
             
                    def params(keyed: false)
         | 
| 54 52 | 
             
                      super(keyed: keyed).tap do |res|
         | 
| 55 53 | 
             
                        if keyed
         | 
| 56 | 
            -
                          res.merge!( | 
| 57 | 
            -
             | 
| 58 | 
            -
                            job:     @job
         | 
| 59 | 
            -
                          })
         | 
| 54 | 
            +
                          res.merge!(usecase: usecase)
         | 
| 55 | 
            +
                          res.merge!(job: @job) if @job
         | 
| 60 56 | 
             
                        else
         | 
| 61 | 
            -
                          res.push(usecase).push(@job)
         | 
| 57 | 
            +
                          res.push(usecase).push(@job) if @job
         | 
| 62 58 | 
             
                        end
         | 
| 63 59 | 
             
                      end
         | 
| 64 60 | 
             
                    end
         | 
    
        data/lib/eco/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: eco-helpers
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1.3. | 
| 4 | 
            +
              version: 1.3.8
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Oscar Segura
         | 
| @@ -208,6 +208,7 @@ files: | |
| 208 208 | 
             
            - ".gitignore"
         | 
| 209 209 | 
             
            - ".rspec"
         | 
| 210 210 | 
             
            - ".yardopts"
         | 
| 211 | 
            +
            - CHANGELOG.md
         | 
| 211 212 | 
             
            - Gemfile
         | 
| 212 213 | 
             
            - README.md
         | 
| 213 214 | 
             
            - Rakefile
         |