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
def current_team
Organization.find_by_id(current_user.current_team_id)
Team.find_by_id(current_user.current_team_id)
end
protected

View file

@ -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

View file

@ -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

View file

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

View file

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

View file

@ -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

View file

@ -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? &&

View file

@ -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

View file

@ -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

View file

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

View file

@ -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

View file

@ -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

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 :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

View file

@ -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

View file

@ -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 }

View file

@ -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