From 31d84d71d3659dc815875f39f466cdcf81d97aaf Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Wed, 23 Jan 2013 18:14:20 +0400 Subject: [PATCH] assign team to project from project page in public section --- .../projects/application_controller.rb | 11 ++++++++ app/controllers/projects/teams_controller.rb | 27 +++++++++++++++++++ app/helpers/projects_helper.rb | 4 +++ app/models/user_team.rb | 2 ++ app/models/user_team_project_relationship.rb | 4 +++ app/views/projects/_project_head.html.haml | 2 +- app/views/projects/teams/avaliable.html.haml | 22 +++++++++++++++ app/views/team_members/_show_team.html.haml | 15 +++++++++++ app/views/team_members/_teams.html.haml | 16 +++++++++++ app/views/team_members/import.html.haml | 2 +- app/views/team_members/index.html.haml | 15 ++++++++++- config/routes.rb | 12 +++++++++ 12 files changed, 129 insertions(+), 3 deletions(-) create mode 100644 app/controllers/projects/application_controller.rb create mode 100644 app/controllers/projects/teams_controller.rb create mode 100644 app/views/projects/teams/avaliable.html.haml create mode 100644 app/views/team_members/_show_team.html.haml create mode 100644 app/views/team_members/_teams.html.haml diff --git a/app/controllers/projects/application_controller.rb b/app/controllers/projects/application_controller.rb new file mode 100644 index 00000000000..7e4776d2d75 --- /dev/null +++ b/app/controllers/projects/application_controller.rb @@ -0,0 +1,11 @@ +class Projects::ApplicationController < ApplicationController + + before_filter :authorize_admin_team_member! + + protected + + def user_team + @team ||= UserTeam.find_by_path(params[:id]) + end + +end diff --git a/app/controllers/projects/teams_controller.rb b/app/controllers/projects/teams_controller.rb new file mode 100644 index 00000000000..c04835ed153 --- /dev/null +++ b/app/controllers/projects/teams_controller.rb @@ -0,0 +1,27 @@ +class Projects::TeamsController < Projects::ApplicationController + + def avaliable + @teams = current_user.is_admin? ? UserTeam.scoped : current_user.user_teams + @teams = @teams.without_project(project) + unless @teams.any? + redirect_to project_team_index_path(project), notice: "No avaliable teams for assigment." + end + end + + def assign + unless params[:team_id].blank? + team = UserTeam.find(params[:team_id]) + access = params[:greatest_project_access] + team.assign_to_project(project, access) + end + redirect_to project_team_index_path(project) + end + + def resign + team = project.user_teams.find_by_path(params[:id]) + team.resign_from_project(project) + + redirect_to project_team_index_path(project) + end + +end diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index dbd47998eb1..c6cb9129499 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -3,6 +3,10 @@ module ProjectsHelper @project.users_projects.sort_by(&:project_access).reverse.group_by(&:project_access) end + def grouper_project_teams(project) + @project.user_team_project_relationships.sort_by(&:greatest_access).reverse.group_by(&:greatest_access) + end + def remove_from_project_team_message(project, user) "You are going to remove #{user.name} from #{project.name} project team. Are you sure?" end diff --git a/app/models/user_team.rb b/app/models/user_team.rb index 2e2f75060c3..0442123fc24 100644 --- a/app/models/user_team.rb +++ b/app/models/user_team.rb @@ -16,6 +16,8 @@ class UserTeam < ActiveRecord::Base message: "only letters, digits & '_' '-' '.' allowed. Letter should be first" } scope :with_member, ->(user){ joins(:user_team_user_relationships).where(user_team_user_relationships: {user_id: user.id}) } + scope :with_project, ->(project){ joins(:user_team_project_relationships).where(user_team_project_relationships: {project_id: project})} + scope :without_project, ->(project){ where("id NOT IN (:ids)", ids: with_project(project))} scope :created_by, ->(user){ where(owner_id: user) } class << self diff --git a/app/models/user_team_project_relationship.rb b/app/models/user_team_project_relationship.rb index 4413c492a6d..1b0368c7ecc 100644 --- a/app/models/user_team_project_relationship.rb +++ b/app/models/user_team_project_relationship.rb @@ -10,6 +10,10 @@ class UserTeamProjectRelationship < ActiveRecord::Base scope :with_project, ->(project){ where(project_id: project.id) } + def team_name + user_team.name + end + private def check_greatest_access diff --git a/app/views/projects/_project_head.html.haml b/app/views/projects/_project_head.html.haml index 94052650694..cc215502859 100644 --- a/app/views/projects/_project_head.html.haml +++ b/app/views/projects/_project_head.html.haml @@ -3,7 +3,7 @@ = link_to project_path(@project), class: "activities-tab tab" do %i.icon-home Show - = nav_link(controller: :team_members) do + = nav_link(controller: [:team_members, :teams]) do = link_to project_team_index_path(@project), class: "team-tab tab" do %i.icon-user Team diff --git a/app/views/projects/teams/avaliable.html.haml b/app/views/projects/teams/avaliable.html.haml new file mode 100644 index 00000000000..814e216d6ad --- /dev/null +++ b/app/views/projects/teams/avaliable.html.haml @@ -0,0 +1,22 @@ += render "projects/project_head" + +%h3.page_title + = "Assign project to team of users" +%hr +%p.slead + Read more about assign to team of users #{link_to "here", '#', class: 'vlink'}. += form_tag assign_project_teams_path(@project), method: 'post' do + %p.slead Choose Team of users you want to assign: + .padded + = label_tag :team_id, "Team" + .input= select_tag(:team_id, options_from_collection_for_select(@teams, :id, :name), prompt: "Select team", class: "chosen xxlarge", required: true) + %p.slead Choose greatest user acces in team you want to assign: + .padded + = label_tag :team_ids, "Permission" + .input= select_tag :greatest_project_access, options_for_select(UserTeam.access_roles), {class: "project-access-select chosen span3" } + + + .actions + = submit_tag 'Assign', class: "btn save-btn" + = link_to "Cancel", project_team_index_path(@project), class: "btn cancel-btn" + diff --git a/app/views/team_members/_show_team.html.haml b/app/views/team_members/_show_team.html.haml new file mode 100644 index 00000000000..da0262efda5 --- /dev/null +++ b/app/views/team_members/_show_team.html.haml @@ -0,0 +1,15 @@ +- team = team_rel.user_team +- allow_admin = can? current_user, :admin_team_member, @project +%li{id: dom_id(team), class: "user_team_row team_#{team.id}"} + .row + .span6 + %strong= link_to team.name, team_path(team), title: team.name, class: "dark" + %br + %small.cgray Members: #{team.members.count} + + .span5.right + .right + - if allow_admin + .left + = link_to resign_project_team_path(@project, team), method: :delete, confirm: "Are you shure?", class: "btn danger small" do + %i.icon-minus.icon-white diff --git a/app/views/team_members/_teams.html.haml b/app/views/team_members/_teams.html.haml new file mode 100644 index 00000000000..156fdd1befa --- /dev/null +++ b/app/views/team_members/_teams.html.haml @@ -0,0 +1,16 @@ +- grouper_project_teams(@project).each do |access, teams| + .ui-box + %h5.title + = UserTeam.access_roles.key(access).pluralize + %small= teams.size + %ul.well-list + - teams.sort_by(&:team_name).each do |tofr| + = render(partial: 'team_members/show_team', locals: {team_rel: tofr}) + + +:javascript + $(function(){ + $('.repo-access-select, .project-access-select').live("change", function() { + $(this.form).submit(); + }); + }) diff --git a/app/views/team_members/import.html.haml b/app/views/team_members/import.html.haml index de82f416248..135db946041 100644 --- a/app/views/team_members/import.html.haml +++ b/app/views/team_members/import.html.haml @@ -4,7 +4,7 @@ = "Import team from another project" %hr %p.slead - Read more about team import #{link_to "here", '#', class: 'vlink'}. + Read more about project team import #{link_to "here", '#', class: 'vlink'}. = form_tag apply_import_project_team_members_path(@project), method: 'post' do %p.slead Choose project you want to use as team source: .padded diff --git a/app/views/team_members/index.html.haml b/app/views/team_members/index.html.haml index 8ba13939a30..f694ccbca93 100644 --- a/app/views/team_members/index.html.haml +++ b/app/views/team_members/index.html.haml @@ -10,11 +10,24 @@ %span.right = link_to import_project_team_members_path(@project), class: "btn small grouped", title: "Import team from another project" do Import team from another project + = link_to avaliable_project_teams_path(@project), class: "btn small grouped", title: "Assign project to team of users" do + Assign project to Team of users = link_to new_project_team_member_path(@project), class: "btn success small grouped", title: "New Team Member" do New Team Member -%hr +%hr .clearfix %div.team-table = render partial: "team_members/team", locals: {project: @project} + + +%h3.page_title + Assigned teams + (#{@project.user_teams.count}) + +%hr + +.clearfix +%div.team-table + = render partial: "team_members/teams", locals: {project: @project} diff --git a/config/routes.rb b/config/routes.rb index e8af16387bc..a19ab14f605 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -269,6 +269,18 @@ Gitlab::Application.routes.draw do end end + scope module: :projects do + resources :teams, only: [] do + collection do + get :avaliable + post :assign + end + member do + delete :resign + end + end + end + resources :notes, only: [:index, :create, :destroy] do collection do post :preview