rename Organization to Team in controllers

This commit is contained in:
zmagod 2017-01-24 17:06:51 +01:00
parent 21c2f82582
commit c2c5616078
16 changed files with 41 additions and 43 deletions

View file

@ -27,7 +27,7 @@ class ApplicationController < ActionController::Base
# Sets current team for all controllers # Sets current team for all controllers
def current_team def current_team
Organization.find_by_id(current_user.current_team_id) Team.find_by_id(current_user.current_team_id)
end end
protected protected

View file

@ -96,7 +96,7 @@ class AtWhoController < ApplicationController
private private
def load_vars def load_vars
@team = Organization.find_by_id(params[:id]) @team = Team.find_by_id(params[:id])
@query = params[:query] @query = params[:query]
render_404 unless @team render_404 unless @team
end end

View file

@ -91,7 +91,7 @@ class CustomFieldsController < ApplicationController
end end
def load_vars_nested def load_vars_nested
@team = Organization.find_by_id(params[:team_id]) @team = Team.find_by_id(params[:team_id])
render_404 unless @team render_404 unless @team
end end

View file

@ -1,7 +1,7 @@
class ExperimentsController < ApplicationController class ExperimentsController < ApplicationController
include SampleActions include SampleActions
include PermissionHelper include PermissionHelper
include OrganizationsHelper include TeamsHelper
include InputSanitizeHelper include InputSanitizeHelper
before_action :set_experiment, before_action :set_experiment,

View file

