Skip to content

Commit

Permalink
send if roles are equal
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcam-src committed Feb 17, 2025
1 parent 5735a0d commit 961f8f2
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions app/services/hyrax/workflow/deposited_viewer_notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ def users_to_notify
)")


# Rails.logger.info("NOTIF 2 - QUERY INSPECT 1")
# users_and_roles_query.each do |query_result|
# Rails.logger.info("RESULT INSPECT #{query_result.inspect}")
# end
Rails.logger.info("NOTIF 2 - QUERY INSPECT 1")
users_and_roles_query.each do |query_result|
Rails.logger.info("RESULT INSPECT #{query_result.inspect}")
end

# users_and_roles = users_and_roles_query.map { |row| row.symbolize_keys }
# Rails.logger.info("NOTIF 2 - QUERY INSPECT: #{users_and_roles.inspect}")
users_and_roles = users_and_roles_query.map { |row| row.symbolize_keys }
Rails.logger.info("NOTIF 2 - QUERY INSPECT: #{users_and_roles.inspect}")

# Rails.logger.info("NOTIF 2 - QUERY RESULTS")
# users_and_roles.each do |query_result|
# puts "User ID: #{query_result[:user_id]}, Email: #{query_result[:email]}, Group: #{query_result[:group_name]}, Admin Set Role: #{query_result[:admin_set_role]}"
# end
Rails.logger.info("NOTIF 2 - QUERY RESULTS")
users_and_roles.each do |query_result|
puts "User ID: #{query_result[:user_id]}, Email: #{query_result[:email]}, Group: #{query_result[:group_name]}, Admin Set Role: #{query_result[:admin_set_role]}"
end

# Map [user_id, group_name, admin_set_role] -> [user_id, {role_name => count}]
user_role_map = users_and_roles.each_with_object({}) do |query_result, h|
Expand All @@ -55,7 +55,7 @@ def users_to_notify
end


# Rails.logger.info("NOTIF - USER ROLE MAP")
Rails.logger.info("NOTIF - USER ROLE MAP")
# Also processing
user_role_map.each do |id, count|
# Manager addition v: 1, m: 1
Expand All @@ -71,30 +71,30 @@ def users_to_notify
managing_count = count['manage']
send_notification = viewing_count > managing_count

# Rails.logger.info "User: #{k}, Roles: #{count.to_a}"
# Rails.logger.info "LOG VIEWING/MANAGING COUNT - User: #{id}, Viewing Count: #{viewing_count}, Managing Count: #{managing_count}, send_notification: #{send_notification}"
Rails.logger.info "User: #{k}, Roles: #{count.to_a}"
Rails.logger.info "LOG VIEWING/MANAGING COUNT - User: #{id}, Viewing Count: #{viewing_count}, Managing Count: #{managing_count}, send_notification: #{send_notification}"
end


# Select users that have the viewing role applied to them more times than the managing role
only_viewers = user_role_map.select { |user_id, role_counts| role_counts['view'] > role_counts['manage'] }
only_viewers = user_role_map.select { |user_id, role_counts| role_counts['view'] >= role_counts['manage'] }
only_viewer_ids = only_viewers.keys.map(&:to_i)

# Rails.logger.info("NOTIF - EXCLUSIVELY VIEWERS")
# only_viewers.each do |k, v|
# Rails.logger.info "User: #{k}, Viewing: #{v['view']}, Managing: #{v['manage']}"
# end
Rails.logger.info("NOTIF - EXCLUSIVELY VIEWERS")
only_viewers.each do |k, v|
Rails.logger.info "User: #{k}, Viewing: #{v['view']}, Managing: #{v['manage']}"
end

# Select recipients with a user id that is in the only_viewer_ids set
# Rails.logger.info("NOTIF - User IDs selected for notification: #{only_viewer_ids.inspect}")
Rails.logger.info("NOTIF - User IDs selected for notification: #{only_viewer_ids.inspect}")

# Fetch users directly from the database
res = ::User.where(id: only_viewer_ids).to_a

# Rails.logger.info("NOTIF - QUERY INSPECTION - #{res.inspect}")
Rails.logger.info("NOTIF - QUERY INSPECTION - #{res.inspect}")

# Rails.logger.info("NOTIF - FINAL RECIPIENTS")
# res.each { |r| Rails.logger.info("User ID: #{r.id}, Email: #{r.email}") }
Rails.logger.info("NOTIF - FINAL RECIPIENTS")
res.each { |r| Rails.logger.info("User ID: #{r.id}, Email: #{r.email}") }
res
end
end
Expand Down

0 comments on commit 961f8f2

Please sign in to comment.