assign team to project from project page in public section
This commit is contained in:
parent
18bd1c9d30
commit
31d84d71d3
12 changed files with 129 additions and 3 deletions
11
app/controllers/projects/application_controller.rb
Normal file
11
app/controllers/projects/application_controller.rb
Normal file
|
@ -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
|
27
app/controllers/projects/teams_controller.rb
Normal file
27
app/controllers/projects/teams_controller.rb
Normal file
|
@ -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
|
|
@ -3,6 +3,10 @@ module ProjectsHelper
|
||||||
@project.users_projects.sort_by(&:project_access).reverse.group_by(&:project_access)
|
@project.users_projects.sort_by(&:project_access).reverse.group_by(&:project_access)
|
||||||
end
|
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)
|
def remove_from_project_team_message(project, user)
|
||||||
"You are going to remove #{user.name} from #{project.name} project team. Are you sure?"
|
"You are going to remove #{user.name} from #{project.name} project team. Are you sure?"
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,6 +16,8 @@ class UserTeam < ActiveRecord::Base
|
||||||
message: "only letters, digits & '_' '-' '.' allowed. Letter should be first" }
|
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_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) }
|
scope :created_by, ->(user){ where(owner_id: user) }
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
|
|
|
@ -10,6 +10,10 @@ class UserTeamProjectRelationship < ActiveRecord::Base
|
||||||
|
|
||||||
scope :with_project, ->(project){ where(project_id: project.id) }
|
scope :with_project, ->(project){ where(project_id: project.id) }
|
||||||
|
|
||||||
|
def team_name
|
||||||
|
user_team.name
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def check_greatest_access
|
def check_greatest_access
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
= link_to project_path(@project), class: "activities-tab tab" do
|
= link_to project_path(@project), class: "activities-tab tab" do
|
||||||
%i.icon-home
|
%i.icon-home
|
||||||
Show
|
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
|
= link_to project_team_index_path(@project), class: "team-tab tab" do
|
||||||
%i.icon-user
|
%i.icon-user
|
||||||
Team
|
Team
|
||||||
|
|
22
app/views/projects/teams/avaliable.html.haml
Normal file
22
app/views/projects/teams/avaliable.html.haml
Normal file
|
@ -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"
|
||||||
|
|
15
app/views/team_members/_show_team.html.haml
Normal file
15
app/views/team_members/_show_team.html.haml
Normal file
|
@ -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
|
16
app/views/team_members/_teams.html.haml
Normal file
16
app/views/team_members/_teams.html.haml
Normal file
|
@ -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();
|
||||||
|
});
|
||||||
|
})
|
|
@ -4,7 +4,7 @@
|
||||||
= "Import team from another project"
|
= "Import team from another project"
|
||||||
%hr
|
%hr
|
||||||
%p.slead
|
%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
|
= form_tag apply_import_project_team_members_path(@project), method: 'post' do
|
||||||
%p.slead Choose project you want to use as team source:
|
%p.slead Choose project you want to use as team source:
|
||||||
.padded
|
.padded
|
||||||
|
|
|
@ -10,11 +10,24 @@
|
||||||
%span.right
|
%span.right
|
||||||
= link_to import_project_team_members_path(@project), class: "btn small grouped", title: "Import team from another project" do
|
= link_to import_project_team_members_path(@project), class: "btn small grouped", title: "Import team from another project" do
|
||||||
Import team from another project
|
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
|
= link_to new_project_team_member_path(@project), class: "btn success small grouped", title: "New Team Member" do
|
||||||
New Team Member
|
New Team Member
|
||||||
%hr
|
|
||||||
|
|
||||||
|
%hr
|
||||||
|
|
||||||
.clearfix
|
.clearfix
|
||||||
%div.team-table
|
%div.team-table
|
||||||
= render partial: "team_members/team", locals: {project: @project}
|
= 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}
|
||||||
|
|
|
@ -269,6 +269,18 @@ Gitlab::Application.routes.draw do
|
||||||
end
|
end
|
||||||
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
|
resources :notes, only: [:index, :create, :destroy] do
|
||||||
collection do
|
collection do
|
||||||
post :preview
|
post :preview
|
||||||
|
|
Loading…
Add table
Reference in a new issue