@ -1,6 +1,6 @@
class MyModulesController < ApplicationController class MyModulesController < ApplicationController
include SampleActions include SampleActions
include OrganizationsHelper include TeamsHelper
include InputSanitizeHelper include InputSanitizeHelper
before_action :load_vars, only: [ before_action :load_vars, only: [

View file

@ -1,7 +1,7 @@
class ProjectsController < ApplicationController class ProjectsController < ApplicationController
include SampleActions include SampleActions
include RenamingUtil include RenamingUtil
include OrganizationsHelper include TeamsHelper
include InputSanitizeHelper include InputSanitizeHelper
before_action :load_vars, only: [:show, :edit, :update, before_action :load_vars, only: [:show, :edit, :update,
@ -26,8 +26,7 @@ class ProjectsController < ApplicationController
def index def index
if params[:team] if params[:team]
current_team_switch(Organization current_team_switch(Team.find_by_id(params[:team]))
.find_by_id(params[:team]))
end end
if current_user.teams.any? if current_user.teams.any?
@ -35,10 +34,9 @@ class ProjectsController < ApplicationController
@current_team_id ||= current_user.teams.first.id @current_team_id ||= current_user.teams.first.id
@current_sort = params[:sort].to_s @current_sort = params[:sort].to_s
@projects_by_teams = current_user @projects_by_teams = current_user.projects_by_teams(@current_team_id,
.projects_by_teams(@current_team_id, @current_sort,
@current_sort, @filter_by_archived)
@filter_by_archived)
end end
@teams = current_user.teams @teams = current_user.teams

View file

@ -1012,7 +1012,7 @@ class ProtocolsController < ApplicationController
def check_import_permissions def check_import_permissions
@protocol_json = params[:protocol] @protocol_json = params[:protocol]
@team = Organization.find(params[:team_id]) @team = Team.find(params[:team_id])
@type = params[:type] ? params[:type].to_sym : nil @type = params[:type] ? params[:type].to_sym : nil
if !( if !(
@protocol_json.present? && @protocol_json.present? &&

View file

@ -1,5 +1,5 @@
class ReportsController < ApplicationController class ReportsController < ApplicationController
include OrganizationsHelper include TeamsHelper
# Ignore CSRF protection just for PDF generation (because it's # Ignore CSRF protection just for PDF generation (because it's
# used via target='_blank') # used via target='_blank')
protect_from_forgery with: :exception, :except => :generate protect_from_forgery with: :exception, :except => :generate

View file

@ -128,7 +128,7 @@ class SampleGroupsController < ApplicationController
end end
def load_vars_nested def load_vars_nested
@team = Organization.find_by_id(params[:team_id]) @team = Team.find_by_id(params[:team_id])
render_404 unless @team render_404 unless @team
end end

View file

@ -1,5 +1,5 @@
class SampleMyModulesController < ApplicationController class SampleMyModulesController < ApplicationController
include OrganizationsHelper include TeamsHelper
before_action :load_vars before_action :load_vars
def index def index

View file

@ -124,7 +124,7 @@ class SampleTypesController < ApplicationController
end end
def load_vars_nested def load_vars_nested
@team = Organization.find_by_id(params[:team_id]) @team = Team.find_by_id(params[:team_id])
render_404 unless @team render_404 unless @team
end end

View file

@ -289,7 +289,7 @@ class SamplesController < ApplicationController
end end
def load_vars_nested def load_vars_nested
@team = Organization.find_by_id(params[:team_id]) @team = Team.find_by_id(params[:team_id])
unless @team unless @team
render_404 render_404

View file

@ -1,4 +1,4 @@
class OrganizationsController < ApplicationController class TeamsController < ApplicationController
before_action :load_vars, only: [:parse_sheet, :import_samples, :export_samples] before_action :load_vars, only: [:parse_sheet, :import_samples, :export_samples]
before_action :check_create_sample_permissions, only: [:parse_sheet, :import_samples] before_action :check_create_sample_permissions, only: [:parse_sheet, :import_samples]
@ -25,7 +25,7 @@ class OrganizationsController < ApplicationController
} }
else else
sheet = Organization.open_spreadsheet(params[:file]) sheet = Team.open_spreadsheet(params[:file])
# Check if we actually have any rows (last_row > 1) # Check if we actually have any rows (last_row > 1)
if sheet.last_row.between?(0, 1) if sheet.last_row.between?(0, 1)
@ -122,7 +122,7 @@ class OrganizationsController < ApplicationController
if @temp_file.session_id == session.id if @temp_file.session_id == session.id
# Check if mappings exists or else we don't have anything to parse # Check if mappings exists or else we don't have anything to parse
if params[:mappings] if params[:mappings]
@sheet = Organization.open_spreadsheet(@temp_file.file) @sheet = Team.open_spreadsheet(@temp_file.file)
# Check for duplicated values # Check for duplicated values
h1 = params[:mappings].clone.delete_if { |k, v| v.empty? } h1 = params[:mappings].clone.delete_if { |k, v| v.empty? }
@ -282,7 +282,7 @@ class OrganizationsController < ApplicationController
end end
def load_vars def load_vars
@team = Organization.find_by_id(params[:id]) @team = Team.find_by_id(params[:id])
unless @team unless @team
render_404 render_404

View file

@ -10,7 +10,7 @@ module Users
def update def update
# Instantialize a new team with the provided name # Instantialize a new team with the provided name
@team = Organization.new @team = Team.new
@team.name = params[:team][:name] @team.name = params[:team][:name]
super do |user| super do |user|
@ -18,7 +18,7 @@ module Users
@team.created_by = user @team.created_by = user
@team.save @team.save
UserOrganization.create( UserTeam.create(
user: user, user: user,
team: @team, team: @team,
role: 'admin' role: 'admin'
@ -101,14 +101,14 @@ module Users
end end
if @team.present? && result[:status] != :user_invalid if @team.present? && result[:status] != :user_invalid
if UserOrganization.exists?(user: user, team: @team) if UserTeam.exists?(user: user, team: @team)
user_team = user_team =
UserOrganization.where(user: user, team: @team).first UserTeam.where(user: user, team: @team).first
result[:status] = :user_exists_and_in_team result[:status] = :user_exists_and_in_team
else else
# Also generate user team relation # Also generate user team relation
user_team = UserOrganization.new( user_team = UserTeam.new(
user: user, user: user,
team: @team, team: @team,
role: @role role: @role
@ -187,12 +187,12 @@ module Users
def check_invite_users_permission def check_invite_users_permission
@user = current_user @user = current_user
@emails = params[:emails] @emails = params[:emails]
@team = Organization.find_by_id(params['teamId']) @team = Team.find_by_id(params['teamId'])
@role = params['role'] @role = params['role']
render_403 if @emails && @emails.empty? render_403 if @emails && @emails.empty?
render_403 if @team && !is_admin_of_team(@team) 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 end
end end

View file

@ -127,7 +127,7 @@ class Users::RegistrationsController < Devise::RegistrationsController
valid_resource = resource.valid? valid_resource = resource.valid?
# Create new team for the new user # Create new team for the new user
@team = Organization.new @team = Team.new
@team.name = params[:team][:name] @team.name = params[:team][:name]
valid_team = @team.valid? valid_team = @team.valid?
@ -146,7 +146,7 @@ class Users::RegistrationsController < Devise::RegistrationsController
@team.save @team.save
# Add this user to the team as owner # Add this user to the team as owner
UserOrganization.create( UserTeam.create(
user: resource, user: resource,
team: @team, team: @team,
role: :admin role: :admin
@ -248,7 +248,7 @@ class Users::RegistrationsController < Devise::RegistrationsController
self.resource = resource_class.new sign_up_params self.resource = resource_class.new sign_up_params
# Also validate team # Also validate team
@team = Organization.new(name: params[:team][:name]) @team = Team.new(name: params[:team][:name])
@team.valid? @team.valid?
respond_with_navigational(resource) { render :new } respond_with_navigational(resource) { render :new }

View file

@ -63,7 +63,7 @@ class Users::SettingsController < ApplicationController
end end
def team def team
@user_team = UserOrganization.find_by(user: @user, team: @team) @user_team = UserTeam.find_by(user: @user, team: @team)
end end
def update_team def update_team
@ -117,23 +117,23 @@ class Users::SettingsController < ApplicationController
def team_users_datatable def team_users_datatable
respond_to do |format| respond_to do |format|
format.json { format.json {
render json: ::OrganizationUsersDatatable.new(view_context, @team, @user) render json: ::TeamUsersDatatable.new(view_context, @team, @user)
} }
end end
end end
def new_team def new_team
@new_team = Organization.new @new_team = Team.new
end end
def create_team def create_team
@new_team = Organization.new(create_team_params) @new_team = Team.new(create_team_params)
@new_team.created_by = @user @new_team.created_by = @user
if @new_team.save if @new_team.save
# Okay, team is created, now # Okay, team is created, now
# add the current user as admin # add the current user as admin
UserOrganization.create( UserTeam.create(
user: @user, user: @user,
team: @new_team, team: @new_team,
role: 2 role: 2
@ -224,7 +224,7 @@ class Users::SettingsController < ApplicationController
if !invalid then if !invalid then
begin begin
UserOrganization.transaction do UserTeam.transaction do
# If user leaves on his/her own accord, # If user leaves on his/her own accord,
# new owner for projects is the first # new owner for projects is the first
# administrator of team # administrator of team
@ -350,7 +350,7 @@ class Users::SettingsController < ApplicationController
def user_current_team def user_current_team
@user.current_team_id = params[:user][:current_team_id] @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 if params[:user][:current_team_id].present? && @user.save
flash[:success] = t('users.settings.changed_team_flash', flash[:success] = t('users.settings.changed_team_flash',
team: @changed_team.name) team: @changed_team.name)
@ -368,17 +368,17 @@ class Users::SettingsController < ApplicationController
end end
def check_team_permission 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) unless is_admin_of_team(@team)
render_403 render_403
end end
end end
def check_user_team_permission 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 @team = @user_team.team
# Don't allow the user to modify UserOrganization-s if he's not admin, # Don't allow the user to modify UserTeam-s if he's not admin,
# unless he/she is modifying his/her UserOrganization # unless he/she is modifying his/her UserTeam
if current_user != @user_team.user and if current_user != @user_team.user and
!is_admin_of_team(@user_team.team) !is_admin_of_team(@user_team.team)
render_403 render_403