Commit 31d84d71d3659dc815875f39f466cdcf81d97aaf

Authored by Andrey Kumanyaev
Committed by Dmitriy Zaporozhets
1 parent 18bd1c9d

assign team to project from project page in public section

app/controllers/projects/application_controller.rb 0 → 100644
... ... @@ -0,0 +1,11 @@
  1 +class Projects::ApplicationController < ApplicationController
  2 +
  3 + before_filter :authorize_admin_team_member!
  4 +
  5 + protected
  6 +
  7 + def user_team
  8 + @team ||= UserTeam.find_by_path(params[:id])
  9 + end
  10 +
  11 +end
... ...
app/controllers/projects/teams_controller.rb 0 → 100644
... ... @@ -0,0 +1,27 @@
  1 +class Projects::TeamsController < Projects::ApplicationController
  2 +
  3 + def avaliable
  4 + @teams = current_user.is_admin? ? UserTeam.scoped : current_user.user_teams
  5 + @teams = @teams.without_project(project)
  6 + unless @teams.any?
  7 + redirect_to project_team_index_path(project), notice: "No avaliable teams for assigment."
  8 + end
  9 + end
  10 +
  11 + def assign
  12 + unless params[:team_id].blank?
  13 + team = UserTeam.find(params[:team_id])
  14 + access = params[:greatest_project_access]
  15 + team.assign_to_project(project, access)
  16 + end
  17 + redirect_to project_team_index_path(project)
  18 + end
  19 +
  20 + def resign
  21 + team = project.user_teams.find_by_path(params[:id])
  22 + team.resign_from_project(project)
  23 +
  24 + redirect_to project_team_index_path(project)
  25 + end
  26 +
  27 +end
... ...
app/helpers/projects_helper.rb
... ... @@ -3,6 +3,10 @@ module ProjectsHelper
3 3 @project.users_projects.sort_by(&:project_access).reverse.group_by(&:project_access)
4 4 end
5 5  
  6 + def grouper_project_teams(project)
  7 + @project.user_team_project_relationships.sort_by(&:greatest_access).reverse.group_by(&:greatest_access)
  8 + end
  9 +
6 10 def remove_from_project_team_message(project, user)
7 11 "You are going to remove #{user.name} from #{project.name} project team. Are you sure?"
8 12 end
... ...
app/models/user_team.rb
... ... @@ -16,6 +16,8 @@ class UserTeam &lt; ActiveRecord::Base
16 16 message: "only letters, digits & '_' '-' '.' allowed. Letter should be first" }
17 17  
18 18 scope :with_member, ->(user){ joins(:user_team_user_relationships).where(user_team_user_relationships: {user_id: user.id}) }
  19 + scope :with_project, ->(project){ joins(:user_team_project_relationships).where(user_team_project_relationships: {project_id: project})}
  20 + scope :without_project, ->(project){ where("id NOT IN (:ids)", ids: with_project(project))}
19 21 scope :created_by, ->(user){ where(owner_id: user) }
20 22  
21 23 class << self
... ...
app/models/user_team_project_relationship.rb
... ... @@ -10,6 +10,10 @@ class UserTeamProjectRelationship &lt; ActiveRecord::Base
10 10  
11 11 scope :with_project, ->(project){ where(project_id: project.id) }
12 12  
  13 + def team_name
  14 + user_team.name
  15 + end
  16 +
13 17 private
14 18  
15 19 def check_greatest_access
... ...
app/views/projects/_project_head.html.haml
... ... @@ -3,7 +3,7 @@
3 3 = link_to project_path(@project), class: "activities-tab tab" do
4 4 %i.icon-home
5 5 Show
6   - = nav_link(controller: :team_members) do
  6 + = nav_link(controller: [:team_members, :teams]) do
