Commit f87b76a805e8ac2d6a77747be171714e2289281a

Authored by Andrey Kumanyaev
Committed by Dmitriy Zaporozhets
1 parent f6f414ce

refactoring user team in public section

app/controllers/teams/application_controller.rb
1 class Teams::ApplicationController < ApplicationController 1 class Teams::ApplicationController < ApplicationController
2 - before_filter :user_team, only: [:index, :show, :edit, :update, :destroy, :issues, :merge_requests, :search, :members]  
3 -  
4 protected 2 protected
5 3
6 def user_team 4 def user_team
app/controllers/teams/projects_controller.rb
1 class Teams::ProjectsController < Teams::ApplicationController 1 class Teams::ProjectsController < Teams::ApplicationController
2 def index 2 def index
3 - @projects = @user_team.projects  
4 - @avaliable_projects = current_user.admin? ? Project.without_team(@user_team) : (Project.personal(current_user) + current_user.projects).uniq 3 + @projects = user_team.projects
  4 + @avaliable_projects = current_user.admin? ? Project.without_team(user_team) : (Project.personal(current_user) + current_user.projects).uniq
5 end 5 end
6 6
7 def new 7 def new
  8 + @projects = Project.scoped
  9 + @projects = @projects.without_team(user_team) if user_team.projects.any?
  10 + #@projects.reject!(&:empty_repo?)
8 end 11 end
9 12
10 def create 13 def create
  14 + unless params[:project_ids].blank?
  15 + project_ids = params[:project_ids]
  16 + access = params[:greatest_project_access]
  17 + user_team.assign_to_projects(project_ids, access)
  18 + end
  19 +
  20 + redirect_to admin_team_path(user_team), notice: 'Projects was successfully added.'
11 end 21 end
12 22
13 def edit 23 def edit
  24 + @user_team = user_team
14 end 25 end
15 26
16 def update 27 def update
  28 + if user_team.update_project_access(project, params[:greatest_project_access])
  29 + redirect_to admin_team_path(user_team), notice: 'Membership was successfully updated.'
  30 + else
  31 + render :edit
  32 + end
17 end 33 end
18 34
19 def destroy 35 def destroy
  36 + user_team.resign_from_project(project)
  37 + redirect_to admin_team_path(user_team), notice: 'Project was successfully removed.'
20 end 38 end
21 end 39 end
app/helpers/user_teams_helper.rb
@@ -19,7 +19,7 @@ module UserTeamsHelper @@ -19,7 +19,7 @@ module UserTeamsHelper
19 team.user_team_user_relationships.sort_by(&:permission).reverse.group_by(&:permission) 19 team.user_team_user_relationships.sort_by(&:permission).reverse.group_by(&:permission)
20 end 20 end
21 21
22 - def remove_from_team_message(team, member) 22 + def remove_from_user_team_message(team, member)
23 "You are going to remove #{member.name} from #{team.name}. Are you sure?" 23 "You are going to remove #{member.name} from #{team.name}. Are you sure?"
24 end 24 end
25 25
app/views/teams/members/_show.html.haml
@@ -27,5 +27,5 @@ @@ -27,5 +27,5 @@
27 - elsif user.blocked 27 - elsif user.blocked
28 %span.btn.disabled.blocked Blocked 28 %span.btn.disabled.blocked Blocked
29 - elsif allow_admin 29 - elsif allow_admin
30 - = link_to team_member_path(@user_team, user), confirm: remove_from_team_message(@user_team, user), method: :delete, class: "very_small btn danger" do 30 + = link_to team_member_path(@user_team, user), confirm: remove_from_user_team_message(@user_team, user), method: :delete, class: "very_small btn danger" do
31 %i.icon-minus.icon-white 31 %i.icon-minus.icon-white