app/jobs/send_db_diff_job.rb
# While looping on AppParameter to collect all DB-diff text, collect also a list
# of unique TMs with associated editors/users in order to notify the TMs of the
# latest changes or updates made.
#
# === Params:
#
# - app_parameter_rows: the list of AppParameter rows selected for DB-diff extraction
#
#
# == Returns:
#
# An Hash keyed by the user.id of each TM, having structure:
#
#     {
#       TM.user1.id => {
#           tm_user: TM.user1,
#           users: [editor_user1, editor_user2, ...],
#           urls:  [req_url1_1, req_url1_2, ..., req_url2_1, ...],
#           description: remote_edit_type_description
#       },
#
#       TM.user2.id => { ... } #, ...
#     }
#
While looping on AppParameter to collect all DB-diff text, collect also a list
of unique TMs with associated editors/users in order to notify the TMs of the
latest changes or updates made.



the list of AppParameter rows selected for DB-diff extraction



An Hash keyed by the user.id of each TM, having structure.




While looping on AppParameter to collect all DB - diff text collect also a list of unique TMs with associated editors / users in order to notify the TMs of the latest changes or updates made . the list of AppParameter rows selected for DB - diff extraction An Hash keyed by the user . id of each TM having structure .
def collect_db_diff_text_and_user_data( app_parameter_rows )
    editor_users = []
    req_urls = []
    team_managers_data = {}
    app_parameter_rows.each do |app_parameter_row|
      if app_parameter_row.free_text_1.present?
        add_sql_diff_comment( "Remote editing recorded from actions by User ID #{ app_parameter_row.code - 100000 }" )
        sql_diff_text_log << app_parameter_row.free_text_1
        sql_diff_text_log << "\r\n"
        user_from_code = User.find_by_id( app_parameter_row.code.to_i - 100000)
        if user_from_code && !editor_users.include?( user_from_code )
          editor_users << user_from_code
          team_managers_users = begin
            user_from_code.swimmer.badges.last.team_managers.map(&:user)
          rescue
            []
          end
          team_managers_users.each do |tm_user|
            if team_managers_data.has_key?( tm_user.id )
              team_managers_data[ tm_user.id ][:users] << user_from_code
              team_managers_data[ tm_user.id ][:description].to_s << ", #{ app_parameter_row.free_text_2 }"
              team_managers_data[ tm_user.id ][:urls] += app_parameter_row.free_text_3.to_s.split("\r\n")
              team_managers_data[ tm_user.id ][:urls].uniq!
            else
              team_managers_data[ tm_user.id ] = {
                tm_user:      tm_user,
                users:        [ user_from_code ],
                urls:         app_parameter_row.free_text_3.to_s.split("\r\n"),
                description:  app_parameter_row.free_text_2.to_s
              }
            end
          end
        end
        app_parameter_row.update( free_text_1: '' )
        app_parameter_row.update( free_text_2: '' )
        app_parameter_row.update( free_text_3: '' )
      end
    end
    team_managers_data
  end
def collect_db_diff_text_and_user_data ( app_parameter_rows ) editor_users = [ ] req_urls = [ ] team_managers_data = { } app_parameter_rows . each do | app_parameter_row | if app_parameter_row . free_text_1 . present? add_sql_diff_comment ( "Remote editing recorded from actions by User ID #{ app_parameter_row.code - 100000 }" ) sql_diff_text_log << app_parameter_row . free_text_1 sql_diff_text_log << "\r\n" user_from_code = User . find_by_id ( app_parameter_row . code . to_i - 100000 ) if user_from_code && ! editor_users . include? ( user_from_code ) editor_users << user_from_code team_managers_users = begin user_from_code . swimmer . badges . last . team_managers . map ( & :user ) rescue [ ] end team_managers_users . each do | tm_user | if team_managers_data . has_key? ( tm_user . id ) team_managers_data [ tm_user . id ] [ :users ] << user_from_code team_managers_data [ tm_user . id ] [ :description ] . to_s << ", #{ app_parameter_row.free_text_2 }" team_managers_data [ tm_user . id ] [ :urls ] += app_parameter_row . free_text_3 . to_s . split ( "\r\n" ) team_managers_data [ tm_user . id ] [ :urls ] . uniq! else team_managers_data [ tm_user . id ] = { tm_user : tm_user , users : [ user_from_code ] , urls : app_parameter_row . free_text_3 . to_s . split ( "\r\n" ) , description : app_parameter_row . free_text_2 . to_s } end end end app_parameter_row . update ( free_text_1 : '' ) app_parameter_row . update ( free_text_2 : '' ) app_parameter_row . update ( free_text_3 : '' ) end end team_managers_data end
While looping on AppParameter to collect all DB-diff text, collect also a list
of unique TMs with associated editors/users in order to notify the TMs of the
latest changes or updates made.
While looping on AppParameter to collect all DB - diff text collect also a list of unique TMs with associated editors / users in order to notify the TMs of the latest changes or updates made .
# Prepare a list of unique editor users and associated TM data: # Scan all serialized row values and move them on a file to be sent via e-mail: # Compile a list of unique users that have edited something remotely: # Compile a list of all the associated TMs: # For each editor user there may be more than 1 team manager. # We need to get all possible TM.users in order to send email notifications # to all of them: # TM already stored? # Add the list of baseURIs to the current TM's and make it unique in each row: # New TM? Initialize hash data: # Clear the DB field used for serialization of this user's actions:
app_parameter_rows
<not_specific>