From 21c2f825822701b54547f647ab2f08d3b7662433 Mon Sep 17 00:00:00 2001 From: zmagod Date: Tue, 24 Jan 2017 16:57:14 +0100 Subject: [PATCH] rename controllers where org/organization --- app/controllers/application_controller.rb | 24 +- app/controllers/at_who_controller.rb | 18 +- app/controllers/concerns/sample_actions.rb | 2 +- app/controllers/custom_fields_controller.rb | 14 +- app/controllers/experiments_controller.rb | 8 +- app/controllers/my_modules_controller.rb | 16 +- app/controllers/projects_controller.rb | 32 +-- app/controllers/protocols_controller.rb | 34 +-- app/controllers/reports_controller.rb | 2 +- app/controllers/result_assets_controller.rb | 12 +- app/controllers/sample_groups_controller.rb | 22 +- .../sample_my_modules_controller.rb | 4 +- app/controllers/sample_types_controller.rb | 22 +- app/controllers/samples_controller.rb | 28 +- app/controllers/steps_controller.rb | 22 +- ...ions_controller.rb => teams_controller.rb} | 44 +-- app/controllers/user_samples_controller.rb | 6 +- .../users/invitations_controller.rb | 60 ++--- .../users/registrations_controller.rb | 30 +-- app/controllers/users/settings_controller.rb | 250 +++++++++--------- 20 files changed, 325 insertions(+), 325 deletions(-) rename app/controllers/{organizations_controller.rb => teams_controller.rb} (85%) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c6e7e2ade..210683b7a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -7,9 +7,9 @@ class ApplicationController < ActionController::Base # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception before_action :authenticate_user! - helper_method :current_organization + helper_method :current_team before_action :generate_intro_tutorial, if: :is_current_page_root? - before_action :update_current_organization, if: :user_signed_in? + before_action :update_current_team, if: :user_signed_in? around_action :set_time_zone, if: :current_user layout 'main' @@ -25,9 +25,9 @@ class ApplicationController < ActionController::Base controller_name == 'projects' && action_name == 'index' end - # Sets current organization for all controllers - def current_organization - Organization.find_by_id(current_user.current_organization_id) + # Sets current team for all controllers + def current_team + Organization.find_by_id(current_user.current_team_id) end protected @@ -37,8 +37,8 @@ class ApplicationController < ActionController::Base @my_module.log(message) elsif @project @project.log(message) - elsif @organization - @organization.log(message) + elsif @team + @team.log(message) else logger.error(message) end @@ -73,7 +73,7 @@ class ApplicationController < ActionController::Base def generate_intro_tutorial if Rails.configuration.x.enable_tutorial && current_user.no_tutorial_done? && - current_user.organizations.where(created_by: current_user).count > 0 then + current_user.teams.where(created_by: current_user).count > 0 then demo_cookie = seed_demo_data current_user cookies[:tutorial_data] = { value: demo_cookie, @@ -83,11 +83,11 @@ class ApplicationController < ActionController::Base end end - def update_current_organization - if current_user.current_organization_id.blank? && - current_user.organizations.count > 0 + def update_current_team + if current_user.current_team_id.blank? && + current_user.teams.count > 0 current_user.update( - current_organization_id: current_user.organizations.first.id + current_team_id: current_user.teams.first.id ) end end diff --git a/app/controllers/at_who_controller.rb b/app/controllers/at_who_controller.rb index 14fe35e54..c697ed048 100644 --- a/app/controllers/at_who_controller.rb +++ b/app/controllers/at_who_controller.rb @@ -4,7 +4,7 @@ class AtWhoController < ApplicationController def users # Search users - res = @organization + res = @team .search_users(@query) .select(:id, :full_name, :email) .limit(Constants::ATWHO_SEARCH_LIMIT) @@ -30,7 +30,7 @@ class AtWhoController < ApplicationController end def menu_items - res = SmartAnnotation.new(current_user, current_organization, @query) + res = SmartAnnotation.new(current_user, current_team, @query) respond_to do |format| format.json do @@ -46,7 +46,7 @@ class AtWhoController < ApplicationController end def samples - res = SmartAnnotation.new(current_user, current_organization, @query) + res = SmartAnnotation.new(current_user, current_team, @query) respond_to do |format| format.json do render json: { @@ -58,7 +58,7 @@ class AtWhoController < ApplicationController end def projects - res = SmartAnnotation.new(current_user, current_organization, @query) + res = SmartAnnotation.new(current_user, current_team, @query) respond_to do |format| format.json do render json: { @@ -70,7 +70,7 @@ class AtWhoController < ApplicationController end def experiments - res = SmartAnnotation.new(current_user, current_organization, @query) + res = SmartAnnotation.new(current_user, current_team, @query) respond_to do |format| format.json do render json: { @@ -82,7 +82,7 @@ class AtWhoController < ApplicationController end def my_modules - res = SmartAnnotation.new(current_user, current_organization, @query) + res = SmartAnnotation.new(current_user, current_team, @query) respond_to do |format| format.json do render json: { @@ -96,12 +96,12 @@ class AtWhoController < ApplicationController private def load_vars - @organization = Organization.find_by_id(params[:id]) + @team = Organization.find_by_id(params[:id]) @query = params[:query] - render_404 unless @organization + render_404 unless @team end def check_users_permissions - render_403 unless can_view_organization_users(@organization) + render_403 unless can_view_team_users(@team) end end diff --git a/app/controllers/concerns/sample_actions.rb b/app/controllers/concerns/sample_actions.rb index 84e0f98f6..c70962372 100644 --- a/app/controllers/concerns/sample_actions.rb +++ b/app/controllers/concerns/sample_actions.rb @@ -45,7 +45,7 @@ module SampleActions end def check_destroy_samples_permissions - unless can_delete_samples(@project.organization) + unless can_delete_samples(@project.team) render_403 end end diff --git a/app/controllers/custom_fields_controller.rb b/app/controllers/custom_fields_controller.rb index 2d2890bbf..0126b2343 100644 --- a/app/controllers/custom_fields_controller.rb +++ b/app/controllers/custom_fields_controller.rb @@ -9,7 +9,7 @@ class CustomFieldsController < ApplicationController def create @custom_field = CustomField.new(custom_field_params) - @custom_field.organization = @organization + @custom_field.team = @team @custom_field.user = current_user respond_to do |format| @@ -19,10 +19,10 @@ class CustomFieldsController < ApplicationController id: @custom_field.id, name: escape_input(@custom_field.name), edit_url: - organization_custom_field_path(@organization, @custom_field), + team_custom_field_path(@team, @custom_field), destroy_html_url: - organization_custom_field_destroy_html_path( - @organization, @custom_field + team_custom_field_destroy_html_path( + @team, @custom_field ) }, status: :ok @@ -91,12 +91,12 @@ class CustomFieldsController < ApplicationController end def load_vars_nested - @organization = Organization.find_by_id(params[:organization_id]) - render_404 unless @organization + @team = Organization.find_by_id(params[:team_id]) + render_404 unless @team end def check_create_permissions - render_403 unless can_create_custom_field_in_organization(@organization) + render_403 unless can_create_custom_field_in_team(@team) end def check_update_permissions diff --git a/app/controllers/experiments_controller.rb b/app/controllers/experiments_controller.rb index 8220a136f..d6a95e7e3 100644 --- a/app/controllers/experiments_controller.rb +++ b/app/controllers/experiments_controller.rb @@ -71,7 +71,7 @@ class ExperimentsController < ApplicationController def canvas @project = @experiment.project - current_organization_switch(@project.organization) + current_team_switch(@project.team) end def edit @@ -267,17 +267,17 @@ class ExperimentsController < ApplicationController def samples @samples_index_link = samples_index_experiment_path(@experiment, format: :json) - @organization = @experiment.project.organization + @team = @experiment.project.team end def samples_index - @organization = @experiment.project.organization + @team = @experiment.project.team respond_to do |format| format.html format.json do render json: ::SampleDatatable.new(view_context, - @organization, + @team, nil, nil, @experiment, diff --git a/app/controllers/my_modules_controller.rb b/app/controllers/my_modules_controller.rb index aacd140f3..9fe9fe54b 100644 --- a/app/controllers/my_modules_controller.rb +++ b/app/controllers/my_modules_controller.rb @@ -222,27 +222,27 @@ class MyModulesController < ApplicationController def protocols @protocol = @my_module.protocol - current_organization_switch(@protocol.organization) + current_team_switch(@protocol.team) end def results - current_organization_switch(@my_module + current_team_switch(@my_module .experiment .project - .organization) + .team) end def samples @samples_index_link = samples_index_my_module_path(@my_module, format: :json) - @organization = @my_module.experiment.project.organization + @team = @my_module.experiment.project.team end def archive @archived_results = @my_module.archived_results - current_organization_switch(@my_module + current_team_switch(@my_module .experiment .project - .organization) + .team) end # Submit actions @@ -324,13 +324,13 @@ class MyModulesController < ApplicationController # AJAX actions def samples_index - @organization = @my_module.experiment.project.organization + @team = @my_module.experiment.project.team respond_to do |format| format.html format.json do render json: ::SampleDatatable.new(view_context, - @organization, + @team, nil, @my_module, nil, diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 7c902cf0c..b8edacf32 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -25,23 +25,23 @@ class ProjectsController < ApplicationController DELETE_SAMPLES = 'Delete'.freeze def index - if params[:organization] - current_organization_switch(Organization - .find_by_id(params[:organization])) + if params[:team] + current_team_switch(Organization + .find_by_id(params[:team])) end - if current_user.organizations.any? - @current_organization_id = current_organization.id if current_organization + if current_user.teams.any? + @current_team_id = current_team.id if current_team - @current_organization_id ||= current_user.organizations.first.id + @current_team_id ||= current_user.teams.first.id @current_sort = params[:sort].to_s - @projects_by_orgs = current_user - .projects_by_orgs(@current_organization_id, + @projects_by_teams = current_user + .projects_by_teams(@current_team_id, @current_sort, @filter_by_archived) end - @organizations = current_user.organizations + @teams = current_user.teams # New project for create new project modal @project = Project.new @@ -60,7 +60,7 @@ class ProjectsController < ApplicationController @project = Project.new(project_params) @project.created_by = current_user @project.last_modified_by = current_user - if current_organization.id == project_params[:organization_id].to_i && + if current_team.id == project_params[:team_id].to_i && @project.save # Create user-project association up = UserProject.new( @@ -252,7 +252,7 @@ class ProjectsController < ApplicationController def show # This is the "info" view - current_organization_switch(@project.organization) + current_team_switch(@project.team) @current_sort = params[:sort].to_s end @@ -274,21 +274,21 @@ class ProjectsController < ApplicationController def samples @samples_index_link = samples_index_project_path(@project, format: :json) - @organization = @project.organization + @team = @project.team end def experiment_archive - current_organization_switch(@project.organization) + current_team_switch(@project.team) end def samples_index - @organization = @project.organization + @team = @project.team @user = current_user respond_to do |format| format.html format.json do render json: ::SampleDatatable.new(view_context, - @organization, + @team, @project, nil, nil, @@ -300,7 +300,7 @@ class ProjectsController < ApplicationController private def project_params - params.require(:project).permit(:name, :organization_id, :visibility, :archived) + params.require(:project).permit(:name, :team_id, :visibility, :archived) end def load_vars diff --git a/app/controllers/protocols_controller.rb b/app/controllers/protocols_controller.rb index 4803f71f5..47dd49af2 100644 --- a/app/controllers/protocols_controller.rb +++ b/app/controllers/protocols_controller.rb @@ -74,7 +74,7 @@ class ProtocolsController < ApplicationController format.json { render json: ::ProtocolsDatatable.new( view_context, - @current_organization, + @current_team, @type, current_user ) @@ -204,7 +204,7 @@ class ProtocolsController < ApplicationController def create @protocol = Protocol.new( - organization: @current_organization, + team: @current_team, protocol_type: Protocol.protocol_types[@type == :public ? :in_repository_public : :in_repository_private], added_by: current_user ) @@ -224,7 +224,7 @@ class ProtocolsController < ApplicationController render json: { url: edit_protocol_path( @protocol, - organization: @current_organization, + team: @current_team, type: @type ) } @@ -531,7 +531,7 @@ class ProtocolsController < ApplicationController transaction_error = false Protocol.transaction do begin - protocol = import_new_protocol(@protocol_json, @organization, @type, current_user) + protocol = import_new_protocol(@protocol_json, @team, @type, current_user) rescue Exception transaction_error = true raise ActiveRecord:: Rollback @@ -674,7 +674,7 @@ class ProtocolsController < ApplicationController format.json { render json: ::LoadFromRepositoryProtocolsDatatable.new( view_context, - @protocol.organization, + @protocol.team, @type, current_user ) @@ -769,7 +769,7 @@ class ProtocolsController < ApplicationController html: render_to_string({ partial: "protocols/header/edit_keywords_modal_body.html.erb" }), - keywords: @protocol.organization.protocol_keywords_list + keywords: @protocol.team.protocol_keywords_list } } end @@ -851,16 +851,16 @@ class ProtocolsController < ApplicationController end end - def load_organization_and_type - @current_organization = current_organization + def load_team_and_type + @current_team = current_team # :public, :private or :archive @type = (params[:type] || "public").to_sym end def check_view_all_permissions - load_organization_and_type + load_team_and_type - unless can_view_organization_protocols(@current_organization) + unless can_view_team_protocols(@current_team) render_403 end end @@ -873,15 +873,15 @@ class ProtocolsController < ApplicationController end def check_create_permissions - load_organization_and_type + load_team_and_type - if !can_create_new_protocol(@current_organization) || @type == :archive + if !can_create_new_protocol(@current_team) || @type == :archive render_403 end end def check_clone_permissions - load_organization_and_type + load_team_and_type @original = Protocol.find_by_id(params[:id]) if @original.blank? || @@ -891,7 +891,7 @@ class ProtocolsController < ApplicationController end def check_edit_permissions - load_organization_and_type + load_team_and_type @protocol = Protocol.find_by_id(params[:id]) unless can_edit_protocol(@protocol) @@ -1012,13 +1012,13 @@ class ProtocolsController < ApplicationController def check_import_permissions @protocol_json = params[:protocol] - @organization = Organization.find(params[:organization_id]) + @team = Organization.find(params[:team_id]) @type = params[:type] ? params[:type].to_sym : nil if !( @protocol_json.present? && - @organization.present? && + @team.present? && (@type == :public || @type == :private) && - can_import_protocols(@organization) + can_import_protocols(@team) ) render_403 end diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index a9c6d82d9..cb0066a6a 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -101,7 +101,7 @@ class ReportsController < ApplicationController def edit # cleans all the deleted report - current_organization_switch(@report.project.organization) + current_team_switch(@report.project.team) @report.cleanup_report render 'reports/new.html.erb' end diff --git a/app/controllers/result_assets_controller.rb b/app/controllers/result_assets_controller.rb index 29b90d316..ada53aef7 100644 --- a/app/controllers/result_assets_controller.rb +++ b/app/controllers/result_assets_controller.rb @@ -40,7 +40,7 @@ class ResultAssetsController < ApplicationController respond_to do |format| if (@result.save and @asset.save) then # Post process file here - @asset.post_process_file(@my_module.experiment.project.organization) + @asset.post_process_file(@my_module.experiment.project.team) # Generate activity Activity.create( @@ -129,15 +129,15 @@ class ResultAssetsController < ApplicationController saved = @result.save if saved then - # Release organization's space taken due to + # Release team's space taken due to # previous asset being removed - org = @result.my_module.experiment.project.organization - org.release_space(previous_size) - org.save + team = @result.my_module.experiment.project.team + team.release_space(previous_size) + team.save # Post process new file if neccesary if @result.asset.present? - @result.asset.post_process_file(org) + @result.asset.post_process_file(team) end Activity.create( diff --git a/app/controllers/sample_groups_controller.rb b/app/controllers/sample_groups_controller.rb index 22433cb53..2fd112572 100644 --- a/app/controllers/sample_groups_controller.rb +++ b/app/controllers/sample_groups_controller.rb @@ -7,7 +7,7 @@ class SampleGroupsController < ApplicationController def create @sample_group = SampleGroup.new(sample_group_params) - @sample_group.organization = @organization + @sample_group.team = @team @sample_group.created_by = current_user @sample_group.last_modified_by = current_user @@ -18,7 +18,7 @@ class SampleGroupsController < ApplicationController html: render_to_string( partial: 'sample_group.html.erb', locals: { sample_group: @sample_group, - organization: @organization } + team: @team } ) }, status: :ok @@ -33,8 +33,8 @@ class SampleGroupsController < ApplicationController end def index - render_404 unless current_organization - @sample_groups = current_organization.sample_groups + render_404 unless current_team + @sample_groups = current_team.sample_groups end def update @@ -47,7 +47,7 @@ class SampleGroupsController < ApplicationController html: render_to_string( partial: 'sample_group.html.erb', locals: { sample_group: @sample_group, - organization: @organization } + team: @team } ) } else @@ -66,7 +66,7 @@ class SampleGroupsController < ApplicationController render_to_string( partial: 'edit.html.erb', locals: { sample_group: @sample_group, - organization: @organization } + team: @team } ), id: @sample_group.id } @@ -81,7 +81,7 @@ class SampleGroupsController < ApplicationController html: render_to_string( partial: 'sample_group.html.erb', locals: { sample_group: @sample_group, - organization: @organization } + team: @team } ) } end @@ -95,7 +95,7 @@ class SampleGroupsController < ApplicationController html: render_to_string( partial: 'delete_sample_group_modal.html.erb', locals: { sample_group: @sample_group, - organization: @organization } + team: @team } ) } end @@ -128,13 +128,13 @@ class SampleGroupsController < ApplicationController end def load_vars_nested - @organization = Organization.find_by_id(params[:organization_id]) + @team = Organization.find_by_id(params[:team_id]) - render_404 unless @organization + render_404 unless @team end def check_create_permissions - render_403 unless can_create_sample_type_in_organization(@organization) + render_403 unless can_create_sample_type_in_team(@team) end def sample_group_params diff --git a/app/controllers/sample_my_modules_controller.rb b/app/controllers/sample_my_modules_controller.rb index f42b120ee..81b1e0632 100644 --- a/app/controllers/sample_my_modules_controller.rb +++ b/app/controllers/sample_my_modules_controller.rb @@ -6,10 +6,10 @@ class SampleMyModulesController < ApplicationController @number_of_samples = @my_module.number_of_samples @samples = @my_module.first_n_samples - current_organization_switch(@my_module + current_team_switch(@my_module .experiment .project - .organization) + .team) respond_to do |format| format.json { render :json => { diff --git a/app/controllers/sample_types_controller.rb b/app/controllers/sample_types_controller.rb index 1b0275dee..b4e0df81f 100644 --- a/app/controllers/sample_types_controller.rb +++ b/app/controllers/sample_types_controller.rb @@ -7,7 +7,7 @@ class SampleTypesController < ApplicationController def create @sample_type = SampleType.new(sample_type_params) - @sample_type.organization = @organization + @sample_type.team = @team @sample_type.created_by = current_user @sample_type.last_modified_by = current_user @@ -18,7 +18,7 @@ class SampleTypesController < ApplicationController html: render_to_string( partial: 'sample_type.html.erb', locals: { sample_type: @sample_type, - organization: @organization } + team: @team } ) }, status: :ok @@ -33,8 +33,8 @@ class SampleTypesController < ApplicationController end def index - render_404 unless current_organization - @sample_types = current_organization.sample_types + render_404 unless current_team + @sample_types = current_team.sample_types end def edit @@ -45,7 +45,7 @@ class SampleTypesController < ApplicationController render_to_string( partial: 'edit.html.erb', locals: { sample_type: @sample_type, - organization: @organization } + team: @team } ), id: @sample_type.id } @@ -63,7 +63,7 @@ class SampleTypesController < ApplicationController html: render_to_string( partial: 'sample_type.html.erb', locals: { sample_type: @sample_type, - organization: @organization } + team: @team } ) } else @@ -81,7 +81,7 @@ class SampleTypesController < ApplicationController html: render_to_string( partial: 'delete_sample_type_modal.html.erb', locals: { sample_type: @sample_type, - organization: @organization } + team: @team } ) } end @@ -105,7 +105,7 @@ class SampleTypesController < ApplicationController html: render_to_string( partial: 'sample_type.html.erb', locals: { sample_type: @sample_type, - organization: @organization } + team: @team } ) } end @@ -124,13 +124,13 @@ class SampleTypesController < ApplicationController end def load_vars_nested - @organization = Organization.find_by_id(params[:organization_id]) + @team = Organization.find_by_id(params[:team_id]) - render_404 unless @organization + render_404 unless @team end def check_create_permissions - render_403 unless can_create_sample_type_in_organization(@organization) + render_403 unless can_create_sample_type_in_team(@team) end def set_sample_type diff --git a/app/controllers/samples_controller.rb b/app/controllers/samples_controller.rb index 27e778101..9143cd128 100644 --- a/app/controllers/samples_controller.rb +++ b/app/controllers/samples_controller.rb @@ -10,11 +10,11 @@ class SamplesController < ApplicationController def new respond_to do |format| format.html - if can_create_samples(@organization) + if can_create_samples(@team) format.json { render json: { - sample_groups: @organization.sample_groups.as_json(only: [:id, :name, :color]), - sample_types: @organization.sample_types.as_json(only: [:id, :name]) + sample_groups: @team.sample_groups.as_json(only: [:id, :name, :color]), + sample_types: @team.sample_types.as_json(only: [:id, :name]) } } else @@ -26,7 +26,7 @@ class SamplesController < ApplicationController def create sample = Sample.new( user: current_user, - organization: @organization + team: @team ) sample.last_modified_by = current_user errors = { @@ -35,7 +35,7 @@ class SamplesController < ApplicationController }; respond_to do |format| - if can_create_samples(@organization) + if can_create_samples(@team) if params[:sample] # Sample name if params[:sample][:name] @@ -88,7 +88,7 @@ class SamplesController < ApplicationController flash: t( 'samples.create.success_flash', sample: escape_input(sample.name), - organization: escape_input(@organization.name) + team: escape_input(@team.name) ) }, status: :ok @@ -122,8 +122,8 @@ class SamplesController < ApplicationController sample_group: @sample.sample_group.nil? ? "" : @sample.sample_group.id, custom_fields: {} }, - sample_groups: @organization.sample_groups.as_json(only: [:id, :name, :color]), - sample_types: @organization.sample_types.as_json(only: [:id, :name]) + sample_groups: @team.sample_groups.as_json(only: [:id, :name, :color]), + sample_types: @team.sample_types.as_json(only: [:id, :name]) } # Add custom fields ids as key (easier lookup on js side) @@ -257,7 +257,7 @@ class SamplesController < ApplicationController flash: t( 'samples.update.success_flash', sample: escape_input(sample.name), - organization: escape_input(@organization.name) + team: escape_input(@team.name) ) }, status: :ok @@ -281,7 +281,7 @@ class SamplesController < ApplicationController def load_vars @sample = Sample.find_by_id(params[:id]) - @organization = current_organization + @team = current_team unless @sample render_404 @@ -289,15 +289,15 @@ class SamplesController < ApplicationController end def load_vars_nested - @organization = Organization.find_by_id(params[:organization_id]) + @team = Organization.find_by_id(params[:team_id]) - unless @organization + unless @team render_404 end end def check_create_permissions - unless can_create_samples(@organization) + unless can_create_samples(@team) render_403 end end @@ -309,7 +309,7 @@ class SamplesController < ApplicationController end def check_destroy_permissions - unless can_delete_samples(@organization) + unless can_delete_samples(@team) render_403 end end diff --git a/app/controllers/steps_controller.rb b/app/controllers/steps_controller.rb index 18c55cb90..cf0480acc 100644 --- a/app/controllers/steps_controller.rb +++ b/app/controllers/steps_controller.rb @@ -45,7 +45,7 @@ class StepsController < ApplicationController if @step.save # Post process all assets @step.assets.each do |asset| - asset.post_process_file(@protocol.organization) + asset.post_process_file(@protocol.team) end # Generate activity @@ -63,7 +63,7 @@ class StepsController < ApplicationController ) ) else - # TODO: Activity for organization if step + # TODO: Activity for team if step # created in protocol management?? end @@ -136,14 +136,14 @@ class StepsController < ApplicationController if @step.save @step.reload - # Release organization's space taken - org = @protocol.organization - org.release_space(previous_size) - org.save + # Release team's space taken + team = @protocol.team + team.release_space(previous_size) + team.save # Post process step assets @step.assets.each do |asset| - asset.post_process_file(org) + asset.post_process_file(team) end # Generate activity @@ -161,7 +161,7 @@ class StepsController < ApplicationController ) ) else - # TODO: Activity for organization if step + # TODO: Activity for team if step # updated in protocol management?? end @@ -192,15 +192,15 @@ class StepsController < ApplicationController end # Calculate space taken by this step - org = @protocol.organization + team = @protocol.team previous_size = @step.space_taken # Destroy the step @step.destroy(current_user) # Release space taken by the step - org.release_space(previous_size) - org.save + team.release_space(previous_size) + team.save # Update protocol timestamp update_protocol_ts(@step) diff --git a/app/controllers/organizations_controller.rb b/app/controllers/teams_controller.rb similarity index 85% rename from app/controllers/organizations_controller.rb rename to app/controllers/teams_controller.rb index 31b0110ca..35db815a0 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/teams_controller.rb @@ -30,7 +30,7 @@ class OrganizationsController < ApplicationController # Check if we actually have any rows (last_row > 1) if sheet.last_row.between?(0, 1) flash[:notice] = t( - "organizations.parse_sheet.errors.empty_file") + "teams.parse_sheet.errors.empty_file") redirect_to session.delete(:return_to) and return end @@ -40,7 +40,7 @@ class OrganizationsController < ApplicationController @rows << Hash[[@header, sheet.row(2)].transpose] # Fill in fields for dropdown - @available_fields = @organization.get_available_sample_fields + @available_fields = @team.get_available_sample_fields # Truncate long fields @available_fields.update(@available_fields) do |_k, v| v.truncate(Constants::NAME_TRUNCATION_LENGTH_DROPDOWN) @@ -62,7 +62,7 @@ class OrganizationsController < ApplicationController } } else - error = t("organizations.parse_sheet.errors.temp_file_failure") + error = t("teams.parse_sheet.errors.temp_file_failure") format.html { flash[:alert] = error redirect_to session.delete(:return_to) @@ -74,7 +74,7 @@ class OrganizationsController < ApplicationController end end rescue ArgumentError, CSV::MalformedCSVError - error = t('organizations.parse_sheet.errors.invalid_file', + error = t('teams.parse_sheet.errors.invalid_file', encoding: ''.encoding) format.html { flash[:alert] = error @@ -85,7 +85,7 @@ class OrganizationsController < ApplicationController status: :unprocessable_entity } rescue TypeError - error = t("organizations.parse_sheet.errors.invalid_extension") + error = t("teams.parse_sheet.errors.invalid_extension") format.html { flash[:alert] = error redirect_to session.delete(:return_to) @@ -96,7 +96,7 @@ class OrganizationsController < ApplicationController } end else - error = t("organizations.parse_sheet.errors.no_file_selected") + error = t("teams.parse_sheet.errors.no_file_selected") format.html { flash[:alert] = error session[:return_to] ||= request.referer @@ -130,7 +130,7 @@ class OrganizationsController < ApplicationController # Check if there exist mapping for sample name (it's mandatory) if params[:mappings].has_value?("-1") - result = @organization.import_samples(@sheet, params[:mappings], current_user) + result = @team.import_samples(@sheet, params[:mappings], current_user) nr_of_added = result[:nr_of_added] total_nr = result[:total_nr] @@ -138,10 +138,10 @@ class OrganizationsController < ApplicationController # If no errors are present, redirect back # to samples table flash[:success] = t( - "organizations.import_samples.success_flash", + "teams.import_samples.success_flash", nr: nr_of_added, samples: t( - "organizations.import_samples.sample", + "teams.import_samples.sample", count: total_nr ) ) @@ -157,10 +157,10 @@ class OrganizationsController < ApplicationController # Otherwise, also redirect back, # but display different message flash[:alert] = t( - "organizations.import_samples.partial_success_flash", + "teams.import_samples.partial_success_flash", nr: nr_of_added, samples: t( - "organizations.import_samples.sample", + "teams.import_samples.sample", count: total_nr ) ) @@ -176,7 +176,7 @@ class OrganizationsController < ApplicationController else # This is currently the only AJAX error response flash_alert = t( - "organizations.import_samples.errors.no_sample_name") + "teams.import_samples.errors.no_sample_name") format.html { flash[:alert] = flash_alert redirect_to session.delete(:return_to) @@ -195,7 +195,7 @@ class OrganizationsController < ApplicationController # This code should never execute unless user tampers with # JS (selects same column in more than one dropdown) flash_alert = t( - "organizations.import_samples.errors.duplicated_values") + "teams.import_samples.errors.duplicated_values") format.html { flash[:alert] = flash_alert redirect_to session.delete(:return_to) @@ -213,7 +213,7 @@ class OrganizationsController < ApplicationController else @temp_file.destroy flash[:alert] = t( - "organizations.import_samples.errors.no_data_to_parse") + "teams.import_samples.errors.no_data_to_parse") format.html { redirect_to session.delete(:return_to) } @@ -225,7 +225,7 @@ class OrganizationsController < ApplicationController else @temp_file.destroy flash[:alert] = t( - "organizations.import_samples.errors.session_expired") + "teams.import_samples.errors.session_expired") format.html { redirect_to session.delete(:return_to) } @@ -237,7 +237,7 @@ class OrganizationsController < ApplicationController else # No temp file to begin with, so no need to destroy it flash[:alert] = t( - "organizations.import_samples.errors.temp_file_not_found") + "teams.import_samples.errors.temp_file_not_found") format.html { redirect_to session.delete(:return_to) } @@ -248,7 +248,7 @@ class OrganizationsController < ApplicationController end else flash[:alert] = t( - "organizations.import_samples.errors.temp_file_not_found") + "teams.import_samples.errors.temp_file_not_found") format.html { redirect_to session.delete(:return_to) } @@ -274,7 +274,7 @@ class OrganizationsController < ApplicationController samples << sample end end - format.csv { send_data @organization.to_csv(samples, params[:header_ids]) } + format.csv { send_data @team.to_csv(samples, params[:header_ids]) } else format.csv { render nothing: true } end @@ -282,21 +282,21 @@ class OrganizationsController < ApplicationController end def load_vars - @organization = Organization.find_by_id(params[:id]) + @team = Organization.find_by_id(params[:id]) - unless @organization + unless @team render_404 end end def check_create_sample_permissions - unless can_create_samples(@organization) + unless can_create_samples(@team) render_403 end end def check_view_samples_permission - unless can_view_samples(@organization) + unless can_view_samples(@team) render_403 end end diff --git a/app/controllers/user_samples_controller.rb b/app/controllers/user_samples_controller.rb index a499420e1..df8ce9ee8 100644 --- a/app/controllers/user_samples_controller.rb +++ b/app/controllers/user_samples_controller.rb @@ -1,12 +1,12 @@ class UserSamplesController < ApplicationController def save_samples_table_status samples_table = SamplesTable.where(user: @current_user, - organization: params[:org]) + team: params[:team]) if samples_table samples_table.first.update(status: params[:state]) else SamplesTable.create(user: @current_user, - organization: params[:org], + team: params[:team], status: params[:state]) end respond_to do |format| @@ -20,7 +20,7 @@ class UserSamplesController < ApplicationController def load_samples_table_status @samples_table_state = SamplesTable.find_status(current_user, - current_organization).first + current_team).first respond_to do |format| if @samples_table_state diff --git a/app/controllers/users/invitations_controller.rb b/app/controllers/users/invitations_controller.rb index 8132fd277..e934a13b8 100644 --- a/app/controllers/users/invitations_controller.rb +++ b/app/controllers/users/invitations_controller.rb @@ -9,18 +9,18 @@ module Users before_filter :update_sanitized_params, only: :update def update - # Instantialize a new organization with the provided name - @org = Organization.new - @org.name = params[:organization][:name] + # Instantialize a new team with the provided name + @team = Organization.new + @team.name = params[:team][:name] super do |user| if user.errors.empty? - @org.created_by = user - @org.save + @team.created_by = user + @team.save UserOrganization.create( user: user, - organization: @org, + team: @team, role: 'admin' ) end @@ -28,7 +28,7 @@ module Users end def accept_resource - unless @org.valid? + unless @team.valid? # Find the user being invited resource = User.find_by_invitation_token( update_resource_params[:invitation_token], @@ -41,8 +41,8 @@ module Users ) resource.valid? # Call validation to generate errors - # In any case, add the organization name error - resource.errors.add(:base, @org.errors.to_a.first) + # In any case, add the team name error + resource.errors.add(:base, @team.errors.to_a.first) return resource end @@ -100,38 +100,38 @@ module Users end end - if @org.present? && result[:status] != :user_invalid - if UserOrganization.exists?(user: user, organization: @org) - user_org = - UserOrganization.where(user: user, organization: @org).first + if @team.present? && result[:status] != :user_invalid + if UserOrganization.exists?(user: user, team: @team) + user_team = + UserOrganization.where(user: user, team: @team).first - result[:status] = :user_exists_and_in_org + result[:status] = :user_exists_and_in_team else - # Also generate user organization relation - user_org = UserOrganization.new( + # Also generate user team relation + user_team = UserOrganization.new( user: user, - organization: @org, + team: @team, role: @role ) - user_org.save + user_team.save generate_notification( @user, user, - user_org.role_str, - user_org.organization + user_team.role_str, + user_team.team ) if result[:status] == :user_exists && !user.confirmed? - result[:status] = :user_exists_unconfirmed_invited_to_org + result[:status] = :user_exists_unconfirmed_invited_to_team elsif result[:status] == :user_exists - result[:status] = :user_exists_invited_to_org + result[:status] = :user_exists_invited_to_team else - result[:status] = :user_created_invited_to_org + result[:status] = :user_created_invited_to_team end end - result[:user_org] = user_org + result[:user_team] = user_team end @invite_results << result @@ -165,14 +165,14 @@ module Users end end - def generate_notification(user, target_user, role, org) - title = I18n.t('notifications.assign_user_to_organization', + def generate_notification(user, target_user, role, team) + title = I18n.t('notifications.assign_user_to_team', assigned_user: target_user.name, role: role, - organization: org.name, + team: team.name, assigned_by_user: user.name) - message = "#{I18n.t('search.index.organization')} #{org.name}" + message = "#{I18n.t('search.index.team')} #{team.name}" notification = Notification.create( type_of: :assignment, title: ActionController::Base.helpers.sanitize(title), @@ -187,11 +187,11 @@ module Users def check_invite_users_permission @user = current_user @emails = params[:emails] - @org = Organization.find_by_id(params['organizationId']) + @team = Organization.find_by_id(params['teamId']) @role = params['role'] render_403 if @emails && @emails.empty? - render_403 if @org && !is_admin_of_organization(@org) + render_403 if @team && !is_admin_of_team(@team) render_403 if @role && !UserOrganization.roles.keys.include?(@role) end end diff --git a/app/controllers/users/registrations_controller.rb b/app/controllers/users/registrations_controller.rb index ca9966e66..8aaf2fb4b 100644 --- a/app/controllers/users/registrations_controller.rb +++ b/app/controllers/users/registrations_controller.rb @@ -126,14 +126,14 @@ class Users::RegistrationsController < Devise::RegistrationsController build_resource(sign_up_params) valid_resource = resource.valid? - # Create new organization for the new user - @org = Organization.new - @org.name = params[:organization][:name] - valid_org = @org.valid? + # Create new team for the new user + @team = Organization.new + @team.name = params[:team][:name] + valid_team = @team.valid? - if valid_org && valid_resource + if valid_team && valid_resource - # this must be called after @org variable is defined. Otherwise this + # this must be called after @team variable is defined. Otherwise this # variable won't be accessable in view. super do |resource| # Set the confirmed_at == created_at IF not using email confirmations @@ -142,18 +142,18 @@ class Users::RegistrationsController < Devise::RegistrationsController end if resource.valid? && resource.persisted? - @org.created_by = resource # set created_by for oraganization - @org.save + @team.created_by = resource # set created_by for oraganization + @team.save - # Add this user to the organization as owner + # Add this user to the team as owner UserOrganization.create( user: resource, - organization: @org, + team: @team, role: :admin ) - # set current organization to new user - resource.current_organization_id = @org.id + # set current team to new user + resource.current_team_id = @team.id resource.save end end @@ -247,9 +247,9 @@ class Users::RegistrationsController < Devise::RegistrationsController # Construct new resource before rendering :new self.resource = resource_class.new sign_up_params - # Also validate organization - @org = Organization.new(name: params[:organization][:name]) - @org.valid? + # Also validate team + @team = Organization.new(name: params[:team][:name]) + @team.valid? respond_with_navigational(resource) { render :new } end diff --git a/app/controllers/users/settings_controller.rb b/app/controllers/users/settings_controller.rb index 190aed9ef..407d11338 100644 --- a/app/controllers/users/settings_controller.rb +++ b/app/controllers/users/settings_controller.rb @@ -6,31 +6,31 @@ class Users::SettingsController < ApplicationController before_action :load_user, only: [ :preferences, :update_preferences, - :organizations, - :organization, - :create_organization, - :organization_users_datatable, + :teams, + :team, + :create_team, + :team_users_datatable, :tutorial, :reset_tutorial, :notifications_settings, - :user_current_organization, - :destroy_user_organization + :user_current_team, + :destroy_user_team ] - before_action :check_organization_permission, only: [ - :organization, - :update_organization, - :destroy_organization, - :organization_name, - :organization_description, - :organization_users_datatable + before_action :check_team_permission, only: [ + :team, + :update_team, + :destroy_team, + :team_name, + :team_description, + :team_users_datatable ] - before_action :check_user_organization_permission, only: [ - :update_user_organization, - :leave_user_organization_html, - :destroy_user_organization_html, - :destroy_user_organization + before_action :check_user_team_permission, only: [ + :update_user_team, + :leave_user_team_html, + :destroy_user_team_html, + :destroy_user_team ] def preferences @@ -53,114 +53,114 @@ class Users::SettingsController < ApplicationController end end - def organizations - @user_orgs = + def teams + @user_teams = @user - .user_organizations - .includes(organization: :users) + .user_teams + .includes(team: :users) .order(created_at: :asc) - @member_of = @user_orgs.count + @member_of = @user_teams.count end - def organization - @user_org = UserOrganization.find_by(user: @user, organization: @org) + def team + @user_team = UserOrganization.find_by(user: @user, team: @team) end - def update_organization + def update_team respond_to do |format| - if @org.update(update_organization_params) - @org.update(last_modified_by: current_user) + if @team.update(update_team_params) + @team.update(last_modified_by: current_user) format.json { render json: { status: :ok, description_label: render_to_string( - partial: "users/settings/organizations/description_label.html.erb", - locals: { org: @org } + partial: "users/settings/teams/description_label.html.erb", + locals: { team: @team } ) } } else format.json { - render json: @org.errors, + render json: @team.errors, status: :unprocessable_entity } end end end - def organization_name + def team_name respond_to do |format| format.json { render json: { html: render_to_string({ - partial: "users/settings/organizations/name_modal_body.html.erb", - locals: { org: @org } + partial: "users/settings/teams/name_modal_body.html.erb", + locals: { team: @team } }) } } end end - def organization_description + def team_description respond_to do |format| format.json { render json: { html: render_to_string({ - partial: "users/settings/organizations/description_modal_body.html.erb", - locals: { org: @org } + partial: "users/settings/teams/description_modal_body.html.erb", + locals: { team: @team } }) } } end end - def organization_users_datatable + def team_users_datatable respond_to do |format| format.json { - render json: ::OrganizationUsersDatatable.new(view_context, @org, @user) + render json: ::OrganizationUsersDatatable.new(view_context, @team, @user) } end end - def new_organization - @new_org = Organization.new + def new_team + @new_team = Organization.new end - def create_organization - @new_org = Organization.new(create_organization_params) - @new_org.created_by = @user + def create_team + @new_team = Organization.new(create_team_params) + @new_team.created_by = @user - if @new_org.save - # Okay, organization is created, now + if @new_team.save + # Okay, team is created, now # add the current user as admin UserOrganization.create( user: @user, - organization: @new_org, + team: @new_team, role: 2 ) - # Redirect to new organization page - redirect_to action: :organization, organization_id: @new_org.id + # Redirect to new team page + redirect_to action: :team, team_id: @new_team.id else - render :new_organization + render :new_team end end - def destroy_organization - @org.destroy + def destroy_team + @team.destroy flash[:notice] = I18n.t( - "users.settings.organizations.edit.modal_destroy_organization.flash_success", - org: @org.name + "users.settings.teams.edit.modal_destroy_team.flash_success", + team: @team.name ) - # Redirect back to all organizations page - redirect_to action: :organizations + # Redirect back to all teams page + redirect_to action: :teams end - def update_user_organization + def update_user_team respond_to do |format| - if @user_org.update(update_user_organization_params) + if @user_team.update(update_user_team_params) format.json { render json: { status: :ok @@ -168,57 +168,57 @@ class Users::SettingsController < ApplicationController } else format.json { - render json: @user_org.errors, + render json: @user_team.errors, status: :unprocessable_entity } end end end - def leave_user_organization_html + def leave_user_team_html respond_to do |format| format.json { render json: { html: render_to_string({ - partial: "users/settings/organizations/leave_user_organization_modal_body.html.erb", - locals: { user_organization: @user_org } + partial: "users/settings/teams/leave_user_team_modal_body.html.erb", + locals: { user_team: @user_team } }), heading: I18n.t( - "users.settings.organizations.index.leave_uo_heading", - org: escape_input(@user_org.organization.name) + "users.settings.teams.index.leave_uo_heading", + team: escape_input(@user_team.team.name) ) } } end end - def destroy_user_organization_html + def destroy_user_team_html respond_to do |format| format.json { render json: { html: render_to_string({ - partial: "users/settings/organizations/destroy_user_organization_modal_body.html.erb", - locals: { user_organization: @user_org } + partial: "users/settings/teams/destroy_user_team_modal_body.html.erb", + locals: { user_team: @user_team } }), heading: I18n.t( - "users.settings.organizations.edit.destroy_uo_heading", - user: escape_input(@user_org.user.full_name), - org: escape_input(@user_org.organization.name) + "users.settings.teams.edit.destroy_uo_heading", + user: escape_input(@user_team.user.full_name), + team: escape_input(@user_team.team.name) ) } } end end - def destroy_user_organization + def destroy_user_team respond_to do |format| - # If user is last administrator of organization, + # If user is last administrator of team, # he/she cannot be deleted from it. invalid = - @user_org.admin? && - @user_org - .organization - .user_organizations + @user_team.admin? && + @user_team + .team + .user_teams .where(role: 2) .count <= 1 @@ -227,24 +227,24 @@ class Users::SettingsController < ApplicationController UserOrganization.transaction do # If user leaves on his/her own accord, # new owner for projects is the first - # administrator of organization + # administrator of team if params[:leave] new_owner = - @user_org - .organization - .user_organizations + @user_team + .team + .user_teams .where(role: 2) - .where.not(id: @user_org.id) + .where.not(id: @user_team.id) .first .user else # Otherwise, the new owner for projects is # the current user (= an administrator removing - # the user from the organization) + # the user from the team) new_owner = current_user end - reset_user_current_organization(@user_org) - @user_org.destroy(new_owner) + reset_user_current_team(@user_team) + @user_team.destroy(new_owner) end rescue Exception invalid = true @@ -254,14 +254,14 @@ class Users::SettingsController < ApplicationController if !invalid if params[:leave] then flash[:notice] = I18n.t( - "users.settings.organizations.index.leave_flash", - org: @user_org.organization.name + "users.settings.teams.index.leave_flash", + team: @user_team.team.name ) flash.keep(:notice) end - generate_notification(@user_organization.user, - @user_org.user, - @user_org.organization, + generate_notification(@user_team.user, + @user_team.user, + @user_team.team, false, false) format.json { @@ -271,7 +271,7 @@ class Users::SettingsController < ApplicationController } else format.json { - render json: @user_org.errors, + render json: @user_team.errors, status: :unprocessable_entity } end @@ -279,14 +279,14 @@ class Users::SettingsController < ApplicationController end def tutorial - @orgs = + @teams = @user - .user_organizations - .includes(organization: :users) + .user_teams + .includes(team: :users) .where(role: 1..2) .order(created_at: :asc) - .map { |uo| uo.organization } - @member_of = @orgs.count + .map { |uo| uo.team } + @member_of = @teams.count respond_to do |format| format.json { @@ -301,12 +301,12 @@ class Users::SettingsController < ApplicationController end def reset_tutorial - if @user.update(tutorial_status: 0) && params[:org][:id].present? - @user.update(current_organization_id: params[:org][:id]) + if @user.update(tutorial_status: 0) && params[:team][:id].present? + @user.update(current_team_id: params[:team][:id]) cookies.delete :tutorial_data cookies.delete :current_tutorial_step - cookies[:repeat_tutorial_org_id] = { - value: params[:org][:id], + cookies[:repeat_tutorial_team_id] = { + value: params[:team][:id], expires: 1.day.from_now } @@ -348,15 +348,15 @@ class Users::SettingsController < ApplicationController end end - def user_current_organization - @user.current_organization_id = params[:user][:current_organization_id] - @changed_org = Organization.find_by_id(@user.current_organization_id) - if params[:user][:current_organization_id].present? && @user.save - flash[:success] = t('users.settings.changed_org_flash', - team: @changed_org.name) + def user_current_team + @user.current_team_id = params[:user][:current_team_id] + @changed_team = Organization.find_by_id(@user.current_team_id) + if params[:user][:current_team_id].present? && @user.save + flash[:success] = t('users.settings.changed_team_flash', + team: @changed_team.name) redirect_to root_path else - flash[:alert] = t('users.settings.changed_org_error_flash') + flash[:alert] = t('users.settings.changed_team_error_flash') redirect_to :back end end @@ -367,20 +367,20 @@ class Users::SettingsController < ApplicationController @user = current_user end - def check_organization_permission - @org = Organization.find_by_id(params[:organization_id]) - unless is_admin_of_organization(@org) + def check_team_permission + @team = Organization.find_by_id(params[:team_id]) + unless is_admin_of_team(@team) render_403 end end - def check_user_organization_permission - @user_org = UserOrganization.find_by_id(params[:user_organization_id]) - @org = @user_org.organization + def check_user_team_permission + @user_team = UserOrganization.find_by_id(params[:user_team_id]) + @team = @user_team.team # Don't allow the user to modify UserOrganization-s if he's not admin, # unless he/she is modifying his/her UserOrganization - if current_user != @user_org.user and - !is_admin_of_organization(@user_org.organization) + if current_user != @user_team.user and + !is_admin_of_team(@user_team.team) render_403 end end @@ -391,15 +391,15 @@ class Users::SettingsController < ApplicationController ) end - def create_organization_params - params.require(:organization).permit( + def create_team_params + params.require(:team).permit( :name, :description ) end - def update_organization_params - params.require(:organization).permit( + def update_team_params + params.require(:team).permit( :name, :description ) @@ -412,16 +412,16 @@ class Users::SettingsController < ApplicationController ) end - def update_user_organization_params - params.require(:user_organization).permit( + def update_user_team_params + params.require(:user_team).permit( :role ) end - def reset_user_current_organization(user_org) - ids = user_org.user.organizations_ids - ids -= [user_org.organization.id] - user_org.user.current_organization_id = ids.first - user_org.user.save + def reset_user_current_team(user_team) + ids = user_team.user.teams_ids + ids -= [user_team.team.id] + user_team.user.current_team_id = ids.first + user_team.user.save end end