From c2c56160780f044c0e06160074e53c036230dada Mon Sep 17 00:00:00 2001 From: zmagod Date: Tue, 24 Jan 2017 17:06:51 +0100 Subject: [PATCH] rename Organization to Team in controllers --- app/controllers/application_controller.rb | 2 +- app/controllers/at_who_controller.rb | 2 +- app/controllers/custom_fields_controller.rb | 2 +- app/controllers/experiments_controller.rb | 2 +- app/controllers/my_modules_controller.rb | 2 +- app/controllers/projects_controller.rb | 12 +++++----- app/controllers/protocols_controller.rb | 2 +- app/controllers/reports_controller.rb | 2 +- app/controllers/sample_groups_controller.rb | 2 +- .../sample_my_modules_controller.rb | 2 +- app/controllers/sample_types_controller.rb | 2 +- app/controllers/samples_controller.rb | 2 +- app/controllers/teams_controller.rb | 8 +++---- .../users/invitations_controller.rb | 14 ++++++------ .../users/registrations_controller.rb | 6 ++--- app/controllers/users/settings_controller.rb | 22 +++++++++---------- 16 files changed, 41 insertions(+), 43 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 210683b7a..f0314e07a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -27,7 +27,7 @@ class ApplicationController < ActionController::Base # Sets current team for all controllers def current_team - Organization.find_by_id(current_user.current_team_id) + Team.find_by_id(current_user.current_team_id) end protected diff --git a/app/controllers/at_who_controller.rb b/app/controllers/at_who_controller.rb index c697ed048..0e9625baf 100644 --- a/app/controllers/at_who_controller.rb +++ b/app/controllers/at_who_controller.rb @@ -96,7 +96,7 @@ class AtWhoController < ApplicationController private def load_vars - @team = Organization.find_by_id(params[:id]) + @team = Team.find_by_id(params[:id]) @query = params[:query] render_404 unless @team end diff --git a/app/controllers/custom_fields_controller.rb b/app/controllers/custom_fields_controller.rb index 0126b2343..64fc2519a 100644 --- a/app/controllers/custom_fields_controller.rb +++ b/app/controllers/custom_fields_controller.rb @@ -91,7 +91,7 @@ class CustomFieldsController < ApplicationController end def load_vars_nested - @team = Organization.find_by_id(params[:team_id]) + @team = Team.find_by_id(params[:team_id]) render_404 unless @team end diff --git a/app/controllers/experiments_controller.rb b/app/controllers/experiments_controller.rb index d6a95e7e3..d31c28199 100644 --- a/app/controllers/experiments_controller.rb +++ b/app/controllers/experiments_controller.rb @@ -1,7 +1,7 @@ class ExperimentsController < ApplicationController include SampleActions include PermissionHelper - include OrganizationsHelper + include TeamsHelper include InputSanitizeHelper before_action :set_experiment, diff --git a/app/controllers/my_modules_controller.rb b/app/controllers/my_modules_controller.rb index 9fe9fe54b..38be3a7ae 100644 --- a/app/controllers/my_modules_controller.rb +++ b/app/controllers/my_modules_controller.rb @@ -1,6 +1,6 @@ class MyModulesController < ApplicationController include SampleActions - include OrganizationsHelper + include TeamsHelper include InputSanitizeHelper before_action :load_vars, only: [ diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index b8edacf32..9d6ca0bed 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -1,7 +1,7 @@ class ProjectsController < ApplicationController include SampleActions include RenamingUtil - include OrganizationsHelper + include TeamsHelper include InputSanitizeHelper before_action :load_vars, only: [:show, :edit, :update, @@ -26,8 +26,7 @@ class ProjectsController < ApplicationController def index if params[:team] - current_team_switch(Organization - .find_by_id(params[:team])) + current_team_switch(Team.find_by_id(params[:team])) end if current_user.teams.any? @@ -35,10 +34,9 @@ class ProjectsController < ApplicationController @current_team_id ||= current_user.teams.first.id @current_sort = params[:sort].to_s - @projects_by_teams = current_user - .projects_by_teams(@current_team_id, - @current_sort, - @filter_by_archived) + @projects_by_teams = current_user.projects_by_teams(@current_team_id, + @current_sort, + @filter_by_archived) end @teams = current_user.teams diff --git a/app/controllers/protocols_controller.rb b/app/controllers/protocols_controller.rb index 47dd49af2..e5b21f3b4 100644 --- a/app/controllers/protocols_controller.rb +++ b/app/controllers/protocols_controller.rb @@ -1012,7 +1012,7 @@ class ProtocolsController < ApplicationController def check_import_permissions @protocol_json = params[:protocol] - @team = Organization.find(params[:team_id]) + @team = Team.find(params[:team_id]) @type = params[:type] ? params[:type].to_sym : nil if !( @protocol_json.present? && diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index cb0066a6a..1f5cb5ef8 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -1,5 +1,5 @@ class ReportsController < ApplicationController - include OrganizationsHelper + include TeamsHelper # Ignore CSRF protection just for PDF generation (because it's # used via target='_blank') protect_from_forgery with: :exception, :except => :generate diff --git a/app/controllers/sample_groups_controller.rb b/app/controllers/sample_groups_controller.rb index 2fd112572..58976274c 100644 --- a/app/controllers/sample_groups_controller.rb +++ b/app/controllers/sample_groups_controller.rb @@ -128,7 +128,7 @@ class SampleGroupsController < ApplicationController end def load_vars_nested - @team = Organization.find_by_id(params[:team_id]) + @team = Team.find_by_id(params[:team_id]) render_404 unless @team end diff --git a/app/controllers/sample_my_modules_controller.rb b/app/controllers/sample_my_modules_controller.rb index 81b1e0632..0e06a5c80 100644 --- a/app/controllers/sample_my_modules_controller.rb +++ b/app/controllers/sample_my_modules_controller.rb @@ -1,5 +1,5 @@ class SampleMyModulesController < ApplicationController - include OrganizationsHelper + include TeamsHelper before_action :load_vars def index diff --git a/app/controllers/sample_types_controller.rb b/app/controllers/sample_types_controller.rb index b4e0df81f..bf5699ce7 100644 --- a/app/controllers/sample_types_controller.rb +++ b/app/controllers/sample_types_controller.rb @@ -124,7 +124,7 @@ class SampleTypesController < ApplicationController end def load_vars_nested - @team = Organization.find_by_id(params[:team_id]) + @team = Team.find_by_id(params[:team_id]) render_404 unless @team end diff --git a/app/controllers/samples_controller.rb b/app/controllers/samples_controller.rb index 9143cd128..72e9f1aa5 100644 --- a/app/controllers/samples_controller.rb +++ b/app/controllers/samples_controller.rb @@ -289,7 +289,7 @@ class SamplesController < ApplicationController end def load_vars_nested - @team = Organization.find_by_id(params[:team_id]) + @team = Team.find_by_id(params[:team_id]) unless @team render_404 diff --git a/app/controllers/teams_controller.rb b/app/controllers/teams_controller.rb index 35db815a0..b0fbdb42a 100644 --- a/app/controllers/teams_controller.rb +++ b/app/controllers/teams_controller.rb @@ -1,4 +1,4 @@ -class OrganizationsController < ApplicationController +class TeamsController < ApplicationController before_action :load_vars, only: [:parse_sheet, :import_samples, :export_samples] before_action :check_create_sample_permissions, only: [:parse_sheet, :import_samples] @@ -25,7 +25,7 @@ class OrganizationsController < ApplicationController } else - sheet = Organization.open_spreadsheet(params[:file]) + sheet = Team.open_spreadsheet(params[:file]) # Check if we actually have any rows (last_row > 1) if sheet.last_row.between?(0, 1) @@ -122,7 +122,7 @@ class OrganizationsController < ApplicationController if @temp_file.session_id == session.id # Check if mappings exists or else we don't have anything to parse if params[:mappings] - @sheet = Organization.open_spreadsheet(@temp_file.file) + @sheet = Team.open_spreadsheet(@temp_file.file) # Check for duplicated values h1 = params[:mappings].clone.delete_if { |k, v| v.empty? } @@ -282,7 +282,7 @@ class OrganizationsController < ApplicationController end def load_vars - @team = Organization.find_by_id(params[:id]) + @team = Team.find_by_id(params[:id]) unless @team render_404 diff --git a/app/controllers/users/invitations_controller.rb b/app/controllers/users/invitations_controller.rb index e934a13b8..db74de1e6 100644 --- a/app/controllers/users/invitations_controller.rb +++ b/app/controllers/users/invitations_controller.rb @@ -10,7 +10,7 @@ module Users def update # Instantialize a new team with the provided name - @team = Organization.new + @team = Team.new @team.name = params[:team][:name] super do |user| @@ -18,7 +18,7 @@ module Users @team.created_by = user @team.save - UserOrganization.create( + UserTeam.create( user: user, team: @team, role: 'admin' @@ -101,14 +101,14 @@ module Users end if @team.present? && result[:status] != :user_invalid - if UserOrganization.exists?(user: user, team: @team) + if UserTeam.exists?(user: user, team: @team) user_team = - UserOrganization.where(user: user, team: @team).first + UserTeam.where(user: user, team: @team).first result[:status] = :user_exists_and_in_team else # Also generate user team relation - user_team = UserOrganization.new( + user_team = UserTeam.new( user: user, team: @team, role: @role @@ -187,12 +187,12 @@ module Users def check_invite_users_permission @user = current_user @emails = params[:emails] - @team = Organization.find_by_id(params['teamId']) + @team = Team.find_by_id(params['teamId']) @role = params['role'] render_403 if @emails && @emails.empty? render_403 if @team && !is_admin_of_team(@team) - render_403 if @role && !UserOrganization.roles.keys.include?(@role) + render_403 if @role && !UserTeam.roles.keys.include?(@role) end end end diff --git a/app/controllers/users/registrations_controller.rb b/app/controllers/users/registrations_controller.rb index 8aaf2fb4b..1a50abffd 100644 --- a/app/controllers/users/registrations_controller.rb +++ b/app/controllers/users/registrations_controller.rb @@ -127,7 +127,7 @@ class Users::RegistrationsController < Devise::RegistrationsController valid_resource = resource.valid? # Create new team for the new user - @team = Organization.new + @team = Team.new @team.name = params[:team][:name] valid_team = @team.valid? @@ -146,7 +146,7 @@ class Users::RegistrationsController < Devise::RegistrationsController @team.save # Add this user to the team as owner - UserOrganization.create( + UserTeam.create( user: resource, team: @team, role: :admin @@ -248,7 +248,7 @@ class Users::RegistrationsController < Devise::RegistrationsController self.resource = resource_class.new sign_up_params # Also validate team - @team = Organization.new(name: params[:team][:name]) + @team = Team.new(name: params[:team][:name]) @team.valid? respond_with_navigational(resource) { render :new } diff --git a/app/controllers/users/settings_controller.rb b/app/controllers/users/settings_controller.rb index 407d11338..eebd5d620 100644 --- a/app/controllers/users/settings_controller.rb +++ b/app/controllers/users/settings_controller.rb @@ -63,7 +63,7 @@ class Users::SettingsController < ApplicationController end def team - @user_team = UserOrganization.find_by(user: @user, team: @team) + @user_team = UserTeam.find_by(user: @user, team: @team) end def update_team @@ -117,23 +117,23 @@ class Users::SettingsController < ApplicationController def team_users_datatable respond_to do |format| format.json { - render json: ::OrganizationUsersDatatable.new(view_context, @team, @user) + render json: ::TeamUsersDatatable.new(view_context, @team, @user) } end end def new_team - @new_team = Organization.new + @new_team = Team.new end def create_team - @new_team = Organization.new(create_team_params) + @new_team = Team.new(create_team_params) @new_team.created_by = @user if @new_team.save # Okay, team is created, now # add the current user as admin - UserOrganization.create( + UserTeam.create( user: @user, team: @new_team, role: 2 @@ -224,7 +224,7 @@ class Users::SettingsController < ApplicationController if !invalid then begin - UserOrganization.transaction do + UserTeam.transaction do # If user leaves on his/her own accord, # new owner for projects is the first # administrator of team @@ -350,7 +350,7 @@ class Users::SettingsController < ApplicationController def user_current_team @user.current_team_id = params[:user][:current_team_id] - @changed_team = Organization.find_by_id(@user.current_team_id) + @changed_team = Team.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) @@ -368,17 +368,17 @@ class Users::SettingsController < ApplicationController end def check_team_permission - @team = Organization.find_by_id(params[:team_id]) + @team = Team.find_by_id(params[:team_id]) unless is_admin_of_team(@team) render_403 end end def check_user_team_permission - @user_team = UserOrganization.find_by_id(params[:user_team_id]) + @user_team = UserTeam.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 + # Don't allow the user to modify UserTeam-s if he's not admin, + # unless he/she is modifying his/her UserTeam if current_user != @user_team.user and !is_admin_of_team(@user_team.team) render_403