Commit dcea52203ddc93c1d073e7615d98725cc3584d2f

Authored by Andrey Kumanyaev
Committed by Dmitriy Zaporozhets
1 parent f87b76a8

remove before_filter from controllers

app/controllers/admin/teams/members_controller.rb
1 1 class Admin::Teams::MembersController < Admin::Teams::ApplicationController
2   - before_filter :team_member, only: [:edit, :destroy, :update]
3   -
4 2 def new
5 3 @users = User.active
6 4 @users = @users.not_in_team(@team) if @team.members.any?
... ... @@ -19,11 +17,12 @@ class Admin::Teams::MembersController &lt; Admin::Teams::ApplicationController
19 17 end
20 18  
21 19 def edit
  20 + team_member
22 21 end
23 22  
24 23 def update
25 24 options = {default_projects_access: params[:default_project_access], group_admin: params[:group_admin]}
26   - if @team.update_membership(@member, options)
  25 + if @team.update_membership(team_member, options)
27 26 redirect_to admin_team_path(@team), notice: 'Membership was successfully updated.'
28 27 else
29 28 render :edit
... ... @@ -31,16 +30,16 @@ class Admin::Teams::MembersController &lt; Admin::Teams::ApplicationController
31 30 end
32 31  
33 32 def destroy
34   - if @team.remove_member(@member)
  33 + if @team.remove_member(team_member)
35 34 redirect_to admin_team_path(@team), notice: "Member was successfully removed from team."
36 35 else
37 36 redirect_to admin_team_members(@team), notice: "Something wrong."
38 37 end
39 38 end
40 39  
41   - private
  40 + protected
42 41  
43 42 def team_member
44   - @member = @team.members.find(params[:id])
  43 + @member ||= @team.members.find(params[:id])
45 44 end
46 45 end
... ...
app/controllers/admin/teams/projects_controller.rb
1 1 class Admin::Teams::ProjectsController < Admin::Teams::ApplicationController
2   - before_filter :team_project, only: [:edit, :destroy, :update]
3   -
4 2 def new
5 3 @projects = Project.scoped
6 4 @projects = @projects.without_team(@team) if @team.projects.any?
... ... @@ -18,10 +16,11 @@ class Admin::Teams::ProjectsController &lt; Admin::Teams::ApplicationController
18 16 end
19 17  
20 18 def edit
  19 + team_project
21 20 end
22 21  
23 22 def update
24   - if @team.update_project_access(@project, params[:greatest_project_access])
  23 + if @team.update_project_access(team_project, params[:greatest_project_access])
25 24 redirect_to admin_team_path(@team), notice: 'Membership was successfully updated.'
26 25 else
27 26 render :edit
... ... @@ -29,14 +28,14 @@ class Admin::Teams::ProjectsController &lt; Admin::Teams::ApplicationController
29 28 end
30 29  
31 30 def destroy
32   - @team.resign_from_project(@project)
  31 + @team.resign_from_project(team_project)
33 32 redirect_to admin_team_path(@team), notice: 'Project was successfully removed.'
34 33 end
35 34  
36   - private
  35 + protected
37 36  
38 37 def team_project
39   - @project = @team.projects.find_by_path(params[:id])
  38 + @project ||= @team.projects.find_by_path(params[:id])
40 39 end
41 40  
42 41 end
... ...
app/controllers/admin/teams_controller.rb
1 1 class Admin::TeamsController < Admin::ApplicationController
2   - before_filter :user_team,
3   - only: [ :edit, :show, :update, :destroy,
4   - :delegate_projects, :relegate_project,
5   - :add_members, :remove_member ]
6   -
7 2 def index
8 3 @teams = UserTeam.order('name ASC')
9 4 @teams = @teams.search(params[:name]) if params[:name].present?
... ... @@ -12,11 +7,11 @@ class Admin::TeamsController &lt; Admin::ApplicationController
12 7  
13 8 def show
14 9 @projects = Project.scoped
15   - @projects = @projects.without_team(@team) if @team.projects.any?
  10 + @projects = @projects.without_team(user_team) if user_team.projects.any?
16 11 #@projects.reject!(&:empty_repo?)
17 12  
18 13 @users = User.active
19   - @users = @users.not_in_team(@team) if @team.members.any?
  14 + @users = @users.not_in_team(user_team) if user_team.members.any?
20 15 @users = UserDecorator.decorate @users
21 16 end
22 17  
... ... @@ -25,15 +20,16 @@ class Admin::TeamsController &lt; Admin::ApplicationController
25 20 end
26 21  
27 22 def edit
  23 + user_team
28 24 end
29 25  
30 26 def create
31   - @team = UserTeam.new(params[:user_team])
32   - @team.path = @team.name.dup.parameterize if @team.name
33   - @team.owner = current_user
  27 + user_team = UserTeam.new(params[:user_team])
  28 + user_team.path = user_team.name.dup.parameterize if user_team.name
  29 + user_team.owner = current_user
34 30  
35   - if @team.save
36   - redirect_to admin_team_path(@team), notice: 'UserTeam was successfully created.'
  31 + if user_team.save
  32 + redirect_to admin_team_path(user_team), notice: 'UserTeam was successfully created.'
37 33 else
38 34 render action: "new"
39 35 end
... ... @@ -44,26 +40,26 @@ class Admin::TeamsController &lt; Admin::ApplicationController
44 40 owner_id = user_team_params.delete(:owner_id)
45 41  
46 42 if owner_id
47   - @team.owner = User.find(owner_id)
  43 + user_team.owner = User.find(owner_id)
48 44 end
49 45  
50   - if @team.update_attributes(user_team_params)
51   - redirect_to admin_team_path(@team), notice: 'UserTeam was successfully updated.'
  46 + if user_team.update_attributes(user_team_params)
  47 + redirect_to admin_team_path(user_team), notice: 'UserTeam was successfully updated.'
52 48 else
53 49 render action: "edit"
54 50 end
55 51 end
56 52  
57 53 def destroy
58   - @team.destroy
  54 + user_team.destroy
59 55  
60 56 redirect_to admin_user_teams_path, notice: 'UserTeam was successfully deleted.'
61 57 end
62 58  
63   - private
  59 + protected
64 60  
65 61 def user_team
66   - @team = UserTeam.find_by_path(params[:id])
  62 + @team ||= UserTeam.find_by_path(params[:id])
67 63 end
68 64  
69 65 end
... ...
app/controllers/teams/projects_controller.rb
... ... @@ -21,11 +21,11 @@ class Teams::ProjectsController &lt; Teams::ApplicationController
21 21 end
22 22  
23 23 def edit
24   - @user_team = user_team
  24 + team_project
25 25 end
26 26  
27 27 def update
28   - if user_team.update_project_access(project, params[:greatest_project_access])
  28 + if user_team.update_project_access(team_project, params[:greatest_project_access])
29 29 redirect_to admin_team_path(user_team), notice: 'Membership was successfully updated.'
30 30 else
31 31 render :edit
... ... @@ -33,7 +33,14 @@ class Teams::ProjectsController &lt; Teams::ApplicationController
33 33 end
34 34  
35 35 def destroy
36   - user_team.resign_from_project(project)
  36 + user_team.resign_from_project(team_project)
37 37 redirect_to admin_team_path(user_team), notice: 'Project was successfully removed.'
38 38 end
  39 +
  40 + private
  41 +
  42 + def team_project
  43 + @project ||= @team.projects.find_by_path(params[:id])
  44 + end
  45 +
39 46 end
... ...