diff --git a/app/controllers/dashboard/calendars_controller.rb b/app/controllers/dashboard/calendars_controller.rb index 8242ee40f..6bed36ca3 100644 --- a/app/controllers/dashboard/calendars_controller.rb +++ b/app/controllers/dashboard/calendars_controller.rb @@ -9,13 +9,13 @@ module Dashboard date = params[:date].to_date start_date = date.beginning_of_month - 8.days end_date = date.end_of_month + 15.days - due_dates = current_user.my_modules.readable_by_user(current_user).active.uncomplete - .joins(experiment: :project) - .where(experiments: { archived: false }) - .where(projects: { archived: false }) - .where(my_modules: { due_date: start_date..end_date }) - .joins(:protocols).where(protocols: { team_id: current_team.id }) - .pluck(:due_date) + due_dates = MyModule.readable_by_user(current_user).active.uncomplete + .joins(experiment: :project) + .where(experiments: { archived: false }) + .where(projects: { archived: false }) + .where(my_modules: { due_date: start_date..end_date }) + .joins(:protocols).where(protocols: { team_id: current_team.id }) + .pluck(:due_date) render json: { events: due_dates.map { |i| { date: i.to_date } } } end @@ -23,12 +23,12 @@ module Dashboard date = params[:date].to_date start_date = date.beginning_of_day end_date = date.end_of_day - my_modules = current_user.my_modules.readable_by_user(current_user).active.uncomplete - .joins(experiment: :project) - .where(experiments: { archived: false }) - .where(projects: { archived: false }) - .where(my_modules: { due_date: start_date..end_date }) - .where(projects: { team_id: current_team.id }) + my_modules = MyModule.readable_by_user(current_user).active.uncomplete + .joins(experiment: :project) + .where(experiments: { archived: false }) + .where(projects: { archived: false }) + .where(my_modules: { due_date: start_date..end_date }) + .where(projects: { team_id: current_team.id }) render json: { html: render_to_string(partial: 'shared/my_modules_list_partial', locals: { my_modules: my_modules }, diff --git a/app/controllers/dashboard/current_tasks_controller.rb b/app/controllers/dashboard/current_tasks_controller.rb index a61a2c787..85cbd1b46 100644 --- a/app/controllers/dashboard/current_tasks_controller.rb +++ b/app/controllers/dashboard/current_tasks_controller.rb @@ -34,7 +34,7 @@ module Dashboard .search_by_name(current_user, current_team, params[:query]).select(:id, :name) unless params[:mode] == 'team' - projects = projects.where(id: current_user.my_modules.joins(:experiment) + projects = projects.where(id: MyModule.readable_by_user(current_user).joins(:experiment) .group(:project_id).select(:project_id).pluck(:project_id)) end render json: projects.map { |i| { value: i.id, label: escape_input(i.name) } }, status: :ok @@ -51,7 +51,7 @@ module Dashboard .search_by_name(current_user, current_team, params[:query]).select(:id, :name) unless params[:mode] == 'team' - experiments = experiments.where(id: current_user.my_modules + experiments = experiments.where(id: MyModule.readable_by_user(current_user) .group(:experiment_id).select(:experiment_id).pluck(:experiment_id)) end render json: experiments.map { |i| { value: i.id, label: escape_input(i.name) } }, status: :ok diff --git a/app/models/user.rb b/app/models/user.rb index 195d3710d..8cc04cb92 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -62,9 +62,7 @@ class User < ApplicationRecord has_many :user_group_memberships, dependent: :destroy has_many :user_groups, through: :user_group_memberships has_many :teams, through: :user_assignments, source: :assignable, source_type: 'Team' - has_many :projects, through: :user_assignments, source: :assignable, source_type: 'Project' has_many :user_my_modules, inverse_of: :user - has_many :my_modules, through: :user_assignments, source: :assignable, source_type: 'MyModule' has_many :comments, inverse_of: :user has_many :activities, inverse_of: :owner, foreign_key: 'owner_id' has_many :results, inverse_of: :user diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 9a784d61e..d2fa9ff1f 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -47,7 +47,6 @@ describe User, type: :model do describe 'Relations' do it { should have_many :teams } - it { should have_many :projects } it { should have_many :user_my_modules } it { should have_many :comments } it { should have_many :activities }