Fix projects query for experiments

Remove unneeded word in view
This commit is contained in:
Jure Grabnar 2016-08-12 11:36:52 +02:00
parent d7341d0383
commit c387439fb2
2 changed files with 10 additions and 8 deletions

View file

@ -93,7 +93,7 @@ class ExperimentsController < ApplicationController
# GET: clone_modal_experiment_path(id) # GET: clone_modal_experiment_path(id)
def clone_modal def clone_modal
@projects = projects_with_role_above_user @projects = projects_with_role_above_user(true)
respond_to do |format| respond_to do |format|
format.json do format.json do
render json: { render json: {
@ -111,7 +111,7 @@ class ExperimentsController < ApplicationController
# Try to clone the experiment # Try to clone the experiment
success = true success = true
if projects_with_role_above_user.include?(project) if projects_with_role_above_user(true).include?(project)
cloned_experiment = @experiment.deep_clone_to_project(current_user, cloned_experiment = @experiment.deep_clone_to_project(current_user,
project) project)
success = cloned_experiment.valid? success = cloned_experiment.valid?
@ -144,7 +144,7 @@ class ExperimentsController < ApplicationController
# GET: move_modal_experiment_path(id) # GET: move_modal_experiment_path(id)
def move_modal def move_modal
@projects = projects_with_role_above_user @projects = projects_with_role_above_user(false)
respond_to do |format| respond_to do |format|
format.json do format.json do
render json: { render json: {
@ -232,12 +232,15 @@ class ExperimentsController < ApplicationController
# Get projects where user is either owner or user in the same organization # Get projects where user is either owner or user in the same organization
# as this experiment # as this experiment
def projects_with_role_above_user # - include_this_project: whether to include project from @experiment
def projects_with_role_above_user(include_this_project)
organization = @experiment.project.organization organization = @experiment.project.organization
projects = organization.projects.where(archived: false)
projects = projects
.where.not(id: @experiment.project.id) unless include_this_project
current_user.user_projects current_user.user_projects
.where(project: .where(project: projects)
Project.where(organization: organization)
.where(archived: false))
.where('role < 2') .where('role < 2')
.map(&:project) .map(&:project)
end end

View file

@ -13,7 +13,6 @@
<h4 class="modal-title" id="move-experiment-modal-label"><%= t("experiments.move.modal_title", experiment: @experiment.name ) %></h5> <h4 class="modal-title" id="move-experiment-modal-label"><%= t("experiments.move.modal_title", experiment: @experiment.name ) %></h5>
</div> </div>
<div class="modal-body"> <div class="modal-body">
asdasd
<%= f.select :project_id, options_for_select(@projects.collect { |p| [ p.name, p.id ] }, <%= f.select :project_id, options_for_select(@projects.collect { |p| [ p.name, p.id ] },
@project.id ), @project.id ),
{}, {class: "form-control selectpicker", "data-role" => "clear"} %> {}, {class: "form-control selectpicker", "data-role" => "clear"} %>