Skip to content
This repository has been archived by the owner on Dec 28, 2023. It is now read-only.

Commit

Permalink
Updating active admin and ransack (#655)
Browse files Browse the repository at this point in the history
* updating active admin and ransack

* adding ransack method to models

* adding more ransack methods

* more ransack methods

* trying to fix tests

* testing

* fixing broken test

* fixing intermitent test
  • Loading branch information
nehamamandelbaum committed Dec 27, 2023
1 parent 0198d59 commit 6e699fc
Show file tree
Hide file tree
Showing 21 changed files with 255 additions and 152 deletions.
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ gem 'rails', '~> 7.0.7'

gem 'bootsnap', require: false

gem 'activeadmin', '~> 2.13.1'
gem 'activeadmin', '~> 3.2'
gem 'autoprefixer-rails', '~> 10.4.2.0'
gem 'cancancan', '~> 3.3.0'
gem 'carrierwave', '~> 2.2.5'
Expand Down Expand Up @@ -47,7 +47,7 @@ gem 'business_time'
gem 'github_api', '~> 0.18.2'
gem 'httparty'
gem 'money-rails', '~> 1.12'
gem 'ransack', '~> 2.3'
gem 'ransack', '~> 4.0'

gem 'sidekiq', "~> 6.5.12"

Expand Down
64 changes: 32 additions & 32 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ GEM
case_transform (>= 0.2)
jsonapi-renderer (>= 0.1.1.beta1, < 0.3)
active_skin (0.0.13)
activeadmin (2.13.1)
activeadmin (3.2.0)
arbre (~> 1.2, >= 1.2.1)
formtastic (>= 3.1, < 5.0)
formtastic_i18n (~> 0.4)
formtastic (>= 3.1)
formtastic_i18n (>= 0.4)
inherited_resources (~> 1.7)
jquery-rails (~> 4.2)
kaminari (~> 1.0, >= 1.2.1)
railties (>= 6.1, < 7.1)
ransack (>= 2.1.1, < 4)
jquery-rails (>= 4.2)
kaminari (>= 1.2.1)
railties (>= 6.1)
ransack (>= 4.0)
activejob (7.0.7.2)
activesupport (= 7.0.7.2)
globalid (>= 0.3.6)
Expand All @@ -123,9 +123,9 @@ GEM
tzinfo (~> 2.0)
addressable (2.8.5)
public_suffix (>= 2.0.2, < 6.0)
arbre (1.6.0)
activesupport (>= 3.0.0, < 7.1)
ruby2_keywords (>= 0.0.2, < 1.0)
arbre (1.7.0)
activesupport (>= 3.0.0)
ruby2_keywords (>= 0.0.2)
ast (2.4.2)
autoprefixer-rails (10.4.2.0)
execjs (~> 2)
Expand Down Expand Up @@ -249,8 +249,8 @@ GEM
sassc (>= 1.11)
foreman (0.87.2)
formatador (1.1.0)
formtastic (4.0.0)
actionpack (>= 5.2.0)
formtastic (5.0.0)
actionpack (>= 6.0.0)
formtastic_i18n (0.7.0)
github_api (0.18.2)
addressable (~> 2.4)
Expand All @@ -275,7 +275,7 @@ GEM
guard (~> 2.8)
guard-compat (~> 1.0)
multi_json (~> 1.8)
has_scope (0.8.1)
has_scope (0.8.2)
actionpack (>= 5.2)
activesupport (>= 5.2)
hashdiff (1.0.1)
Expand All @@ -298,11 +298,11 @@ GEM
image_processing (1.12.2)
mini_magick (>= 4.9.5, < 5)
ruby-vips (>= 2.0.17, < 3)
inherited_resources (1.13.1)
actionpack (>= 5.2, < 7.1)
has_scope (~> 0.6)
railties (>= 5.2, < 7.1)
responders (>= 2, < 4)
inherited_resources (1.14.0)
actionpack (>= 6.0)
has_scope (>= 0.6)
railties (>= 6.0)
responders (>= 2)
inline_svg (1.9.0)
activesupport (>= 3.0)
nokogiri (>= 1.6)
Expand Down Expand Up @@ -347,7 +347,7 @@ GEM
listen (3.8.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
loofah (2.21.3)
loofah (2.22.0)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
lumberjack (1.2.8)
Expand All @@ -361,7 +361,7 @@ GEM
method_source (1.0.0)
mini_magick (4.12.0)
mini_mime (1.1.5)
mini_portile2 (2.8.2)
mini_portile2 (2.8.5)
minitest (5.20.0)
moneta (1.0.0)
monetize (1.12.0)
Expand Down Expand Up @@ -427,8 +427,8 @@ GEM
public_suffix (5.0.4)
puma (6.3.1)
nio4r (~> 2.0)
racc (1.7.1)
rack (2.2.7)
racc (1.7.3)
rack (2.2.8)
rack-proxy (0.7.6)
rack
rack-test (2.1.0)
Expand All @@ -454,7 +454,7 @@ GEM
actionpack (>= 5.0.1.rc1)
actionview (>= 5.0.1.rc1)
activesupport (>= 5.0.1.rc1)
rails-dom-testing (2.1.1)
rails-dom-testing (2.2.0)
activesupport (>= 5.0.0)
minitest
nokogiri (>= 1.6)
Expand All @@ -472,10 +472,10 @@ GEM
thor (~> 1.0)
zeitwerk (~> 2.5)
rainbow (3.1.1)
rake (13.0.6)
ransack (2.6.0)
activerecord (>= 6.0.4)
activesupport (>= 6.0.4)
rake (13.1.0)
ransack (4.1.1)
activerecord (>= 6.1.5)
activesupport (>= 6.1.5)
i18n
rate_throttle_client (0.1.2)
rb-fsevent (0.11.2)
Expand All @@ -485,7 +485,7 @@ GEM
regexp_parser (2.8.1)
request_store (1.5.1)
rack (>= 1.4)
responders (3.1.0)
responders (3.1.1)
actionpack (>= 5.2)
railties (>= 5.2)
rexml (3.2.5)
Expand Down Expand Up @@ -596,7 +596,7 @@ GEM
railties (>= 6.0.0)
tailwindcss-rails (2.0.30-x86_64-linux)
railties (>= 6.0.0)
thor (1.2.2)
thor (1.3.0)
thread_safe (0.3.6)
tilt (2.2.0)
timeliness (0.4.5)
Expand Down Expand Up @@ -631,7 +631,7 @@ GEM
websocket-extensions (0.1.5)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.6.8)
zeitwerk (2.6.12)

PLATFORMS
aarch64-linux
Expand All @@ -646,7 +646,7 @@ DEPENDENCIES
active_admin_theme
active_model_serializers (~> 0.10.13)
active_skin
activeadmin (~> 2.13.1)
activeadmin (~> 3.2)
autoprefixer-rails (~> 10.4.2.0)
barnes
better_errors
Expand Down Expand Up @@ -703,7 +703,7 @@ DEPENDENCIES
rails-ajax_redirect
rails-controller-testing
rails-i18n
ransack (~> 2.3)
ransack (~> 4.0)
rollbar
roo (~> 2.9.0)
rqrcode
Expand Down
28 changes: 19 additions & 9 deletions app/models/allocation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,20 @@ class Allocation < ApplicationRecord
delegate :name, to: :project, prefix: true, allow_nil: true
delegate :name, to: :user, prefix: true, allow_nil: true

scope :ongoing, -> {
scope :ongoing, lambda {
where(ongoing: true, user_id: User.active).order(start_at: :desc)
}

scope :finished, -> {
where(ongoing: false, user_id: User.active).order(end_at: :desc) }
scope :in_period, -> (start_at, end_at) do
scope :finished, lambda {
where(ongoing: false, user_id: User.active).order(end_at: :desc)
}
scope :in_period, lambda { |start_at, end_at|
where(
"daterange(start_at, end_at, '[]') && daterange(:start_at, :end_at, '[]')",
start_at: start_at,
end_at: end_at
start_at:,
end_at:
)
end
}

def days_until_finish
return unless end_at
Expand All @@ -53,20 +54,29 @@ def self.hourly_rate_currencies
def user_punches
project
.punches
.where(user: user)
.where(user:)
.since(start_at)
.order(from: :desc)
.decorate
end

def self.ransackable_attributes(_auth_object = nil)
%w[created_at end_at hourly_rate_cents hourly_rate_currency id ongoing project_id start_at
updated_at user_id]
end

def self.ransackable_associations(_auth_object = nil)
%w[project user]
end

private

def end_before_start?
end_at.present? && end_at < start_at
end

def unique_period
return unless Allocation.in_period(start_at, end_at).where.not(id: id).exists?(user_id: user_id)
return unless Allocation.in_period(start_at, end_at).where.not(id:).exists?(user_id:)

errors.add(:start_at, :overlapped_period)
end
Expand Down
4 changes: 4 additions & 0 deletions app/models/city.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ def to_s
def holidays
regional_holidays.to_formatted_hash
end

def self.ransackable_attributes(_auth_object = nil)
%w[created_at id name state_id updated_at]
end
end
9 changes: 9 additions & 0 deletions app/models/contribution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ def update_rejected_reason(rejected_reason = "other_reason", reviewer_id)
scope :by_created_at_from, ->(date) { where('created_at >= ?', date) if date.present? }
scope :by_created_at_until, ->(date) { where('created_at <= ?', date) if date.present? }

def self.ransackable_attributes(_auth_object = nil)
%w[created_at description id link notes pending pr_state rejected_reason repository_id
reviewed_at reviewer_id state tracking updated_at]
end

def self.ransackable_associations(_auth_object = nil)
%w[repository reviewed_by users]
end

private

def normalize_description_blank_value
Expand Down
8 changes: 8 additions & 0 deletions app/models/education_experience.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,12 @@ class EducationExperience < ApplicationRecord
allow_nil: true

scope :for_user, ->(user_id) { where(user_id:) }

def self.ransackable_associations(_auth_object = nil)
["user"]
end

def self.ransackable_attributes(_auth_object = nil)
%w[course created_at end_date id institution start_date updated_at user_id]
end
end
15 changes: 12 additions & 3 deletions app/models/evaluation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,21 @@ class Evaluation < ApplicationRecord

attribute :evaluation_date, :date, default: Time.zone.today

scope :by_kind, -> (kind) { joins(:questionnaire).merge(Questionnaire.public_send(kind)) }
scope :by_kind, ->(kind) { joins(:questionnaire).merge(Questionnaire.public_send(kind)) }

enumerize :english_level, in: {
beginner: 0, intermediate: 1, advanced: 2, fluent: 3
}, scope: :shallow,
predicates: true
}, scope: :shallow,
predicates: true

def self.ransackable_associations(_auth_object = nil)
%w[answers evaluated evaluator questionnaire]
end

def self.ransackable_attributes(_auth_object = nil)
%w[created_at english_level evaluated_id evaluation_date evaluator_id id observation
questionnaire_id score updated_at]
end

private

Expand Down
10 changes: 9 additions & 1 deletion app/models/office.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Office < ApplicationRecord
has_many :users, dependent: :restrict_with_error
has_many :users_without_head, ->(office) {where.not(id: office.head_id)}, class_name: 'User'
has_many :users_without_head, ->(office) { where.not(id: office.head_id) }, class_name: 'User'
belongs_to :head, class_name: 'User', optional: true

validates :city, presence: true, uniqueness: true
Expand All @@ -22,4 +22,12 @@ def calculate_score
users_average_score = users_overall_scores.sum / users_overall_scores.size
update(score: users_average_score.round(2))
end

def self.ransackable_associations(_auth_object = nil)
%w[head users users_without_head]
end

def self.ransackable_attributes(_auth_object = nil)
%w[active city created_at head_id id score updated_at users_count]
end
end
8 changes: 8 additions & 0 deletions app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,12 @@ def enable!
def to_s
name
end

def self.ransackable_attributes(_auth_object = nil)
%w[active created_at id market name updated_at]
end

def self.ransackable_associations(_auth_object = nil)
%w[allocations punches]
end
end

0 comments on commit 6e699fc

Please sign in to comment.