7 7 = link_to project_team_index_path(@project), class: "team-tab tab" do
8 8 %i.icon-user
9 9 Team
... ...
app/views/projects/teams/avaliable.html.haml 0 → 100644
... ... @@ -0,0 +1,22 @@
  1 += render "projects/project_head"
  2 +
  3 +%h3.page_title
  4 + = "Assign project to team of users"
  5 +%hr
  6 +%p.slead
  7 + Read more about assign to team of users #{link_to "here", '#', class: 'vlink'}.
  8 += form_tag assign_project_teams_path(@project), method: 'post' do
  9 + %p.slead Choose Team of users you want to assign:
  10 + .padded
  11 + = label_tag :team_id, "Team"
  12 + .input= select_tag(:team_id, options_from_collection_for_select(@teams, :id, :name), prompt: "Select team", class: "chosen xxlarge", required: true)
  13 + %p.slead Choose greatest user acces in team you want to assign:
  14 + .padded
  15 + = label_tag :team_ids, "Permission"
  16 + .input= select_tag :greatest_project_access, options_for_select(UserTeam.access_roles), {class: "project-access-select chosen span3" }
  17 +
  18 +
  19 + .actions
  20 + = submit_tag 'Assign', class: "btn save-btn"
  21 + = link_to "Cancel", project_team_index_path(@project), class: "btn cancel-btn"
  22 +
... ...
app/views/team_members/_show_team.html.haml 0 → 100644
... ... @@ -0,0 +1,15 @@
  1 +- team = team_rel.user_team
  2 +- allow_admin = can? current_user, :admin_team_member, @project
  3 +%li{id: dom_id(team), class: "user_team_row team_#{team.id}"}
  4 + .row
  5 + .span6
  6 + %strong= link_to team.name, team_path(team), title: team.name, class: "dark"
  7 + %br
  8 + %small.cgray Members: #{team.members.count}
  9 +
  10 + .span5.right
  11 + .right
  12 + - if allow_admin
  13 + .left
  14 + = link_to resign_project_team_path(@project, team), method: :delete, confirm: "Are you shure?", class: "btn danger small" do
  15 + %i.icon-minus.icon-white
... ...
app/views/team_members/_teams.html.haml 0 → 100644
... ... @@ -0,0 +1,16 @@
  1 +- grouper_project_teams(@project).each do |access, teams|
  2 + .ui-box
  3 + %h5.title
  4 + = UserTeam.access_roles.key(access).pluralize
  5 + %small= teams.size
  6 + %ul.well-list
  7 + - teams.sort_by(&:team_name).each do |tofr|
  8 + = render(partial: 'team_members/show_team', locals: {team_rel: tofr})
  9 +
  10 +
  11 +:javascript
  12 + $(function(){
  13 + $('.repo-access-select, .project-access-select').live("change", function() {
  14 + $(this.form).submit();
  15 + });
  16 + })
... ...
app/views/team_members/import.html.haml
... ... @@ -4,7 +4,7 @@
4 4 = "Import team from another project"
5 5 %hr
6 6 %p.slead
7   - Read more about team import #{link_to "here", '#', class: 'vlink'}.
  7 + Read more about project team import #{link_to "here", '#', class: 'vlink'}.
8 8 = form_tag apply_import_project_team_members_path(@project), method: 'post' do
9 9 %p.slead Choose project you want to use as team source:
10 10 .padded
... ...
app/views/team_members/index.html.haml
... ... @@ -10,11 +10,24 @@
10 10 %span.right
11 11 = link_to import_project_team_members_path(@project), class: "btn small grouped", title: "Import team from another project" do
12 12 Import team from another project
  13 + = link_to avaliable_project_teams_path(@project), class: "btn small grouped", title: "Assign project to team of users" do
  14 + Assign project to Team of users
13 15 = link_to new_project_team_member_path(@project), class: "btn success small grouped", title: "New Team Member" do
14 16 New Team Member
15   -%hr
16 17  
  18 +%hr
17 19  
18 20 .clearfix
19 21 %div.team-table
20 22 = render partial: "team_members/team", locals: {project: @project}
  23 +
  24 +
  25 +%h3.page_title
  26 + Assigned teams
  27 + (#{@project.user_teams.count})
  28 +
  29 +%hr
  30 +
  31 +.clearfix
  32 +%div.team-table
  33 + = render partial: "team_members/teams", locals: {project: @project}
... ...
config/routes.rb
... ... @@ -269,6 +269,18 @@ Gitlab::Application.routes.draw do
269 269 end
270 270 end
271 271  
  272 + scope module: :projects do
  273 + resources :teams, only: [] do
  274 + collection do
  275 + get :avaliable
  276 + post :assign
  277 + end
  278 + member do
  279 + delete :resign
  280 + end
  281 + end
  282 + end
  283 +
272 284 resources :notes, only: [:index, :create, :destroy] do
273 285 collection do
274 286 post :preview
... ...