Commit 439f399bece8c2b01dc064b6c02f28fb4149595e

Authored by Dmitriy Zaporozhets
1 parent 670aaaeb

Remove all team resources except models. Move models to deprecated directory

Showing 63 changed files with 193 additions and 2611 deletions   Show diff stats
app/controllers/admin/teams/application_controller.rb
@@ -1,11 +0,0 @@ @@ -1,11 +0,0 @@
1 -# Provides a base class for Admin controllers to subclass  
2 -#  
3 -# Automatically sets the layout and ensures an administrator is logged in  
4 -class Admin::Teams::ApplicationController < Admin::ApplicationController  
5 -  
6 - private  
7 -  
8 - def user_team  
9 - @team = UserTeam.find_by_path(params[:team_id])  
10 - end  
11 -end  
app/controllers/admin/teams/members_controller.rb
@@ -1,40 +0,0 @@ @@ -1,40 +0,0 @@
1 -class Admin::Teams::MembersController < Admin::Teams::ApplicationController  
2 - def new  
3 - @users = User.potential_team_members(user_team)  
4 - end  
5 -  
6 - def create  
7 - unless params[:user_ids].blank?  
8 - user_ids = params[:user_ids]  
9 - access = params[:default_project_access]  
10 - is_admin = params[:group_admin]  
11 - user_team.add_members(user_ids, access, is_admin)  
12 - end  
13 -  
14 - redirect_to admin_team_path(user_team), notice: 'Members were successfully added into Team of users.'  
15 - end  
16 -  
17 - def edit  
18 - team_member  
19 - end  
20 -  
21 - def update  
22 - options = {default_projects_access: params[:default_project_access], group_admin: params[:group_admin]}  
23 - if user_team.update_membership(team_member, options)  
24 - redirect_to admin_team_path(user_team), notice: "Membership for #{team_member.name} was successfully updated in Team of users."  
25 - else  
26 - render :edit  
27 - end  
28 - end  
29 -  
30 - def destroy  
31 - user_team.remove_member(team_member)  
32 - redirect_to admin_team_path(user_team), notice: "Member #{team_member.name} was successfully removed from Team of users."  
33 - end  
34 -  
35 - protected  
36 -  
37 - def team_member  
38 - @member ||= user_team.members.find_by_username(params[:id])  
39 - end  
40 -end  
app/controllers/admin/teams/projects_controller.rb
@@ -1,41 +0,0 @@ @@ -1,41 +0,0 @@
1 -class Admin::Teams::ProjectsController < Admin::Teams::ApplicationController  
2 - def new  
3 - @projects = Project.scoped  
4 - @projects = @projects.without_team(user_team) if user_team.projects.any?  
5 - #@projects.reject!(&:empty_repo?)  
6 - end  
7 -  
8 - def create  
9 - unless params[:project_ids].blank?  
10 - project_ids = params[:project_ids]  
11 - access = params[:greatest_project_access]  
12 - user_team.assign_to_projects(project_ids, access)  
13 - end  
14 -  
15 - redirect_to admin_team_path(user_team), notice: 'Team of users was successfully assgned to projects.'  
16 - end  
17 -  
18 - def edit  
19 - team_project  
20 - end  
21 -  
22 - def update  
23 - if user_team.update_project_access(team_project, params[:greatest_project_access])  
24 - redirect_to admin_team_path(user_team), notice: 'Access was successfully updated.'  
25 - else  
26 - render :edit  
27 - end  
28 - end  
29 -  
30 - def destroy  
31 - user_team.resign_from_project(team_project)  
32 - redirect_to admin_team_path(user_team), notice: 'Team of users was successfully reassigned from project.'  
33 - end  
34 -  
35 - protected  
36 -  
37 - def team_project  
38 - @project ||= user_team.projects.find_with_namespace(params[:id])  
39 - end  
40 -  
41 -end  
app/controllers/admin/teams_controller.rb
@@ -1,59 +0,0 @@ @@ -1,59 +0,0 @@
1 -class Admin::TeamsController < Admin::ApplicationController  
2 - def index  
3 - @teams = UserTeam.order('name ASC')  
4 - @teams = @teams.search(params[:name]) if params[:name].present?  
5 - @teams = @teams.page(params[:page]).per(20)  
6 - end  
7 -  
8 - def show  
9 - user_team  
10 - end  
11 -  
12 - def new  
13 - @team = UserTeam.new  
14 - end  
15 -  
16 - def edit  
17 - user_team  
18 - end  
19 -  
20 - def create  
21 - @team = UserTeam.new(params[:user_team])  
22 - @team.path = @team.name.dup.parameterize if @team.name  
23 - @team.owner = current_user  
24 -  
25 - if @team.save  
26 - redirect_to admin_team_path(@team), notice: 'Team of users was successfully created.'  
27 - else  
28 - render action: "new"  
29 - end  
30 - end  
31 -  
32 - def update  
33 - user_team_params = params[:user_team].dup  
34 - owner_id = user_team_params.delete(:owner_id)  
35 -  
36 - if owner_id  
37 - user_team.owner = User.find(owner_id)  
38 - end  
39 -  
40 - if user_team.update_attributes(user_team_params)  
41 - redirect_to admin_team_path(user_team), notice: 'Team of users was successfully updated.'  
42 - else  
43 - render action: "edit"  
44 - end  
45 - end  
46 -  
47 - def destroy  
48 - user_team.destroy  
49 -  
50 - redirect_to admin_teams_path, notice: 'Team of users was successfully deleted.'  
51 - end  
52 -  
53 - protected  
54 -  
55 - def user_team  
56 - @team ||= UserTeam.find_by_path(params[:id])  
57 - end  
58 -  
59 -end  
app/controllers/dashboard_controller.rb
@@ -7,7 +7,6 @@ class DashboardController &lt; ApplicationController @@ -7,7 +7,6 @@ class DashboardController &lt; ApplicationController
7 def show 7 def show
8 @groups = current_user.authorized_groups.sort_by(&:human_name) 8 @groups = current_user.authorized_groups.sort_by(&:human_name)
9 @has_authorized_projects = @projects.count > 0 9 @has_authorized_projects = @projects.count > 0
10 - @teams = current_user.authorized_teams  
11 @projects_count = @projects.count 10 @projects_count = @projects.count
12 @projects = @projects.limit(20) 11 @projects = @projects.limit(20)
13 12
app/controllers/projects/teams_controller.rb
@@ -1,34 +0,0 @@ @@ -1,34 +0,0 @@
1 -class Projects::TeamsController < Projects::ApplicationController  
2 -  
3 - before_filter :authorize_admin_team_member!  
4 -  
5 - def available  
6 - @teams = current_user.is_admin? ? UserTeam.scoped : current_user.user_teams  
7 - @teams = @teams.without_project(project)  
8 - unless @teams.any?  
9 - redirect_to project_team_index_path(project), notice: "No available teams for assigment."  
10 - end  
11 - end  
12 -  
13 - def assign  
14 - unless params[:team_id].blank?  
15 - team = UserTeam.find(params[:team_id])  
16 - access = params[:greatest_project_access]  
17 - team.assign_to_project(project, access)  
18 - end  
19 - redirect_to project_team_index_path(project)  
20 - end  
21 -  
22 - def resign  
23 - team = project.user_teams.find_by_path(params[:id])  
24 - team.resign_from_project(project)  
25 -  
26 - redirect_to project_team_index_path(project)  
27 - end  
28 -  
29 - protected  
30 -  
31 - def user_team  
32 - @team ||= UserTeam.find_by_path(params[:id])  
33 - end  
34 -end  
app/controllers/teams/application_controller.rb
@@ -1,13 +0,0 @@ @@ -1,13 +0,0 @@
1 -class Teams::ApplicationController < ApplicationController  
2 -  
3 - layout 'user_team'  
4 -  
5 - before_filter :authorize_manage_user_team!  
6 -  
7 - protected  
8 -  
9 - def user_team  
10 - @team ||= UserTeam.find_by_path(params[:team_id])  
11 - end  
12 -  
13 -end  
app/controllers/teams/members_controller.rb
@@ -1,53 +0,0 @@ @@ -1,53 +0,0 @@
1 -class Teams::MembersController < Teams::ApplicationController  
2 -  
3 - skip_before_filter :authorize_manage_user_team!, only: [:index]  
4 -  
5 - def index  
6 - @members = user_team.members  
7 - end  
8 -  
9 - def new  
10 - @users = User.potential_team_members(user_team)  
11 - end  
12 -  
13 - def create  
14 - unless params[:user_ids].blank?  
15 - user_ids = params[:user_ids].split(',')  
16 - access = params[:default_project_access]  
17 - is_admin = params[:group_admin]  
18 - user_team.add_members(user_ids, access, is_admin)  
19 - end  
20 -  
21 - redirect_to team_members_path(user_team), notice: 'Members were successfully added into Team of users.'  
22 - end  
23 -  
24 - def edit  
25 - team_member  
26 - end  
27 -  
28 - def update  
29 - member_params = params[:team_member]  
30 -  
31 - options = {  
32 - default_projects_access: member_params[:permission],  
33 - group_admin: member_params[:group_admin]  
34 - }  
35 -  
36 - if user_team.update_membership(team_member, options)  
37 - redirect_to team_members_path(user_team), notice: "Membership for #{team_member.name} was successfully updated in Team of users."  
38 - else  
39 - render :edit  
40 - end  
41 - end  
42 -  
43 - def destroy  
44 - user_team.remove_member(team_member)  
45 - redirect_to team_path(user_team), notice: "Member #{team_member.name} was successfully removed from Team of users."  
46 - end  
47 -  
48 - protected  
49 -  
50 - def team_member  
51 - @member ||= user_team.members.find_by_username(params[:id])  
52 - end  
53 -end  
app/controllers/teams/projects_controller.rb
@@ -1,40 +0,0 @@ @@ -1,40 +0,0 @@
1 -class Teams::ProjectsController < Teams::ApplicationController  
2 - def create  
3 - redirect_to :back if params[:project_ids].blank?  
4 -  
5 - project_ids = params[:project_ids]  
6 - access = params[:greatest_project_access]  
7 -  
8 - # Reject non-allowed projects  
9 - allowed_project_ids = current_user.owned_projects.map(&:id)  
10 - project_ids.select! { |id| allowed_project_ids.include?(id.to_i) }  
11 -  
12 - # Assign projects to team  
13 - user_team.assign_to_projects(project_ids, access)  
14 -  
15 - redirect_to edit_team_path(user_team), notice: 'Team of users was successfully assigned to projects.'  
16 - end  
17 -  
18 - def edit  
19 - team_project  
20 - end  
21 -  
22 - def update  
23 - if user_team.update_project_access(team_project, params[:greatest_project_access])  
24 - redirect_to edit_team_path(user_team), notice: 'Access was successfully updated.'  
25 - else  
26 - render :edit  
27 - end  
28 - end  
29 -  
30 - def destroy  
31 - user_team.resign_from_project(team_project)  
32 - redirect_to team_projects_path(user_team), notice: 'Team of users was successfully reassigned from project.'  
33 - end  
34 -  
35 - private  
36 -  
37 - def team_project  
38 - @project ||= user_team.projects.find_with_namespace(params[:id])  
39 - end  
40 -end  
app/controllers/teams_controller.rb
@@ -1,93 +0,0 @@ @@ -1,93 +0,0 @@
1 -class TeamsController < ApplicationController  
2 - # Authorize  
3 - before_filter :authorize_create_team!, only: [:new, :create]  
4 - before_filter :authorize_manage_user_team!, only: [:edit, :update]  
5 - before_filter :authorize_admin_user_team!, only: [:destroy]  
6 -  
7 - before_filter :user_team, except: [:new, :create]  
8 -  
9 - layout :determine_layout  
10 -  
11 - before_filter :set_title, only: [:new, :create]  
12 -  
13 - def show  
14 - projects  
15 - @events = Event.in_projects(user_team.project_ids).limit(20).offset(params[:offset] || 0)  
16 - end  
17 -  
18 - def edit  
19 - projects  
20 - @avaliable_projects = current_user.owned_projects.without_team(user_team)  
21 - end  
22 -  
23 - def update  
24 - if user_team.update_attributes(params[:user_team])  
25 - redirect_to team_path(user_team)  
26 - else  
27 - render action: :edit  
28 - end  
29 - end  
30 -  
31 - def destroy  
32 - user_team.destroy  
33 - redirect_to dashboard_path  
34 - end  
35 -  
36 - def new  
37 - @team = UserTeam.new  
38 - end  
39 -  
40 - def create  
41 - @team = UserTeam.new(params[:user_team])  
42 - @team.owner = current_user unless params[:owner]  
43 - @team.path = @team.name.dup.parameterize if @team.name  
44 -  
45 - if @team.save  
46 - # Add current user as Master to the team  
47 - @team.add_members([current_user.id], UsersProject::MASTER, true)  
48 -  
49 - redirect_to team_path(@team)  
50 - else  
51 - render action: :new  
52 - end  
53 - end  
54 -  
55 - # Get authored or assigned open merge requests  
56 - def merge_requests  
57 - projects  
58 - @merge_requests = MergeRequest.of_user_team(user_team)  
59 - @merge_requests = FilterContext.new(@merge_requests, params).execute  
60 - @merge_requests = @merge_requests.recent.page(params[:page]).per(20)  
61 - end  
62 -  
63 - # Get only assigned issues  
64 - def issues  
65 - projects  
66 - @issues = Issue.of_user_team(user_team)  
67 - @issues = FilterContext.new(@issues, params).execute  
68 - @issues = @issues.recent.page(params[:page]).per(20)  
69 - @issues = @issues.includes(:author, :project)  
70 - end  
71 -  
72 - protected  
73 -  
74 - def projects  
75 - @projects ||= user_team.projects.sorted_by_activity  
76 - end  
77 -  
78 - def user_team  
79 - @team ||= current_user.authorized_teams.find_by_path(params[:id])  
80 - end  
81 -  
82 - def set_title  
83 - @title = 'New Team'  
84 - end  
85 -  
86 - def determine_layout  
87 - if [:new, :create].include?(action_name.to_sym)  
88 - 'navless'  
89 - else  
90 - 'user_team'  
91 - end  
92 - end  
93 -end  
app/helpers/application_helper.rb
@@ -92,7 +92,6 @@ module ApplicationHelper @@ -92,7 +92,6 @@ module ApplicationHelper
92 def search_autocomplete_source 92 def search_autocomplete_source
93 projects = current_user.authorized_projects.map { |p| { label: "project: #{simple_sanitize(p.name_with_namespace)}", url: project_path(p) } } 93 projects = current_user.authorized_projects.map { |p| { label: "project: #{simple_sanitize(p.name_with_namespace)}", url: project_path(p) } }
94 groups = current_user.authorized_groups.map { |group| { label: "group: #{simple_sanitize(group.name)}", url: group_path(group) } } 94 groups = current_user.authorized_groups.map { |group| { label: "group: #{simple_sanitize(group.name)}", url: group_path(group) } }
95 - teams = current_user.authorized_teams.map { |team| { label: "team: #{simple_sanitize(team.name)}", url: team_path(team) } }  
96 95
97 default_nav = [ 96 default_nav = [
98 { label: "My Profile", url: profile_path }, 97 { label: "My Profile", url: profile_path },
@@ -128,7 +127,7 @@ module ApplicationHelper @@ -128,7 +127,7 @@ module ApplicationHelper
128 ] 127 ]
129 end 128 end
130 129
131 - [groups, teams, projects, default_nav, project_nav, help_nav].flatten.to_json 130 + [groups, projects, default_nav, project_nav, help_nav].flatten.to_json
132 end 131 end
133 132
134 def emoji_autocomplete_source 133 def emoji_autocomplete_source
app/helpers/user_teams_helper.rb
@@ -1,25 +0,0 @@ @@ -1,25 +0,0 @@
1 -module UserTeamsHelper  
2 - def team_filter_path(entity, options={})  
3 - exist_opts = {  
4 - status: params[:status],  
5 - project_id: params[:project_id],  
6 - }  
7 -  
8 - options = exist_opts.merge(options)  
9 -  
10 - case entity  
11 - when 'issue' then  
12 - issues_team_path(@team, options)  
13 - when 'merge_request'  
14 - merge_requests_team_path(@team, options)  
15 - end  
16 - end  
17 -  
18 - def grouped_user_team_members(team)  
19 - team.user_team_user_relationships.sort_by(&:permission).reverse.group_by(&:permission)  
20 - end  
21 -  
22 - def remove_from_user_team_message(team, member)  
23 - "You are going to remove #{member.name} from #{team.name}. Are you sure?"  
24 - end  
25 -end  
app/models/ability.rb
@@ -11,7 +11,6 @@ class Ability @@ -11,7 +11,6 @@ class Ability
11 when "PersonalSnippet" then personal_snippet_abilities(user, subject) 11 when "PersonalSnippet" then personal_snippet_abilities(user, subject)
12 when "MergeRequest" then merge_request_abilities(user, subject) 12 when "MergeRequest" then merge_request_abilities(user, subject)
13 when "Group", "Namespace" then group_abilities(user, subject) 13 when "Group", "Namespace" then group_abilities(user, subject)
14 - when "UserTeam" then user_team_abilities(user, subject)  
15 else [] 14 else []
16 end.concat(global_abilities(user)) 15 end.concat(global_abilities(user))
17 end 16 end
@@ -19,7 +18,6 @@ class Ability @@ -19,7 +18,6 @@ class Ability
19 def global_abilities(user) 18 def global_abilities(user)
20 rules = [] 19 rules = []
21 rules << :create_group if user.can_create_group 20 rules << :create_group if user.can_create_group
22 - rules << :create_team if user.can_create_team  
23 rules 21 rules
24 end 22 end
25 23
@@ -146,21 +144,6 @@ class Ability @@ -146,21 +144,6 @@ class Ability
146 rules.flatten 144 rules.flatten
147 end 145 end
148 146
149 - def user_team_abilities user, team  
150 - rules = []  
151 -  
152 - # Only group owner and administrators can manage team  
153 - if user.admin? || team.owner == user || team.admin?(user)  
154 - rules << [ :manage_user_team ]  
155 - end  
156 -  
157 - if team.owner == user || user.admin?  
158 - rules << [ :admin_user_team ]  
159 - end  
160 -  
161 - rules.flatten  
162 - end  
163 -  
164 [:issue, :note, :project_snippet, :personal_snippet, :merge_request].each do |name| 147 [:issue, :note, :project_snippet, :personal_snippet, :merge_request].each do |name|
165 define_method "#{name}_abilities" do |user, subject| 148 define_method "#{name}_abilities" do |user, subject|
166 if subject.author == user 149 if subject.author == user
app/models/deprecated/user_team.rb 0 → 100644
@@ -0,0 +1,116 @@ @@ -0,0 +1,116 @@
  1 +# == Schema Information
  2 +#
  3 +# Table name: user_teams
  4 +#
  5 +# id :integer not null, primary key
  6 +# name :string(255)
  7 +# path :string(255)
  8 +# owner_id :integer
  9 +# created_at :datetime not null
  10 +# updated_at :datetime not null
  11 +# description :string(255) default(""), not null
  12 +#
  13 +
  14 +class UserTeam < ActiveRecord::Base
  15 + attr_accessible :name, :description, :owner_id, :path
  16 +
  17 + belongs_to :owner, class_name: User
  18 +
  19 + has_many :user_team_project_relationships, dependent: :destroy
  20 + has_many :user_team_user_relationships, dependent: :destroy
  21 +
  22 + has_many :projects, through: :user_team_project_relationships
  23 + has_many :members, through: :user_team_user_relationships, source: :user
  24 +
  25 + validates :owner, presence: true
  26 + validates :name, presence: true, uniqueness: true,
  27 + length: { within: 0..255 },
  28 + format: { with: Gitlab::Regex.name_regex,
  29 + message: "only letters, digits, spaces & '_' '-' '.' allowed." }
  30 + validates :description, length: { within: 0..255 }
  31 + validates :path, uniqueness: true, presence: true, length: { within: 1..255 },
  32 + format: { with: Gitlab::Regex.path_regex,
  33 + message: "only letters, digits & '_' '-' '.' allowed. Letter should be first" }
  34 +
  35 + scope :with_member, ->(user){ joins(:user_team_user_relationships).where(user_team_user_relationships: {user_id: user.id}) }
  36 + scope :with_project, ->(project){ joins(:user_team_project_relationships).where(user_team_project_relationships: {project_id: project})}
  37 + scope :without_project, ->(project){ where("user_teams.id NOT IN (:ids)", ids: (a = with_project(project); a.blank? ? 0 : a))}
  38 + scope :created_by, ->(user){ where(owner_id: user) }
  39 +
  40 + class << self
  41 + def search query
  42 + where("name LIKE :query OR path LIKE :query", query: "%#{query}%")
  43 + end
  44 +
  45 + def global_id
  46 + 'GLN'
  47 + end
  48 +
  49 + def access_roles
  50 + UsersProject.access_roles
  51 + end
  52 + end
  53 +
  54 + def to_param
  55 + path
  56 + end
  57 +
  58 + def assign_to_projects(projects, access)
  59 + projects.each do |project|
  60 + assign_to_project(project, access)
  61 + end
  62 + end
  63 +
  64 + def assign_to_project(project, access)
  65 + Gitlab::UserTeamManager.assign(self, project, access)
  66 + end
  67 +
  68 + def resign_from_project(project)
  69 + Gitlab::UserTeamManager.resign(self, project)
  70 + end
  71 +
  72 + def add_members(users, access, group_admin)
  73 + # reject existing users
  74 + users.reject! { |id| member_ids.include?(id.to_i) }
  75 +
  76 + users.each do |user|
  77 + add_member(user, access, group_admin)
  78 + end
  79 + end
  80 +
  81 + def add_member(user, access, group_admin)
  82 + Gitlab::UserTeamManager.add_member_into_team(self, user, access, group_admin)
  83 + end
  84 +
  85 + def remove_member(user)
  86 + Gitlab::UserTeamManager.remove_member_from_team(self, user)
  87 + end
  88 +
  89 + def update_membership(user, options)
  90 + Gitlab::UserTeamManager.update_team_user_membership(self, user, options)
  91 + end
  92 +
  93 + def update_project_access(project, permission)
  94 + Gitlab::UserTeamManager.update_project_greates_access(self, project, permission)
  95 + end
  96 +
  97 + def max_project_access(project)
  98 + user_team_project_relationships.find_by_project_id(project).greatest_access
  99 + end
  100 +
  101 + def human_max_project_access(project)
  102 + self.class.access_roles.invert[max_project_access(project)]
  103 + end
  104 +
  105 + def default_projects_access(member)
  106 + user_team_user_relationships.find_by_user_id(member).permission
  107 + end
  108 +
  109 + def human_default_projects_access(member)
  110 + self.class.access_roles.invert[default_projects_access(member)]
  111 + end
  112 +
  113 + def admin?(member)
  114 + user_team_user_relationships.with_user(member).first.try(:group_admin?)
  115 + end
  116 +end
app/models/deprecated/user_team_project_relationship.rb 0 → 100644
@@ -0,0 +1,44 @@ @@ -0,0 +1,44 @@
  1 +# == Schema Information
  2 +#
  3 +# Table name: user_team_project_relationships
  4 +#
  5 +# id :integer not null, primary key
  6 +# project_id :integer
  7 +# user_team_id :integer
  8 +# greatest_access :integer
  9 +# created_at :datetime not null
  10 +# updated_at :datetime not null
  11 +#
  12 +
  13 +class UserTeamProjectRelationship < ActiveRecord::Base
  14 + attr_accessible :greatest_access, :project_id, :user_team_id
  15 +
  16 + belongs_to :user_team
  17 + belongs_to :project
  18 +
  19 + validates :project, presence: true
  20 + validates :user_team, presence: true
  21 + validate :check_greatest_access
  22 +
  23 + scope :with_project, ->(project){ where(project_id: project.id) }
  24 +
  25 + def team_name
  26 + user_team.name
  27 + end
  28 +
  29 + def human_max_access
  30 + UserTeam.access_roles.key(greatest_access)
  31 + end
  32 +
  33 + private
  34 +
  35 + def check_greatest_access
  36 + errors.add(:base, :incorrect_access_code) unless correct_access?
  37 + end
  38 +
  39 + def correct_access?
  40 + return false if greatest_access.blank?
  41 + return true if UsersProject.access_roles.has_value?(greatest_access)
  42 + false
  43 + end
  44 +end
app/models/deprecated/user_team_user_relationship.rb 0 → 100644
@@ -0,0 +1,32 @@ @@ -0,0 +1,32 @@
  1 +# == Schema Information
  2 +#
  3 +# Table name: user_team_user_relationships
  4 +#
  5 +# id :integer not null, primary key
  6 +# user_id :integer
  7 +# user_team_id :integer
  8 +# group_admin :boolean
  9 +# permission :integer
  10 +# created_at :datetime not null
  11 +# updated_at :datetime not null
  12 +#
  13 +
  14 +class UserTeamUserRelationship < ActiveRecord::Base
  15 + attr_accessible :group_admin, :permission, :user_id, :user_team_id
  16 +
  17 + belongs_to :user_team
  18 + belongs_to :user
  19 +
  20 + validates :user_team, presence: true
  21 + validates :user, presence: true
  22 +
  23 + scope :with_user, ->(user) { where(user_id: user.id) }
  24 +
  25 + def user_name
  26 + user.name
  27 + end
  28 +
  29 + def access_human
  30 + UsersProject.access_roles.invert[permission]
  31 + end
  32 +end
app/models/user.rb
@@ -75,13 +75,6 @@ class User &lt; ActiveRecord::Base @@ -75,13 +75,6 @@ class User &lt; ActiveRecord::Base
75 has_many :users_groups, dependent: :destroy 75 has_many :users_groups, dependent: :destroy
76 has_many :groups, through: :users_groups 76 has_many :groups, through: :users_groups
77 77
78 - # Teams  
79 - has_many :own_teams, dependent: :destroy, class_name: "UserTeam", foreign_key: :owner_id  
80 - has_many :user_team_user_relationships, dependent: :destroy  
81 - has_many :user_teams, through: :user_team_user_relationships  
82 - has_many :user_team_project_relationships, through: :user_teams  
83 - has_many :team_projects, through: :user_team_project_relationships  
84 -  
85 # Projects 78 # Projects
86 has_many :snippets, dependent: :destroy, foreign_key: :author_id, class_name: "Snippet" 79 has_many :snippets, dependent: :destroy, foreign_key: :author_id, class_name: "Snippet"
87 has_many :users_projects, dependent: :destroy 80 has_many :users_projects, dependent: :destroy
@@ -235,10 +228,6 @@ class User &lt; ActiveRecord::Base @@ -235,10 +228,6 @@ class User &lt; ActiveRecord::Base
235 own_groups 228 own_groups
236 end 229 end
237 230
238 - def owned_teams  
239 - own_teams  
240 - end  
241 -  
242 # Groups user has access to 231 # Groups user has access to
243 def authorized_groups 232 def authorized_groups
244 @group_ids ||= (groups.pluck(:id) + own_groups.pluck(:id) + authorized_projects.pluck(:namespace_id)) 233 @group_ids ||= (groups.pluck(:id) + own_groups.pluck(:id) + authorized_projects.pluck(:namespace_id))
@@ -252,15 +241,6 @@ class User &lt; ActiveRecord::Base @@ -252,15 +241,6 @@ class User &lt; ActiveRecord::Base
252 Project.where(id: @project_ids) 241 Project.where(id: @project_ids)
253 end 242 end
254 243
255 - def authorized_teams  
256 - if admin?  
257 - UserTeam.scoped  
258 - else  
259 - @team_ids ||= (user_teams.pluck(:id) + own_teams.pluck(:id)).uniq  
260 - UserTeam.where(id: @team_ids)  
261 - end  
262 - end  
263 -  
264 # Team membership in authorized projects 244 # Team membership in authorized projects
265 def tm_in_authorized_projects 245 def tm_in_authorized_projects
266 UsersProject.where(project_id: authorized_projects.map(&:id), user_id: self.id) 246 UsersProject.where(project_id: authorized_projects.map(&:id), user_id: self.id)
app/models/user_team.rb
@@ -1,116 +0,0 @@ @@ -1,116 +0,0 @@
1 -# == Schema Information  
2 -#  
3 -# Table name: user_teams  
4 -#  
5 -# id :integer not null, primary key  
6 -# name :string(255)  
7 -# path :string(255)  
8 -# owner_id :integer  
9 -# created_at :datetime not null  
10 -# updated_at :datetime not null  
11 -# description :string(255) default(""), not null  
12 -#  
13 -  
14 -class UserTeam < ActiveRecord::Base  
15 - attr_accessible :name, :description, :owner_id, :path  
16 -  
17 - belongs_to :owner, class_name: User  
18 -  
19 - has_many :user_team_project_relationships, dependent: :destroy  
20 - has_many :user_team_user_relationships, dependent: :destroy  
21 -  
22 - has_many :projects, through: :user_team_project_relationships  
23 - has_many :members, through: :user_team_user_relationships, source: :user  
24 -  
25 - validates :owner, presence: true  
26 - validates :name, presence: true, uniqueness: true,  
27 - length: { within: 0..255 },  
28 - format: { with: Gitlab::Regex.name_regex,  
29 - message: "only letters, digits, spaces & '_' '-' '.' allowed." }  
30 - validates :description, length: { within: 0..255 }  
31 - validates :path, uniqueness: true, presence: true, length: { within: 1..255 },  
32 - format: { with: Gitlab::Regex.path_regex,  
33 - message: "only letters, digits & '_' '-' '.' allowed. Letter should be first" }  
34 -  
35 - scope :with_member, ->(user){ joins(:user_team_user_relationships).where(user_team_user_relationships: {user_id: user.id}) }  
36 - scope :with_project, ->(project){ joins(:user_team_project_relationships).where(user_team_project_relationships: {project_id: project})}  
37 - scope :without_project, ->(project){ where("user_teams.id NOT IN (:ids)", ids: (a = with_project(project); a.blank? ? 0 : a))}  
38 - scope :created_by, ->(user){ where(owner_id: user) }  
39 -  
40 - class << self  
41 - def search query  
42 - where("name LIKE :query OR path LIKE :query", query: "%#{query}%")  
43 - end  
44 -  
45 - def global_id  
46 - 'GLN'  
47 - end  
48 -  
49 - def access_roles  
50 - UsersProject.access_roles  
51 - end  
52 - end  
53 -  
54 - def to_param  
55 - path  
56 - end  
57 -  
58 - def assign_to_projects(projects, access)  
59 - projects.each do |project|  
60 - assign_to_project(project, access)  
61 - end  
62 - end  
63 -  
64 - def assign_to_project(project, access)  
65 - Gitlab::UserTeamManager.assign(self, project, access)  
66 - end  
67 -  
68 - def resign_from_project(project)  
69 - Gitlab::UserTeamManager.resign(self, project)  
70 - end  
71 -  
72 - def add_members(users, access, group_admin)  
73 - # reject existing users  
74 - users.reject! { |id| member_ids.include?(id.to_i) }  
75 -  
76 - users.each do |user|  
77 - add_member(user, access, group_admin)  
78 - end  
79 - end  
80 -  
81 - def add_member(user, access, group_admin)  
82 - Gitlab::UserTeamManager.add_member_into_team(self, user, access, group_admin)  
83 - end  
84 -  
85 - def remove_member(user)  
86 - Gitlab::UserTeamManager.remove_member_from_team(self, user)  
87 - end  
88 -  
89 - def update_membership(user, options)  
90 - Gitlab::UserTeamManager.update_team_user_membership(self, user, options)  
91 - end  
92 -  
93 - def update_project_access(project, permission)  
94 - Gitlab::UserTeamManager.update_project_greates_access(self, project, permission)  
95 - end  
96 -  
97 - def max_project_access(project)  
98 - user_team_project_relationships.find_by_project_id(project).greatest_access  
99 - end  
100 -  
101 - def human_max_project_access(project)  
102 - self.class.access_roles.invert[max_project_access(project)]  
103 - end  
104 -  
105 - def default_projects_access(member)  
106 - user_team_user_relationships.find_by_user_id(member).permission  
107 - end  
108 -  
109 - def human_default_projects_access(member)  
110 - self.class.access_roles.invert[default_projects_access(member)]  
111 - end  
112 -  
113 - def admin?(member)  
114 - user_team_user_relationships.with_user(member).first.try(:group_admin?)  
115 - end  
116 -end  
app/models/user_team_project_relationship.rb
@@ -1,44 +0,0 @@ @@ -1,44 +0,0 @@
1 -# == Schema Information  
2 -#  
3 -# Table name: user_team_project_relationships  
4 -#  
5 -# id :integer not null, primary key  
6 -# project_id :integer  
7 -# user_team_id :integer  
8 -# greatest_access :integer  
9 -# created_at :datetime not null  
10 -# updated_at :datetime not null  
11 -#  
12 -  
13 -class UserTeamProjectRelationship < ActiveRecord::Base  
14 - attr_accessible :greatest_access, :project_id, :user_team_id  
15 -  
16 - belongs_to :user_team  
17 - belongs_to :project  
18 -  
19 - validates :project, presence: true  
20 - validates :user_team, presence: true  
21 - validate :check_greatest_access  
22 -  
23 - scope :with_project, ->(project){ where(project_id: project.id) }  
24 -  
25 - def team_name  
26 - user_team.name  
27 - end  
28 -  
29 - def human_max_access  
30 - UserTeam.access_roles.key(greatest_access)  
31 - end  
32 -  
33 - private  
34 -  
35 - def check_greatest_access  
36 - errors.add(:base, :incorrect_access_code) unless correct_access?  
37 - end  
38 -  
39 - def correct_access?  
40 - return false if greatest_access.blank?  
41 - return true if UsersProject.access_roles.has_value?(greatest_access)  
42 - false  
43 - end  
44 -end  
app/models/user_team_user_relationship.rb
@@ -1,32 +0,0 @@ @@ -1,32 +0,0 @@
1 -# == Schema Information  
2 -#  
3 -# Table name: user_team_user_relationships  
4 -#  
5 -# id :integer not null, primary key  
6 -# user_id :integer  
7 -# user_team_id :integer  
8 -# group_admin :boolean  
9 -# permission :integer  
10 -# created_at :datetime not null  
11 -# updated_at :datetime not null  
12 -#  
13 -  
14 -class UserTeamUserRelationship < ActiveRecord::Base  
15 - attr_accessible :group_admin, :permission, :user_id, :user_team_id  
16 -  
17 - belongs_to :user_team  
18 - belongs_to :user  
19 -  
20 - validates :user_team, presence: true  
21 - validates :user, presence: true  
22 -  
23 - scope :with_user, ->(user) { where(user_id: user.id) }  
24 -  
25 - def user_name  
26 - user.name  
27 - end  
28 -  
29 - def access_human  
30 - UsersProject.access_roles.invert[permission]  
31 - end  
32 -end  
app/views/admin/dashboard/index.html.haml
@@ -50,10 +50,6 @@ @@ -50,10 +50,6 @@
50 %h4 Stats 50 %h4 Stats
51 %hr 51 %hr
52 %p 52 %p
53 - Teams  
54 - %span.light.pull-right  
55 - = UserTeam.count  
56 - %p  
57 Forks 53 Forks
58 %span.light.pull-right 54 %span.light.pull-right
59 = ForkedProjectLink.count 55 = ForkedProjectLink.count
app/views/admin/teams/edit.html.haml
@@ -1,28 +0,0 @@ @@ -1,28 +0,0 @@
1 -%h3.page_title Edit Team  
2 -%hr  
3 -= form_for @team, url: admin_team_path(@team), method: :put do |f|  
4 - - if @team.errors.any?  
5 - .alert.alert-error  
6 - %span= @team.errors.full_messages.first  
7 - .clearfix.team_name_holder  
8 - = f.label :name do  
9 - Team name is  
10 - .input  
11 - = f.text_field :name, placeholder: "Example Team", class: "xxlarge"  
12 -  
13 - .clearfix.team-description-holder  
14 - = f.label :description, "Details"  
15 - .input  
16 - = f.text_area :description, maxlength: 250, class: "xxlarge js-gfm-input", rows: 4  
17 -  
18 - .clearfix.team_name_holder  
19 - = f.label :path do  
20 - %span.cred Team path is  
21 - .input  
22 - = f.text_field :path, placeholder: "example-team", class: "xxlarge danger"  
23 - %ul.cred  
24 - %li It will change web url for access team and team projects.  
25 -  
26 - .form-actions  
27 - = f.submit 'Edit team', class: "btn btn-remove"  
28 - = link_to 'Cancel', admin_teams_path, class: "btn btn-cancel"  
app/views/admin/teams/index.html.haml
@@ -1,48 +0,0 @@ @@ -1,48 +0,0 @@
1 -%h3.page_title  
2 - Teams (#{@teams.total_count})  
3 - %small  
4 - allow you to organize groups of people that have a common focus. Use teams to simplify the process of assigning roles to groups of people.  
5 -  
6 - = link_to 'New Team', new_admin_team_path, class: "btn btn-small pull-right"  
7 -%br  
8 -  
9 -= form_tag admin_teams_path, method: :get, class: 'form-inline' do  
10 - = text_field_tag :name, params[:name], class: "span6"  
11 - = submit_tag "Search", class: "btn submit btn-primary"  
12 -  
13 -%hr  
14 -  
15 -%ul.bordered-list  
16 - - @teams.each do |team|  
17 - %li  
18 - .clearfix  
19 - .pull-right.prepend-top-10  
20 - = link_to 'Edit', edit_admin_team_path(team), id: "edit_#{dom_id(team)}", class: "btn btn-small"  
21 - = link_to 'Destroy', admin_team_path(team), confirm: "REMOVE #{team.name}? Are you sure?", method: :delete, class: "btn btn-small btn-remove"  
22 -  
23 - %h4  
24 - = link_to admin_team_path(team) do  
25 - %i.icon-group  
26 - = team.name  
27 -  
28 - .clearfix.light.append-bottom-10  
29 - %span  
30 - %b Owner:  
31 - - if team.owner  
32 - = link_to team.owner.name, admin_user_path(team.owner)  
33 - - else  
34 - (deleted)  
35 - \|  
36 - %span  
37 - %b Users:  
38 - %span.badge= team.members.count  
39 - \|  
40 - %span  
41 - %b Projects:  
42 - %span.badge= team.projects.count  
43 -  
44 - .clearfix  
45 - %p  
46 - = truncate team.description, length: 150  
47 -  
48 -= paginate @teams, theme: "gitlab"  
app/views/admin/teams/members/_form.html.haml
@@ -1,20 +0,0 @@ @@ -1,20 +0,0 @@
1 -= form_tag admin_team_member_path(@team, @member), method: :put do  
2 - -if @member.errors.any?  
3 - .alert.alert-error  
4 - %ul  
5 - - @member.errors.full_messages.each do |msg|  
6 - %li= msg  
7 -  
8 - .clearfix  
9 - %label Default access for Team projects:  
10 - .input  
11 - = select_tag :default_project_access, options_for_select(UserTeam.access_roles, @team.default_projects_access(@member)), class: "project-access-select chosen span3"  
12 - .clearfix  
13 - %label Team admin?  
14 - .input  
15 - = check_box_tag :group_admin, true, @team.admin?(@member)  
16 -  
17 - %br  
18 - .actions  
19 - = submit_tag 'Save', class: "btn btn-primary"  
20 - = link_to 'Cancel', :back, class: "btn"  
app/views/admin/teams/members/edit.html.haml
@@ -1,16 +0,0 @@ @@ -1,16 +0,0 @@
1 -%h3  
2 - Edit access #{@member.name} in #{@team.name} team  
3 -  
4 -%hr  
5 -%table.zebra-striped  
6 - %tr  
7 - %td User:  
8 - %td= @member.name  
9 - %tr  
10 - %td Team:  
11 - %td= @team.name  
12 - %tr  
13 - %td Since:  
14 - %td= member_since(@team, @member).stamp("Nov 11, 2010")  
15 -  
16 -= render 'form'  
app/views/admin/teams/members/new.html.haml
@@ -1,27 +0,0 @@ @@ -1,27 +0,0 @@
1 -%h3.page_title  
2 - New members for  
3 - = link_to @team.name, admin_team_path(@team)  
4 - team  
5 -%hr  
6 -= form_tag admin_team_members_path(@team), id: "team_members", class: "bulk_import", method: :post do  
7 - - if @team.errors.any?  
8 - .alert.alert-error  
9 - %span= @team.errors.full_messages.first  
10 - .clearfix  
11 - = label_tag :user_ids do  
12 - Users to add  
13 - .input  
14 - = select_tag :user_ids, options_from_collection_for_select(@users , :id, :name_with_username), multiple: true, data: {placeholder: 'Select users'}, class: 'chosen span5'  
15 - .clearfix.group-description-holder  
16 - = label_tag :default_project_access do  
17 - Default permission in projects  
18 - .input  
19 - = select_tag :default_project_access, options_for_select(Project.access_options), {class: "project-access-select chosen span3" }  
20 - .clearfix  
21 - = label_tag :group_admin do  
22 - Is team admin  
23 - .input  
24 - = check_box_tag :group_admin  
25 - .clearfix.form-actions  
26 - = submit_tag 'Add users into team', class: "btn btn-primary", id: :add_members_to_team  
27 - = link_to 'Cancel', :back, class: "btn"  
app/views/admin/teams/new.html.haml
@@ -1,26 +0,0 @@ @@ -1,26 +0,0 @@
1 -%h3.page_title New Team  
2 -%hr  
3 -= form_for @team, url: admin_teams_path do |f|  
4 - - if @team.errors.any?  
5 - .alert.alert-error  
6 - %span= @team.errors.full_messages.first  
7 - .clearfix  
8 - = f.label :name do  
9 - Team name is  
10 - .input  
11 - = f.text_field :name, placeholder: "Ex. OpenSource", class: "xxlarge left"  
12 -  
13 - .clearfix.team-description-holder  
14 - = f.label :description, "Details"  
15 - .input  
16 - = f.text_area :description, maxlength: 250, class: "xxlarge js-gfm-input", rows: 4  
17 -  
18 - .form-actions  
19 - = f.submit 'Create team', class: "btn btn-create"  
20 -  
21 - %hr  
22 - .padded  
23 - %ul  
24 - %li All created teams are public (users can view who enter into team and which project are assigned for this team)  
25 - %li People within a team see only projects they have access to  
26 - %li You will be able to assign existing projects for team  
app/views/admin/teams/projects/_form.html.haml
@@ -1,16 +0,0 @@ @@ -1,16 +0,0 @@
1 -= form_tag admin_team_project_path(@team, @project), method: :put do  
2 - -if @project.errors.any?  
3 - .alert.alert-error  
4 - %ul  
5 - - @project.errors.full_messages.each do |msg|  
6 - %li= msg  
7 -  
8 - .clearfix  
9 - %label Max access for Team members:  
10 - .input  
11 - = select_tag :greatest_project_access, options_for_select(UserTeam.access_roles, @team.max_project_access(@project)), class: "project-access-select chosen span3"  
12 -  
13 - %br  
14 - .actions  
15 - = submit_tag 'Save', class: "btn btn-primary"  
16 - = link_to 'Cancel', :back, class: "btn"  
app/views/admin/teams/projects/edit.html.haml
@@ -1,16 +0,0 @@ @@ -1,16 +0,0 @@
1 -%h3  
2 - Edit max access in #{@project.name} for #{@team.name} team  
3 -  
4 -%hr  
5 -%table.zebra-striped  
6 - %tr  
7 - %td Project:  
8 - %td= @project.name  
9 - %tr  
10 - %td Team:  
11 - %td= @team.name  
12 - %tr  
13 - %td Since:  
14 - %td= assigned_since(@team, @project).stamp("Nov 11, 2010")  
15 -  
16 -= render 'form'  
app/views/admin/teams/projects/new.html.haml
@@ -1,18 +0,0 @@ @@ -1,18 +0,0 @@
1 -%h3.page_title  
2 - Team: #{@team.name}  
3 -%hr  
4 -= form_tag admin_team_projects_path(@team), id: "assign_projects", class: "bulk_import", method: :post do  
5 - %h6 Choose Projects you want to assign:  
6 - .clearfix  
7 - = label_tag :project_ids, "Projects"  
8 - .input  
9 - = select_tag :project_ids, options_from_collection_for_select(@projects , :id, :name_with_namespace), multiple: true, data: {placeholder: 'Select projects'}, class: 'chosen span5'  
10 -  
11 - %h6 Choose greatest user acces for your team in this projects:  
12 - .clearfix  
13 - = label_tag :greatest_project_access, "Greatest Access"  
14 - .input  
15 - = select_tag :greatest_project_access, options_for_select(Project.access_options), {class: "project-access-select chosen span3" }  
16 -  
17 - .form-actions  
18 - = submit_tag 'Add team to projects', class: "btn btn-create", id: :assign_projects_to_team  
app/views/admin/teams/show.html.haml
@@ -1,96 +0,0 @@ @@ -1,96 +0,0 @@
1 -%h3.page_title  
2 - Team: #{@team.name}  
3 -  
4 -  
5 - = link_to edit_admin_team_path(@team), class: "btn btn-small pull-right" do  
6 - %i.icon-edit  
7 - Edit  
8 -%hr  
9 -  
10 -  
11 -.row  
12 - .span6  
13 - .ui-box  
14 - %h5.title  
15 - Team info:  
16 - %ul.well-list  
17 - %li  
18 - %span.light Name:  
19 - %strong= @team.name  
20 - %li  
21 - %span.light Path:  
22 - %strong  
23 - = @team.path  
24 -  
25 - %li  
26 - %span.light Description:  
27 - %strong  
28 - = @team.description  
29 -  
30 - %li  
31 - %span.light Owned by:  
32 - %strong  
33 - - if @team.owner  
34 - = link_to @team.owner.name, admin_user_path(@team.owner)  
35 - - else  
36 - (deleted)  
37 - .pull-right  
38 - = link_to "#", class: "btn btn-small change-owner-link" do  
39 - %i.icon-edit  
40 - Change owner  
41 - %li.change-owner-holder.hide.bgred  
42 - .form-holder  
43 - %strong.cred New Owner:  
44 - = form_for @team, url: admin_team_path(@team) do |f|  
45 - = users_select_tag(:"user_team[owner_id]")  
46 - .prepend-top-10  
47 - = f.submit 'Change Owner', class: "btn btn-remove"  
48 - = link_to "Cancel", "#", class: "btn change-owner-cancel-link"  
49 -  
50 - %li  
51 - %span.light Created at:  
52 - %strong  
53 - = @team.created_at.stamp("March 1, 1999")  
54 -  
55 - .span6  
56 - .ui-box  
57 - %h5.title  
58 - Members (#{@team.members.count})  
59 - .pull-right  
60 - = link_to 'Add members', new_admin_team_member_path(@team), class: "btn btn-small", id: :add_members_to_team  
61 - %ul.well-list#members_list  
62 - - @team.members.each do |member|  
63 - %li.member{ class: "user_#{member.id}"}  
64 - = link_to [:admin, member] do  
65 - %strong  
66 - = member.name  
67 - .pull-right  
68 - %span.light  
69 - = @team.human_default_projects_access(member)  
70 - - if @team.admin?(member)  
71 - %span.label.label-info Admin  
72 - &nbsp;  
73 - = link_to 'Edit', edit_admin_team_member_path(@team, member), class: "btn btn-small"  
74 - &nbsp;  
75 - = link_to 'Remove', admin_team_member_path(@team, member), confirm: 'Remove member from team. Are you sure?', method: :delete, class: "btn btn-remove btn-small", id: "remove_member_#{member.id}"  
76 -  
77 -  
78 - .ui-box  
79 - %h5.title  
80 - Projects (#{@team.projects.count})  
81 - .pull-right  
82 - = link_to 'Add projects', new_admin_team_project_path(@team), class: "btn btn-small", id: :assign_projects_to_team  
83 - %ul.well-list#projects_list  
84 - - @team.projects.each do |project|  
85 - %li.project  
86 - = link_to [:admin, project] do  
87 - %strong  
88 - = project.name_with_namespace  
89 -  
90 - .pull-right  
91 - %span.light  
92 - = @team.human_max_project_access(project)  
93 - &nbsp;  
94 - = link_to 'Edit', edit_admin_team_project_path(@team, project), class: "btn btn-small"  
95 - &nbsp;  
96 - = link_to 'Relegate', admin_team_project_path(@team, project), confirm: 'Remove project from team. Are you sure?', method: :delete, class: "btn btn-remove small", id: "relegate_project_#{project.id}"  
app/views/admin/users/show.html.haml
@@ -93,13 +93,6 @@ @@ -93,13 +93,6 @@
93 %li 93 %li
94 %strong= link_to group.name, admin_group_path(group) 94 %strong= link_to group.name, admin_group_path(group)
95 95
96 - - if @admin_user.owned_teams.present?  
97 - .ui-box  
98 - %h5.title Owned teams:  
99 - %ul.well-list  
100 - - @admin_user.owned_teams.each do |team|  
101 - %li  
102 - %strong= link_to team.name, admin_team_path(team)  
103 96
104 97
105 .span6 98 .span6
app/views/dashboard/_sidebar.html.haml
@@ -3,16 +3,12 @@ @@ -3,16 +3,12 @@
3 = link_to 'Projects', '#projects', 'data-toggle' => 'tab', id: 'sidebar-projects-tab' 3 = link_to 'Projects', '#projects', 'data-toggle' => 'tab', id: 'sidebar-projects-tab'
4 %li 4 %li
5 = link_to 'Groups', '#groups', 'data-toggle' => 'tab', id: 'sidebar-groups-tab' 5 = link_to 'Groups', '#groups', 'data-toggle' => 'tab', id: 'sidebar-groups-tab'
6 - %li  
7 - = link_to 'Teams', '#teams', 'data-toggle' => 'tab', id: 'sidebar-teams-tab'  
8 6
9 .tab-content 7 .tab-content
10 .tab-pane.active#projects 8 .tab-pane.active#projects
11 = render "projects", projects: @projects 9 = render "projects", projects: @projects
12 .tab-pane#groups 10 .tab-pane#groups
13 = render "groups", groups: @groups 11 = render "groups", groups: @groups
14 - .tab-pane#teams  
15 - = render "teams", teams: @teams  
16 12
17 .prepend-top-20 13 .prepend-top-20
18 %span.rss-icon 14 %span.rss-icon
app/views/layouts/nav/_admin.html.haml
@@ -4,8 +4,6 @@ @@ -4,8 +4,6 @@
4 %i.icon-home 4 %i.icon-home
5 = nav_link(controller: :projects) do 5 = nav_link(controller: :projects) do
6 = link_to "Projects", admin_projects_path 6 = link_to "Projects", admin_projects_path
7 - = nav_link(controller: :teams) do  
8 - = link_to "Teams", admin_teams_path  
9 = nav_link(controller: :groups) do 7 = nav_link(controller: :groups) do
10 = link_to "Groups", admin_groups_path 8 = link_to "Groups", admin_groups_path
11 = nav_link(controller: :users) do 9 = nav_link(controller: :users) do
app/views/projects/teams/available.html.haml
@@ -1,22 +0,0 @@ @@ -1,22 +0,0 @@
1 -= render "projects/settings_nav"  
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 btn-create"  
21 - = link_to "Cancel", project_team_index_path(@project), class: "btn btn-cancel"  
22 -  
app/views/teams/_filter.html.haml
@@ -1,33 +0,0 @@ @@ -1,33 +0,0 @@
1 -= form_tag team_filter_path(entity), method: 'get' do  
2 - %fieldset.dashboard-search-filter  
3 - = search_field_tag "search", params[:search], { placeholder: 'Search', class: 'search-text-input' }  
4 - = button_tag type: 'submit', class: 'btn' do  
5 - %i.icon-search  
6 -  
7 - %fieldset  
8 - %legend Status:  
9 - %ul.nav.nav-pills.nav-stacked  
10 - %li{class: ("active" if !params[:status])}  
11 - = link_to team_filter_path(entity, status: nil) do  
12 - Open  
13 - %li{class: ("active" if params[:status] == 'closed')}  
14 - = link_to team_filter_path(entity, status: 'closed') do  
15 - Closed  
16 - %li{class: ("active" if params[:status] == 'all')}  
17 - = link_to team_filter_path(entity, status: 'all') do  
18 - All  
19 -  
20 - %fieldset  
21 - %legend Projects:  
22 - %ul.nav.nav-pills.nav-stacked  
23 - - @projects.each do |project|  
24 - - unless entities_per_project(project, entity).zero?  
25 - %li{class: ("active" if params[:project_id] == project.id.to_s)}  
26 - = link_to team_filter_path(entity, project_id: project.id) do  
27 - = project.name_with_namespace  
28 - %small.pull-right= entities_per_project(project, entity)  
29 -  
30 - %fieldset  
31 - %hr  
32 - = link_to "Reset", team_filter_path(entity), class: 'btn pull-right'  
33 -  
app/views/teams/_projects.html.haml
@@ -1,22 +0,0 @@ @@ -1,22 +0,0 @@
1 -.ui-box  
2 - %h5.title  
3 - Projects  
4 - %small  
5 - (#{projects.count})  
6 - - if can? current_user, :manage_user_team, @team  
7 - %span.pull-right  
8 - = link_to edit_team_path(@team), class: "btn btn-tiny info" do  
9 - %i.icon-plus  
10 - Assign Project  
11 - %ul.well-list  
12 - - if projects.blank?  
13 - %p.nothing_here_message This team has no projects yet  
14 - - projects.each do |project|  
15 - %li  
16 - = link_to project_path(project), class: dom_class(project) do  
17 - %strong.well-title= truncate(project.name_with_namespace, length: 40)  
18 - %span.arrow  
19 - &rarr;  
20 - %span.last_activity  
21 - %strong Last activity:  
22 - %span= project_last_activity(project)  
app/views/teams/edit.html.haml
@@ -1,74 +0,0 @@ @@ -1,74 +0,0 @@
1 -.row  
2 - .span3  
3 - %ul.nav.nav-pills.nav-stacked  
4 - %li.active  
5 - = link_to 'Projects', '#tab-projects', 'data-toggle' => 'tab'  
6 - %li  
7 - = link_to 'Edit Team', '#tab-edit', 'data-toggle' => 'tab'  
8 - - if can? current_user, :admin_user_team, @team  
9 - %li  
10 - = link_to 'Remove', '#tab-remove', 'data-toggle' => 'tab'  
11 -  
12 - .span9  
13 - .tab-content  
14 - .tab-pane.active#tab-projects  
15 - .ui-box.projects-table  
16 - %h5.title Projects  
17 - %ul.well-list  
18 - - @projects.each do |project|  
19 - %li  
20 - - if project.public  
21 - %i.icon-share  
22 - - else  
23 - %i.icon-lock.cgreen  
24 - = link_to project.name_with_namespace, project  
25 - .pull-right  
26 - = link_to 'Edit max access', edit_team_project_path(@team, project), class: "btn btn-small"  
27 - = link_to 'Relegate', team_project_path(@team, project), confirm: 'Remove project from team and move to global namespace. Are you sure?', method: :delete, class: "btn btn-remove small"  
28 - .form-holder  
29 - = form_tag team_projects_path(@team), id: "assign_projects", class: "bulk_import", method: :post do  
30 - %table.headless  
31 - %tr  
32 - %td= select_tag :project_ids, options_from_collection_for_select(@avaliable_projects , :id, :name_with_namespace), multiple: true, data: {placeholder: 'Select projects'}, class: 'chosen span4'  
33 - %td= select_tag :greatest_project_access, options_for_select(UserTeam.access_roles), {class: "project-access-select chosen" }  
34 - %td= submit_tag 'Add Project', class: "btn btn-create", id: :assign_projects_to_team  
35 -  
36 -  
37 - .tab-pane#tab-edit  
38 - .ui-box  
39 - %h5.title Edit Team  
40 - %div.form-holder  
41 - = form_for @team, url: team_path(@team) do |f|  
42 - - if @team.errors.any?  
43 - .alert.alert-error  
44 - %span= @team.errors.full_messages.first  
45 - .clearfix  
46 - = f.label :name do  
47 - Team name is  
48 - .input  
49 - = f.text_field :name, placeholder: "Ex. OpenSource", class: "xlarge left"  
50 -  
51 - .clearfix.team-description-holder  
52 - = f.label :description, "Details"  
53 - .input  
54 - = f.text_area :description, maxlength: 250, class: "xlarge js-gfm-input", rows: 4  
55 -  
56 - .clearfix  
57 - = f.label :path do  
58 - Team path is  
59 - .input  
60 - = f.text_field :path, placeholder: "opensource", class: "xlarge left"  
61 -  
62 - .form-actions  
63 - = f.submit 'Save team changes', class: "btn btn-primary"  
64 -  
65 - .tab-pane#tab-remove  
66 - .ui-box.ui-box-danger  
67 - %h5.title Remove team  
68 - .ui-box-body  
69 - %p  
70 - Remove of team will cause removing members access to projects.  
71 - %p  
72 - %strong Removed team can not be restored!  
73 -  
74 - = link_to 'Remove team', team_path(@team), method: :delete, confirm: "You are sure?", class: "btn btn-remove btn-small"  
app/views/teams/issues.html.haml
@@ -1,23 +0,0 @@ @@ -1,23 +0,0 @@
1 -%h3.page_title  
2 - Issues  
3 - %small (in Team projects assigned to Team members)  
4 - %small.pull-right #{@issues.total_count} issues  
5 -  
6 -%hr  
7 -.row  
8 - .span3  
9 - = render 'filter', entity: 'issue'  
10 - .span9  
11 - - if @issues.any?  
12 - - @issues.group_by(&:project).each do |group|  
13 - %div.ui-box  
14 - - @project = group[0]  
15 - %h5.title  
16 - = link_to_project @project  
17 - %ul.well-list.issues-list  
18 - - group[1].each do |issue|  
19 - = render issue  
20 - %hr  
21 - = paginate @issues, theme: "gitlab"  
22 - - else  
23 - %p.nothing_here_message Nothing to show here  
app/views/teams/members/_form.html.haml
@@ -1,20 +0,0 @@ @@ -1,20 +0,0 @@
1 -= form_tag admin_team_member_path(@team, @member), method: :put do  
2 - -if @member.errors.any?  
3 - .alert.alert-error  
4 - %ul  
5 - - @member.errors.full_messages.each do |msg|  
6 - %li= msg  
7 -  
8 - .clearfix  
9 - %label Default access for Team projects:  
10 - .input  
11 - = select_tag :default_project_access, options_for_select(UserTeam.access_roles, @team.default_projects_access(@member)), class: "project-access-select chosen span3"  
12 - .clearfix  
13 - %label Team admin?  
14 - .input  
15 - = check_box_tag :group_admin, true, @team.admin?(@member)  
16 -  
17 - %br  
18 - .actions  
19 - = submit_tag 'Save', class: "btn btn-save"  
20 - = link_to 'Cancel', :back, class: "btn"  
app/views/teams/members/_member.html.haml
@@ -1,31 +0,0 @@ @@ -1,31 +0,0 @@
1 -- user = member.user  
2 -- allow_admin = can? current_user, :manage_user_team, @team  
3 -%li{id: dom_id(member), class: "team_member_row user_#{user.id}"}  
4 - .row  
5 - .span3  
6 - = link_to user_path(user.username), title: user.name, class: "dark" do  
7 - = image_tag gravatar_icon(user.email, 40), class: "avatar s32"  
8 - = link_to user_path(user.username), title: user.name, class: "dark" do  
9 - %strong= truncate(user.name, lenght: 40)  
10 - %br  
11 - %small.cgray= user.username  
12 -  
13 - .span5.pull-right  
14 - - if allow_admin  
15 - .pull-left  
16 - = form_for(member, as: :team_member, url: team_member_path(@team, user)) do |f|  
17 - = label_tag :group_admin do  
18 - = f.check_box :group_admin, class: 'trigger-submit'  
19 - %span Admin access  
20 - &nbsp;  
21 - = f.select :permission, options_for_select(UsersProject.access_roles, @team.default_projects_access(user)), {}, class: "span2 trigger-submit"  
22 - .pull-right  
23 - - if current_user == user  
24 - %span.label.label-success This is you!  
25 - - if @team.owner == user  
26 - %span.label.label-info Owner  
27 - - elsif user.blocked?  
28 - %span.label.label-error Blocked  
29 - - elsif allow_admin  
30 - = link_to team_member_path(@team, user), confirm: remove_from_user_team_message(@team, user), method: :delete, class: "btn-tiny btn btn-remove", title: "Remove from team" do  
31 - %i.icon-minus.icon-white  
app/views/teams/members/_team.html.haml
@@ -1,10 +0,0 @@ @@ -1,10 +0,0 @@
1 -- grouped_user_team_members(team).each do |access, members|  
2 - - access_key = Project.access_options.key(access)  
3 - - next if params[:type].present? && params[:type] != access_key.tableize  
4 - .ui-box  
5 - %h5.title  
6 - = access_key.pluralize  
7 - %small= members.size  
8 - %ul.well-list.team-members  
9 - - members.sort_by(&:user_name).each do |member|  
10 - = render 'teams/members/member', member: member  
app/views/teams/members/edit.html.haml
@@ -1,16 +0,0 @@ @@ -1,16 +0,0 @@
1 -%h3.page_title  
2 - Edit access #{@member.name} in #{@team.name} team  
3 -  
4 -%hr  
5 -%table.zebra-striped  
6 - %tr  
7 - %td User:  
8 - %td= @member.name  
9 - %tr  
10 - %td Team:  
11 - %td= @team.name  
12 - %tr  
13 - %td Since:  
14 - %td= member_since(@team, @member).stamp("Nov 11, 2010")  
15 -  
16 -= render 'form'  
app/views/teams/members/index.html.haml
@@ -1,37 +0,0 @@ @@ -1,37 +0,0 @@
1 -%h3.page_title  
2 - Team Members  
3 - (#{@members.count})  
4 - %small  
5 - Read more about project permissions  
6 - %strong= link_to "here", help_permissions_path, class: "vlink"  
7 -  
8 - - if can? current_user, :manage_user_team, @team  
9 - %span.pull-right  
10 - = link_to new_team_member_path(@team), class: "btn btn-primary small grouped", title: "New Team Member" do  
11 - New Team Member  
12 -%hr  
13 -  
14 -  
15 -.row  
16 - .span3  
17 - %ul.nav.nav-pills.nav-stacked  
18 - %li{class: ("active" if !params[:type])}  
19 - = link_to team_members_path(@team, type: nil) do  
20 - All  
21 - %li{class: ("active" if params[:type] == 'masters')}  
22 - = link_to team_members_path(@team, type: 'masters') do  
23 - Masters  
24 - %li{class: ("active" if params[:type] == 'developers')}  
25 - = link_to team_members_path(@team, type: 'developers') do  
26 - Developers  
27 - %li{class: ("active" if params[:type] == 'reporters')}  
28 - = link_to team_members_path(@team, type: 'reporters') do  
29 - Reporters  
30 - %li{class: ("active" if params[:type] == 'guests')}  
31 - = link_to team_members_path(@team, type: 'guests') do  
32 - Guests  
33 -  
34 - .span9  
35 - .clearfix  
36 - %div.team-table  
37 - = render "teams/members/team", team: @team  
app/views/teams/members/new.html.haml
@@ -1,25 +0,0 @@ @@ -1,25 +0,0 @@
1 -%h3.page_title  
2 - Team: #{@team.name}  
3 -  
4 -%hr  
5 -  
6 -= form_tag team_members_path(@team), id: "team_members", class: "bulk_import", method: :post do  
7 - %h6 1. Choose people you want in the team  
8 - .clearfix  
9 - = label_tag :user_ids, "People"  
10 - .input  
11 - = users_select_tag(:user_ids, multiple: true)  
12 -  
13 - %h6 2. Set access level for them  
14 - .clearfix  
15 - = label_tag :project_access, "Project Access"  
16 - .input= select_tag :default_project_access, options_for_select(Project.access_options), class: "project-access-select chosen"  
17 -  
18 - .clearfix  
19 - = label_tag :group_admin do  
20 - %span Team Admin?  
21 - .input= check_box_tag :group_admin  
22 -  
23 - .actions  
24 - = submit_tag 'Add users', class: "btn btn-create", id: :add_members_to_team  
25 - = link_to "Cancel", team_members_path(@team), class: "btn btn-cancel"  
app/views/teams/merge_requests.html.haml
@@ -1,24 +0,0 @@ @@ -1,24 +0,0 @@
1 -%h3.page_title  
2 - Merge Requests  
3 - %small (authored by or assigned to Team members)  
4 - %small.pull-right #{@merge_requests.total_count} merge requests  
5 -  
6 -%hr  
7 -.row  
8 - .span3  
9 - = render 'filter', entity: 'merge_request'  
10 - .span9  
11 - - if @merge_requests.any?  
12 - - @merge_requests.group_by(&:project).each do |group|  
13 - .ui-box  
14 - - @project = group[0]  
15 - %h5.title  
16 - = link_to_project @project  
17 - %ul.well-list  
18 - - group[1].each do |merge_request|  
19 - = render(partial: 'merge_requests/merge_request', locals: {merge_request: merge_request})  
20 - %hr  
21 - = paginate @merge_requests, theme: "gitlab"  
22 -  
23 - - else  
24 - %h3.nothing_here_message Nothing to show here  
app/views/teams/new.html.haml
@@ -1,37 +0,0 @@ @@ -1,37 +0,0 @@
1 -= form_for @team, url: teams_path do |f|  
2 - - if @team.errors.any?  
3 - .alert.alert-error  
4 - %span= @team.errors.full_messages.first  
5 - .clearfix  
6 - = f.label :name do  
7 - Team name is  
8 - .input  
9 - = f.text_field :name, placeholder: "Ex. Ruby Developers", class: "xxlarge left"  
10 -  
11 - .clearfix.team-description-holder  
12 - = f.label :description, "Details"  
13 - .input  
14 - = f.text_area :description, maxlength: 250, class: "xxlarge js-gfm-input", rows: 4  
15 -  
16 -  
17 - .clearfix  
18 - .input  
19 - %ul  
20 - %li All created teams are public (users can view who enter into team and which project are assigned for this team)  
21 - %li People within a team see only projects they have access to  
22 - %li You will be able to assign existing projects for team  
23 - .form-actions  
24 - = f.submit 'Create team', class: "btn btn-create"  
25 -  
26 - - if current_user.can_create_group?  
27 - .clearfix  
28 - .input.light  
29 - Need a group for several dependent projects?  
30 - = link_to new_group_path, class: "btn btn-tiny" do  
31 - Create a group  
32 - - if current_user.can_create_project?  
33 - .clearfix  
34 - .input.light  
35 - Want to create a project?  
36 - = link_to new_project_path, class: "btn btn-tiny" do  
37 - Create a project  
app/views/teams/projects/_form.html.haml
@@ -1,16 +0,0 @@ @@ -1,16 +0,0 @@
1 -= form_tag team_project_path(@team, @project), method: :put do  
2 - -if @project.errors.any?  
3 - .alert.alert-error  
4 - %ul  
5 - - @project.errors.full_messages.each do |msg|  
6 - %li= msg  
7 -  
8 - .clearfix  
9 - %label Max access for Team members:  
10 - .input  
11 - = select_tag :greatest_project_access, options_for_select(UserTeam.access_roles, @team.max_project_access(@project)), class: "project-access-select chosen span3"  
12 -  
13 - %br  
14 - .actions  
15 - = submit_tag 'Save', class: "btn btn-save"  
16 - = link_to 'Cancel', :back, class: "btn btn-cancel"  
app/views/teams/projects/edit.html.haml
@@ -1,6 +0,0 @@ @@ -1,6 +0,0 @@
1 -%h3.page_title  
2 - Edit max access in #{link_to @project.name_with_namespace, @project} for #{link_to(@team.name, team_path(@team))} team  
3 -  
4 -%hr  
5 -  
6 -= render 'form'  
app/views/teams/show.atom.builder
@@ -1,28 +0,0 @@ @@ -1,28 +0,0 @@
1 -xml.instruct!  
2 -xml.feed "xmlns" => "http://www.w3.org/2005/Atom", "xmlns:media" => "http://search.yahoo.com/mrss/" do  
3 - xml.title "Team feed - #{@team.name}"  
4 - xml.link :href => team_url(@team, :atom), :rel => "self", :type => "application/atom+xml"  
5 - xml.link :href => team_url(@team), :rel => "alternate", :type => "text/html"  
6 - xml.id projects_url  
7 - xml.updated @events.maximum(:updated_at).strftime("%Y-%m-%dT%H:%M:%SZ") if @events.any?  
8 -  
9 - @events.each do |event|  
10 - if event.proper?  
11 - xml.entry do  
12 - event_link = event_feed_url(event)  
13 - event_title = event_feed_title(event)  
14 -  
15 - xml.id "tag:#{request.host},#{event.created_at.strftime("%Y-%m-%d")}:#{event.id}"  
16 - xml.link :href => event_link  
17 - xml.title truncate(event_title, :length => 80)  
18 - xml.updated event.created_at.strftime("%Y-%m-%dT%H:%M:%SZ")  
19 - xml.media :thumbnail, :width => "40", :height => "40", :url => gravatar_icon(event.author_email)  
20 - xml.author do |author|  
21 - xml.name event.author_name  
22 - xml.email event.author_email  
23 - end  
24 - xml.summary event_title  
25 - end  
26 - end  
27 - end  
28 -end  
app/views/teams/show.html.haml
@@ -1,25 +0,0 @@ @@ -1,25 +0,0 @@
1 -.dashboard  
2 - .activities.span8  
3 - = link_to dashboard_path, class: 'btn btn-tiny' do  
4 - &larr; To dashboard  
5 - &nbsp;  
6 - %span.cgray Events and projects are filtered in scope of team  
7 - %hr  
8 - - if @events.any?  
9 - .content_list  
10 - - else  
11 - %p.nothing_here_message Projects activity will be displayed here  
12 - .loading.hide  
13 - .side.span4  
14 - - if @team.description.present?  
15 - .description-block  
16 - = @team.description  
17 - = render "projects", projects: @projects  
18 - .prepend-top-20  
19 - = link_to team_path(@team, { format: :atom, private_token: current_user.private_token }), title: "Feed" do  
20 - %strong  
21 - %i.icon-rss  
22 - News Feed  
23 -  
24 - %hr  
25 - = render 'shared/promo'  
app/views/teams/show.js.haml
@@ -1,2 +0,0 @@ @@ -1,2 +0,0 @@
1 -:plain  
2 - Pager.append(#{@events.count}, "#{escape_javascript(render(@events))}");  
config/routes.rb
@@ -155,20 +155,6 @@ Gitlab::Application.routes.draw do @@ -155,20 +155,6 @@ Gitlab::Application.routes.draw do
155 resources :users_groups, only: [:create, :update, :destroy] 155 resources :users_groups, only: [:create, :update, :destroy]
156 end 156 end
157 157
158 - #  
159 - # Teams Area  
160 - #  
161 - resources :teams, constraints: {id: /(?:[^.]|\.(?!atom$))+/, format: /atom/} do  
162 - member do  
163 - get :issues  
164 - get :merge_requests  
165 - end  
166 - scope module: :teams do  
167 - resources :members, only: [:index, :new, :create, :edit, :update, :destroy]  
168 - resources :projects, only: [:index, :new, :create, :edit, :update, :destroy], constraints: { id: /[a-zA-Z.0-9_\-\/]+/ }  
169 - end  
170 - end  
171 -  
172 resources :projects, constraints: { id: /[^\/]+/ }, only: [:new, :create] 158 resources :projects, constraints: { id: /[^\/]+/ }, only: [:new, :create]
173 159
174 devise_for :users, controllers: { omniauth_callbacks: :omniauth_callbacks, registrations: :registrations } 160 devise_for :users, controllers: { omniauth_callbacks: :omniauth_callbacks, registrations: :registrations }
@@ -307,18 +293,6 @@ Gitlab::Application.routes.draw do @@ -307,18 +293,6 @@ Gitlab::Application.routes.draw do
307 end 293 end
308 end 294 end
309 295
310 - scope module: :projects do  
311 - resources :teams, only: [] do  
312 - collection do  
313 - get :available  
314 - post :assign  
315 - end  
316 - member do  
317 - delete :resign  
318 - end  
319 - end  
320 - end  
321 -  
322 resources :notes, only: [:index, :create, :destroy] do 296 resources :notes, only: [:index, :create, :destroy] do
323 collection do 297 collection do
324 post :preview 298 post :preview
features/steps/userteams/userteams.rb
@@ -1,241 +0,0 @@ @@ -1,241 +0,0 @@
1 -class Userteams < Spinach::FeatureSteps  
2 - include SharedAuthentication  
3 - include SharedPaths  
4 - include SharedProject  
5 - include Select2Helper  
6 -  
7 - When 'I do not have teams with me' do  
8 - UserTeam.with_member(current_user).destroy_all  
9 - end  
10 -  
11 - Then 'I should see dashboard page without teams info block' do  
12 - page.has_no_css?(".teams-box").must_equal true  
13 - end  
14 -  
15 - When 'I have teams with my membership' do  
16 - team = create :user_team, owner: current_user  
17 - team.add_member(current_user, UserTeam.access_roles["Master"], true)  
18 - end  
19 -  
20 - Then 'I should see dashboard page with teams information block' do  
21 - page.should have_css(".teams-box")  
22 - end  
23 -  
24 - When 'exist user teams' do  
25 - team = create :user_team  
26 - team.add_member(current_user, UserTeam.access_roles["Master"], true)  
27 - end  
28 -  
29 - And 'I click on "All teams" link' do  
30 - click_link("All Teams")  
31 - end  
32 -  
33 - Then 'I should see "All teams" page' do  
34 - current_path.should == teams_path  
35 - end  
36 -  
37 - And 'I should see exist teams in teams list' do  
38 - team = UserTeam.last  
39 - find_in_list(".teams_list tr", team).must_equal true  
40 - end  
41 -  
42 - When 'I click to "New team" link' do  
43 - click_link("New Team")  
44 - end  
45 -  
46 - And 'I submit form with new team info' do  
47 - fill_in 'name', with: 'gitlab'  
48 -  
49 - fill_in 'user_team_description', with: 'team description'  
50 - click_button 'Create team'  
51 - end  
52 -  
53 - And 'I should see newly created team' do  
54 - page.should have_content "gitlab"  
55 - page.should have_content "team description"  
56 - end  
57 -  
58 - Then 'I should be redirected to new team page' do  
59 - team = UserTeam.last  
60 - current_path.should == team_path(team)  
61 - end  
62 -  
63 - When 'I have teams with projects and members' do  
64 - team = create :user_team, owner: current_user  
65 - @project = create :project  
66 - team.add_member(current_user, UserTeam.access_roles["Master"], true)  
67 - team.assign_to_project(@project, UserTeam.access_roles["Master"])  
68 - @event = create(:closed_issue_event, project: @project)  
69 - end  
70 -  
71 - When 'I visit team page' do  
72 - visit team_path(UserTeam.last)  
73 - end  
74 -  
75 - Then 'I should see projects list' do  
76 - within(".side .ui-box") do  
77 - page.should have_content(@project.name)  
78 - end  
79 - end  
80 -  
81 - And 'project from team has issues assigned to me' do  
82 - team = UserTeam.last  
83 - team.projects.each do |project|  
84 - project.issues << create(:issue, assignee: current_user)  
85 - end  
86 - end  
87 -  
88 - When 'I visit team issues page' do  
89 - team = UserTeam.last  
90 - visit issues_team_path(team)  
91 - end  
92 -  
93 - Then 'I should see issues from this team assigned to me' do  
94 - team = UserTeam.last  
95 - team.projects.each do |project|  
96 - project.issues.assigned_to(current_user).each do |issue|  
97 - page.should have_content issue.title  
98 - end  
99 - end  
100 - end  
101 -  
102 - Given 'I have team with projects and members' do  
103 - team = create :user_team, owner: current_user  
104 - project = create :project  
105 - user = create :user  
106 - team.add_member(current_user, UserTeam.access_roles["Master"], true)  
107 - team.add_member(user, UserTeam.access_roles["Developer"], false)  
108 - team.assign_to_project(project, UserTeam.access_roles["Master"])  
109 - end  
110 -  
111 - Given 'project from team has issues assigned to teams members' do  
112 - team = UserTeam.last  
113 - team.projects.each do |project|  
114 - team.members.each do |member|  
115 - project.issues << create(:issue, assignee: member)  
116 - end  
117 - end  
118 - end  
119 -  
120 - Then 'I should see issues from this team assigned to teams members' do  
121 - team = UserTeam.last  
122 - team.projects.each do |project|  
123 - team.members.each do |member|  
124 - project.issues.assigned_to(member).each do |issue|  
125 - page.should have_content issue.title  
126 - end  
127 - end  
128 - end  
129 - end  
130 -  
131 - Given 'project from team has merge requests assigned to me' do  
132 - team = UserTeam.last  
133 - team.projects.each do |project|  
134 - create(:merge_request, assignee: current_user, project: project)  
135 - end  
136 - end  
137 -  
138 - When 'I visit team merge requests page' do  
139 - team = UserTeam.last  
140 - visit merge_requests_team_path(team)  
141 - end  
142 -  
143 - Then 'I should see merge requests from this team assigned to me' do  
144 - team = UserTeam.last  
145 - team.projects.each do |project|  
146 - project.merge_requests.each do |merge_request|  
147 - page.should have_content merge_request.title  
148 - end  
149 - end  
150 - end  
151 -  
152 - Given 'project from team has merge requests assigned to team members' do  
153 - team = UserTeam.last  
154 - team.projects.each do |project|  
155 - member = team.members.sample  
156 - create(:merge_request, assignee: member, project: project)  
157 - end  
158 - end  
159 -  
160 - Given 'I have new user "John"' do  
161 - create :user, name: "John"  
162 - end  
163 -  
164 - When 'I visit team people page' do  
165 - team = UserTeam.last  
166 - visit team_members_path(team)  
167 - end  
168 -  
169 - And 'I select user "John" from list with role "Reporter"' do  
170 - user = User.find_by_name("John")  
171 - select2(user.id, from: "#user_ids", multiple: true)  
172 - within "#team_members" do  
173 - select "Reporter", from: "default_project_access"  
174 - end  
175 - click_button "Add"  
176 - end  
177 -  
178 - Then 'I should see user "John" in team list' do  
179 - user = User.find_by_name("John")  
180 - team_members_list = find(".team-table")  
181 - team_members_list.should have_content user.name  
182 - end  
183 -  
184 - And 'I have my own project without teams' do  
185 - @project = create :project, namespace: current_user.namespace  
186 - end  
187 -  
188 - And 'I visit my team page' do  
189 - team = UserTeam.where(owner_id: current_user.id).last  
190 - visit team_path(team)  
191 - end  
192 -  
193 - When 'I click on link "Assign Project"' do  
194 - click_link "Assign Project"  
195 - end  
196 -  
197 - Then 'I should see form with my own project in available projects list' do  
198 - projects_select = find("#project_ids")  
199 - projects_select.should have_content(@project.name)  
200 - end  
201 -  
202 - When 'I submit form with selected project and max access' do  
203 - within "#assign_projects" do  
204 - select @project.name_with_namespace, from: "project_ids"  
205 - select "Reporter", from: "greatest_project_access"  
206 - end  
207 - click_button "Add"  
208 - end  
209 -  
210 - Then 'I should see my own project in team projects list' do  
211 - projects = find(".projects-table")  
212 - projects.should have_content(@project.name)  
213 - end  
214 -  
215 - When 'I click link "New Team Member"' do  
216 - click_link "New Team Member"  
217 - end  
218 -  
219 - protected  
220 -  
221 - def current_team  
222 - @user_team ||= UserTeam.first  
223 - end  
224 -  
225 - def project  
226 - current_team.projects.first  
227 - end  
228 -  
229 - def assigned_to_user key, user  
230 - project.send(key).where(assignee_id: user)  
231 - end  
232 -  
233 - def find_in_list(selector, item)  
234 - members_list = all(selector)  
235 - entered = false  
236 - members_list.each do |member_item|  
237 - entered = true if member_item.has_content?(item.name)  
238 - end  
239 - entered  
240 - end  
241 -end  
features/teams/team.feature
@@ -1,65 +0,0 @@ @@ -1,65 +0,0 @@
1 -Feature: UserTeams  
2 - Background:  
3 - Given I sign in as a user  
4 - And I own project "Shop"  
5 - And project "Shop" has push event  
6 -  
7 - Scenario: I should see teams info block  
8 - When I have teams with my membership  
9 - And I visit dashboard page  
10 - Then I should see dashboard page with teams information block  
11 -  
12 - Scenario: I should can create new team  
13 - When I have teams with my membership  
14 - And I visit dashboard page  
15 - When I click to "New team" link  
16 - And I submit form with new team info  
17 - Then I should be redirected to new team page  
18 - Then I should see newly created team  
19 -  
20 - Scenario: I should see team dashboard list  
21 - When I have teams with projects and members  
22 - When I visit team page  
23 - Then I should see projects list  
24 -  
25 - Scenario: I should see team issues list  
26 - Given I have team with projects and members  
27 - And project from team has issues assigned to me  
28 - When I visit team issues page  
29 - Then I should see issues from this team assigned to me  
30 -  
31 - Scenario: I should see teams members issues list  
32 - Given I have team with projects and members  
33 - Given project from team has issues assigned to teams members  
34 - When I visit team issues page  
35 - Then I should see issues from this team assigned to teams members  
36 -  
37 - Scenario: I should see team merge requests list  
38 - Given I have team with projects and members  
39 - Given project from team has merge requests assigned to me  
40 - When I visit team merge requests page  
41 - Then I should see merge requests from this team assigned to me  
42 -  
43 - Scenario: I should see teams members merge requests list  
44 - Given I have team with projects and members  
45 - Given project from team has merge requests assigned to team members  
46 - When I visit team merge requests page  
47 - Then I should see merge requests from this team assigned to me  
48 -  
49 - @javascript  
50 - Scenario: I should add user to projects in Team  
51 - Given I have team with projects and members  
52 - Given I have new user "John"  
53 - When I visit team people page  
54 - When I click link "New Team Member"  
55 - And I select user "John" from list with role "Reporter"  
56 - Then I should see user "John" in team list  
57 -  
58 - Scenario: I should assign my team to my own project  
59 - Given I have team with projects and members  
60 - And I have my own project without teams  
61 - And I visit my team page  
62 - When I click on link "Assign Project"  
63 - Then I should see form with my own project in available projects list  
64 - When I submit form with selected project and max access  
65 - Then I should see my own project in team projects list  
lib/api/api.rb
@@ -35,7 +35,6 @@ module API @@ -35,7 +35,6 @@ module API
35 mount Notes 35 mount Notes
36 mount Internal 36 mount Internal
37 mount SystemHooks 37 mount SystemHooks
38 - mount UserTeams  
39 mount ProjectSnippets 38 mount ProjectSnippets
40 mount DeployKeys 39 mount DeployKeys
41 mount ProjectHooks 40 mount ProjectHooks
lib/api/entities.rb
@@ -99,10 +99,6 @@ module API @@ -99,10 +99,6 @@ module API
99 expose :id, :title, :key, :created_at 99 expose :id, :title, :key, :created_at
100 end 100 end
101 101
102 - class UserTeam < Grape::Entity  
103 - expose :id, :name, :path, :owner_id  
104 - end  
105 -  
106 class MergeRequest < Grape::Entity 102 class MergeRequest < Grape::Entity
107 expose :id, :target_branch, :source_branch, :project_id, :title, :state 103 expose :id, :target_branch, :source_branch, :project_id, :title, :state
108 expose :author, :assignee, using: Entities::UserBasic 104 expose :author, :assignee, using: Entities::UserBasic
lib/api/user_teams.rb
@@ -1,276 +0,0 @@ @@ -1,276 +0,0 @@
1 -module API  
2 - # user_teams API  
3 - class UserTeams < Grape::API  
4 - before { authenticate! }  
5 -  
6 - resource :user_teams do  
7 - helpers do  
8 - def handle_team_member_errors(errors)  
9 - if errors[:permission].any?  
10 - render_api_error!(errors[:permission], 422)  
11 - end  
12 - not_found!  
13 - end  
14 -  
15 - def validate_access_level?(level)  
16 - [UsersProject::GUEST, UsersProject::REPORTER, UsersProject::DEVELOPER, UsersProject::MASTER].include? level.to_i  
17 - end  
18 - end  
19 -  
20 -  
21 - # Get a user_teams list  
22 - #  
23 - # Example Request:  
24 - # GET /user_teams  
25 - get do  
26 - if current_user.admin  
27 - @user_teams = paginate UserTeam  
28 - else  
29 - @user_teams = paginate current_user.user_teams  
30 - end  
31 - present @user_teams, with: Entities::UserTeam  
32 - end  
33 -  
34 -  
35 - # Create user_team. Available only for admin  
36 - #  
37 - # Parameters:  
38 - # name (required) - The name of the user_team  
39 - # path (required) - The path of the user_team  
40 - # Example Request:  
41 - # POST /user_teams  
42 - post do  
43 - authenticated_as_admin!  
44 - required_attributes! [:name, :path]  
45 -  
46 - attrs = attributes_for_keys [:name, :path]  
47 - @user_team = UserTeam.new(attrs)  
48 - @user_team.owner = current_user  
49 -  
50 - if @user_team.save  
51 - present @user_team, with: Entities::UserTeam  
52 - else  
53 - not_found!  
54 - end  
55 - end  
56 -  
57 -  
58 - # Get a single user_team  
59 - #  
60 - # Parameters:  
61 - # id (required) - The ID of a user_team  
62 - # Example Request:  
63 - # GET /user_teams/:id  
64 - get ":id" do  
65 - @user_team = UserTeam.find(params[:id])  
66 - if current_user.admin or current_user.user_teams.include? @user_team  
67 - present @user_team, with: Entities::UserTeam  
68 - else  
69 - not_found!  
70 - end  
71 - end  
72 -  
73 -  
74 - # Get user_team members  
75 - #  
76 - # Parameters:  
77 - # id (required) - The ID of a user_team  
78 - # Example Request:  
79 - # GET /user_teams/:id/members  
80 - get ":id/members" do  
81 - @user_team = UserTeam.find(params[:id])  
82 - if current_user.admin or current_user.user_teams.include? @user_team  
83 - @members = paginate @user_team.members  
84 - present @members, with: Entities::TeamMember, user_team: @user_team  
85 - else  
86 - not_found!  
87 - end  
88 - end  
89 -  
90 -  
91 - # Add a new user_team member  
92 - #  
93 - # Parameters:  
94 - # id (required) - The ID of a user_team  
95 - # user_id (required) - The ID of a user  
96 - # access_level (required) - Project access level  
97 - # Example Request:  
98 - # POST /user_teams/:id/members  
99 - post ":id/members" do  
100 - authenticated_as_admin!  
101 - required_attributes! [:user_id, :access_level]  
102 -  
103 - if not validate_access_level?(params[:access_level])  
104 - render_api_error!("Wrong access level", 422)  
105 - end  
106 -  
107 - @user_team = UserTeam.find(params[:id])  
108 - if @user_team  
109 - team_member = @user_team.user_team_user_relationships.find_by_user_id(params[:user_id])  
110 - # Not existing member  
111 - if team_member.nil?  
112 - @user_team.add_member(params[:user_id], params[:access_level], false)  
113 - team_member = @user_team.user_team_user_relationships.find_by_user_id(params[:user_id])  
114 -  
115 - if team_member.nil?  
116 - render_api_error!("Error creating membership", 500)  
117 - else  
118 - @member = team_member.user  
119 - present @member, with: Entities::TeamMember, user_team: @user_team  
120 - end  
121 - else  
122 - render_api_error!("Already exists", 409)  
123 - end  
124 - else  
125 - not_found!  
126 - end  
127 - end  
128 -  
129 -  
130 - # Get a single team member from user_team  
131 - #  
132 - # Parameters:  
133 - # id (required) - The ID of a user_team  
134 - # user_id (required) - The ID of a team member  
135 - # Example Request:  
136 - # GET /user_teams/:id/members/:user_id  
137 - get ":id/members/:user_id" do  
138 - @user_team = UserTeam.find(params[:id])  
139 - if current_user.admin or current_user.user_teams.include? @user_team  
140 - team_member = @user_team.user_team_user_relationships.find_by_user_id(params[:user_id])  
141 - unless team_member.nil?  
142 - present team_member.user, with: Entities::TeamMember, user_team: @user_team  
143 - else  
144 - not_found!  
145 - end  
146 - else  
147 - not_found!  
148 - end  
149 - end  
150 -  
151 - # Remove a team member from user_team  
152 - #  
153 - # Parameters:  
154 - # id (required) - The ID of a user_team  
155 - # user_id (required) - The ID of a team member  
156 - # Example Request:  
157 - # DELETE /user_teams/:id/members/:user_id  
158 - delete ":id/members/:user_id" do  
159 - authenticated_as_admin!  
160 -  
161 - @user_team = UserTeam.find(params[:id])  
162 - if @user_team  
163 - team_member = @user_team.user_team_user_relationships.find_by_user_id(params[:user_id])  
164 - unless team_member.nil?  
165 - team_member.destroy  
166 - else  
167 - not_found!  
168 - end  
169 - else  
170 - not_found!  
171 - end  
172 - end  
173 -  
174 -  
175 - # Get to user_team assigned projects  
176 - #  
177 - # Parameters:  
178 - # id (required) - The ID of a user_team  
179 - # Example Request:  
180 - # GET /user_teams/:id/projects  
181 - get ":id/projects" do  
182 - @user_team = UserTeam.find(params[:id])  
183 - if current_user.admin or current_user.user_teams.include? @user_team  
184 - @projects = paginate @user_team.projects  
185 - present @projects, with: Entities::TeamProject, user_team: @user_team  
186 - else  
187 - not_found!  
188 - end  
189 - end  
190 -  
191 -  
192 - # Add a new user_team project  
193 - #  
194 - # Parameters:  
195 - # id (required) - The ID of a user_team  
196 - # project_id (required) - The ID of a project  
197 - # greatest_access_level (required) - Project access level  
198 - # Example Request:  
199 - # POST /user_teams/:id/projects  
200 - post ":id/projects" do  
201 - authenticated_as_admin!  
202 - required_attributes! [:project_id, :greatest_access_level]  
203 -  
204 - if not validate_access_level?(params[:greatest_access_level])  
205 - render_api_error!("Wrong greatest_access_level", 422)  
206 - end  
207 -  
208 - @user_team = UserTeam.find(params[:id])  
209 - if @user_team  
210 - team_project = @user_team.user_team_project_relationships.find_by_project_id(params[:project_id])  
211 -  
212 - # No existing project  
213 - if team_project.nil?  
214 - @user_team.assign_to_projects([params[:project_id]], params[:greatest_access_level])  
215 - team_project = @user_team.user_team_project_relationships.find_by_project_id(params[:project_id])  
216 - if team_project.nil?  
217 - render_api_error!("Error creating project assignment", 500)  
218 - else  
219 - @project = team_project.project  
220 - present @project, with: Entities::TeamProject, user_team: @user_team  
221 - end  
222 - else  
223 - render_api_error!("Already exists", 409)  
224 - end  
225 - else  
226 - not_found!  
227 - end  
228 - end  
229 -  
230 - # Show a single team project from user_team  
231 - #  
232 - # Parameters:  
233 - # id (required) - The ID of a user_team  
234 - # project_id (required) - The ID of a project assigned to the team  
235 - # Example Request:  
236 - # GET /user_teams/:id/projects/:project_id  
237 - get ":id/projects/:project_id" do  
238 - @user_team = UserTeam.find(params[:id])  
239 - if current_user.admin or current_user.user_teams.include? @user_team  
240 - team_project = @user_team.user_team_project_relationships.find_by_project_id(params[:project_id])  
241 - unless team_project.nil?  
242 - present team_project.project, with: Entities::TeamProject, user_team: @user_team  
243 - else  
244 - not_found!  
245 - end  
246 - else  
247 - not_found!  
248 - end  
249 - end  
250 -  
251 - # Remove a team project from user_team  
252 - #  
253 - # Parameters:  
254 - # id (required) - The ID of a user_team  
255 - # project_id (required) - The ID of a project assigned to the team  
256 - # Example Request:  
257 - # DELETE /user_teams/:id/projects/:project_id  
258 - delete ":id/projects/:project_id" do  
259 - authenticated_as_admin!  
260 -  
261 - @user_team = UserTeam.find(params[:id])  
262 - if @user_team  
263 - team_project = @user_team.user_team_project_relationships.find_by_project_id(params[:project_id])  
264 - unless team_project.nil?  
265 - team_project.destroy  
266 - else  
267 - not_found!  
268 - end  
269 - else  
270 - not_found!  
271 - end  
272 - end  
273 -  
274 - end  
275 - end  
276 -end  
lib/gitlab/user_team_manager.rb
@@ -1,146 +0,0 @@ @@ -1,146 +0,0 @@
1 -# UserTeamManager class  
2 -#  
3 -# Used for manage User teams with project repositories  
4 -module Gitlab  
5 - class UserTeamManager  
6 - class << self  
7 - def assign(team, project, access)  
8 - project = Project.find(project) unless project.is_a? Project  
9 - searched_project = team.user_team_project_relationships.find_by_project_id(project.id)  
10 -  
11 - unless searched_project.present?  
12 - team.user_team_project_relationships.create(project_id: project.id, greatest_access: access)  
13 - update_team_users_access_in_project(team, project, :added)  
14 - end  
15 - end  
16 -  
17 - def resign(team, project)  
18 - project = Project.find(project) unless project.is_a? Project  
19 -  
20 - team.user_team_project_relationships.with_project(project).destroy_all  
21 -  
22 - update_team_users_access_in_project(team, project, :updated)  
23 - end  
24 -  
25 - def update_team_user_membership(team, member, options)  
26 - updates = {}  
27 -  
28 - if options[:default_projects_access].present?  
29 - default_projects_access = options[:default_projects_access].to_s  
30 -  
31 - if default_projects_access != team.default_projects_access(member).to_s  
32 - updates[:permission] = default_projects_access  
33 - end  
34 - end  
35 -  
36 - if options[:group_admin].present?  
37 - group_admin = options[:group_admin].to_s == "1" ? true : false  
38 -  
39 - if group_admin != team.admin?(member)  
40 - updates[:group_admin] = group_admin  
41 - end  
42 - end  
43 -  
44 - return true if updates.blank?  
45 -  
46 - user_team_relationship = team.user_team_user_relationships.find_by_user_id(member)  
47 - return false unless user_team_relationship.update_attributes(updates)  
48 -  
49 - rebuild_project_permissions_to_member(team, member) if updates[:permission]  
50 -  
51 - true  
52 - end  
53 -  
54 - def update_project_greates_access(team, project, permission)  
55 - project_relation = team.user_team_project_relationships.find_by_project_id(project)  
56 - if permission != team.max_project_access(project)  
57 - if project_relation.update_attributes(greatest_access: permission)  
58 - update_team_users_access_in_project(team, project, :updated)  
59 - true  
60 - else  
61 - false  
62 - end  
63 - else  
64 - true  
65 - end  
66 - end  
67 -  
68 - def rebuild_project_permissions_to_member(team, member)  
69 - team.projects.each do |project|  
70 - update_team_user_access_in_project(team, member, project, :updated)  
71 - end  
72 - end  
73 -  
74 - def update_team_users_access_in_project(team, project, action)  
75 - members = team.members  
76 - members.each do |member|  
77 - update_team_user_access_in_project(team, member, project, action)  
78 - end  
79 - end  
80 -  
81 - def update_team_user_access_in_project(team, user, project, action)  
82 - granted_access = max_teams_member_permission_in_project(user, project, action)  
83 - project_team_user = UsersProject.find_by_user_id_and_project_id(user.id, project.id)  
84 -  
85 - if granted_access.zero?  
86 - project_team_user.destroy if project_team_user.present?  
87 - return  
88 - end  
89 -  
90 - if project_team_user.present?  
91 - project_team_user.update_attributes(project_access: granted_access)  
92 - else  
93 - project.team << [user, granted_access]  
94 - end  
95 - end  
96 -  
97 - def max_teams_member_permission_in_project(user, project, action = nil, teams = nil)  
98 - result_access = 0  
99 -  
100 - teams ||= project.user_teams.with_member(user)  
101 -  
102 - if action && (action == :added)  
103 - result_access = project.users_projects.with_user(user).first.project_access if project.users_projects.with_user(user).any?  
104 - end  
105 -  
106 - if teams.any?  
107 - teams.each do |team|  
108 - granted_access = max_team_member_permission_in_project(team, user, project)  
109 - result_access = [granted_access, result_access].max  
110 - end  
111 - end  
112 - result_access  
113 - end  
114 -  
115 - def max_team_member_permission_in_project(team, user, project)  
116 - member_access = team.default_projects_access(user)  
117 - team_access = team.user_team_project_relationships.find_by_project_id(project.id).greatest_access  
118 -  
119 - [team_access, member_access].min  
120 - end  
121 -  
122 - def add_member_into_team(team, user, access, admin)  
123 - user = User.find(user) unless user.is_a? User  
124 -  
125 - team.user_team_user_relationships.create(user_id: user.id, permission: access, group_admin: admin)  
126 - team.projects.each do |project|  
127 - update_team_user_access_in_project(team, user, project, :added)  
128 - end  
129 - end  
130 -  
131 - def remove_member_from_team(team, user)  
132 - user = User.find(user) unless user.is_a? User  
133 -  
134 - team.user_team_user_relationships.with_user(user).destroy_all  
135 - other_teams = []  
136 - team.projects.each do |project|  
137 - other_teams << project.user_teams.with_member(user)  
138 - end  
139 - other_teams.uniq  
140 - unless other_teams.any?  
141 - UsersProject.in_projects(team.projects).with_user(user).destroy_all  
142 - end  
143 - end  
144 - end  
145 - end  
146 -end  
spec/models/user_team_project_relationship_spec.rb
@@ -1,17 +0,0 @@ @@ -1,17 +0,0 @@
1 -# == Schema Information  
2 -#  
3 -# Table name: user_team_project_relationships  
4 -#  
5 -# id :integer not null, primary key  
6 -# project_id :integer  
7 -# user_team_id :integer  
8 -# greatest_access :integer  
9 -# created_at :datetime not null  
10 -# updated_at :datetime not null  
11 -#  
12 -  
13 -require 'spec_helper'  
14 -  
15 -describe UserTeamProjectRelationship do  
16 - pending "add some examples to (or delete) #{__FILE__}"  
17 -end  
spec/models/user_team_spec.rb
@@ -1,37 +0,0 @@ @@ -1,37 +0,0 @@
1 -# == Schema Information  
2 -#  
3 -# Table name: user_teams  
4 -#  
5 -# id :integer not null, primary key  
6 -# name :string(255)  
7 -# path :string(255)  
8 -# owner_id :integer  
9 -# created_at :datetime not null  
10 -# updated_at :datetime not null  
11 -# description :string(255) default(""), not null  
12 -#  
13 -  
14 -require 'spec_helper'  
15 -  
16 -describe UserTeam do  
17 - let(:team) { FactoryGirl.create :user_team }  
18 -  
19 - context ".add_member" do  
20 - let(:user) { FactoryGirl.create :user }  
21 -  
22 - it "should work" do  
23 - team.add_member(user, UsersProject::DEVELOPER, false)  
24 - team.members.should include(user)  
25 - end  
26 - end  
27 -  
28 - context ".remove_member" do  
29 - let(:user) { FactoryGirl.create :user }  
30 - before { team.add_member(user, UsersProject::DEVELOPER, false) }  
31 -  
32 - it "should work" do  
33 - team.remove_member(user)  
34 - team.members.should_not include(user)  
35 - end  
36 - end  
37 -end  
spec/models/user_team_user_relationship_spec.rb
@@ -1,18 +0,0 @@ @@ -1,18 +0,0 @@
1 -# == Schema Information  
2 -#  
3 -# Table name: user_team_user_relationships  
4 -#  
5 -# id :integer not null, primary key  
6 -# user_id :integer  
7 -# user_team_id :integer  
8 -# group_admin :boolean  
9 -# permission :integer  
10 -# created_at :datetime not null  
11 -# updated_at :datetime not null  
12 -#  
13 -  
14 -require 'spec_helper'  
15 -  
16 -describe UserTeamUserRelationship do  
17 - pending "add some examples to (or delete) #{__FILE__}"  
18 -end  
spec/requests/api/user_teams_spec.rb
@@ -1,360 +0,0 @@ @@ -1,360 +0,0 @@
1 -require 'spec_helper'  
2 -  
3 -describe API::API do  
4 - include ApiHelpers  
5 -  
6 - # Create test objects  
7 - let(:user1) { create(:user) }  
8 - let(:user2) { create(:user) }  
9 - let(:admin) { create(:admin) }  
10 - let!(:group1) { create(:group, owner: user1) }  
11 - let!(:group2) { create(:group, owner: user2) }  
12 - let(:user_team1) { create(:user_team, owner: user1) }  
13 - let(:user_team2) { create(:user_team, owner: user2) }  
14 - let!(:project1) { create(:project, creator_id: admin.id) }  
15 - let!(:project2) { create(:project, creator_id: admin.id) }  
16 -  
17 -  
18 - before {  
19 - # Add members to teams  
20 - user_team1.add_member(user1, UsersProject::MASTER, false)  
21 - user_team2.add_member(user2, UsersProject::MASTER, false)  
22 -  
23 - # Add projects to teams  
24 - user_team1.assign_to_projects([project1.id], UsersProject::MASTER)  
25 - user_team2.assign_to_projects([project2.id], UsersProject::MASTER)  
26 -  
27 - }  
28 -  
29 - describe "GET /user_teams" do  
30 - context "when unauthenticated" do  
31 - it "should return authentication error" do  
32 - get api("/user_teams")  
33 - response.status.should == 401  
34 - end  
35 - end  
36 -  
37 - context "when authenticated as user" do  
38 - it "normal user: should return an array of user_teams of user1" do  
39 - get api("/user_teams", user1)  
40 - response.status.should == 200  
41 - json_response.should be_an Array  
42 - json_response.length.should == 1  
43 - json_response.first['name'].should == user_team1.name  
44 - end  
45 - end  
46 -  
47 - context "when authenticated as admin" do  
48 - it "admin: should return an array of all user_teams" do  
49 - get api("/user_teams", admin)  
50 - response.status.should == 200  
51 - json_response.should be_an Array  
52 - json_response.length.should == 2  
53 - end  
54 - end  
55 - end  
56 -  
57 - describe "GET /user_teams/:id" do  
58 - context "when authenticated as user" do  
59 - it "should return one of user1's user_teams" do  
60 - get api("/user_teams/#{user_team1.id}", user1)  
61 - response.status.should == 200  
62 - json_response['name'] == user_team1.name  
63 - end  
64 -  
65 - it "should not return a non existing team" do  
66 - get api("/user_teams/1328", user1)  
67 - response.status.should == 404  
68 - end  
69 -  
70 - it "should not return a user_team not attached to user1" do  
71 - get api("/user_teams/#{user_team2.id}", user1)  
72 - response.status.should == 404  
73 - end  
74 - end  
75 -  
76 - context "when authenticated as admin" do  
77 - it "should return any existing user_team" do  
78 - get api("/user_teams/#{user_team2.id}", admin)  
79 - response.status.should == 200  
80 - json_response['name'].should == user_team2.name  
81 - end  
82 -  
83 - it "should not return a non existing user_team" do  
84 - get api("/user_teams/1328", admin)  
85 - response.status.should == 404  
86 - end  
87 - end  
88 - end  
89 -  
90 - describe "POST /user_teams" do  
91 - context "when authenticated as user" do  
92 - it "should not create user_team" do  
93 - count_before=UserTeam.count  
94 - post api("/user_teams", user1), attributes_for(:user_team)  
95 - response.status.should == 403  
96 - UserTeam.count.should == count_before  
97 - end  
98 - end  
99 -  
100 - context "when authenticated as admin" do  
101 - it "should create user_team" do  
102 - count_before=UserTeam.count  
103 - post api("/user_teams", admin), attributes_for(:user_team)  
104 - response.status.should == 201  
105 - UserTeam.count.should == count_before + 1  
106 - end  
107 -  
108 - it "should not create user_team, duplicate" do  
109 - post api("/user_teams", admin), {:name => "Duplicate Test", :path => user_team2.path}  
110 - response.status.should == 404  
111 - end  
112 -  
113 - it "should return 400 bad request error if name not given" do  
114 - post api("/user_teams", admin), {:path => user_team2.path}  
115 - response.status.should == 400  
116 - end  
117 -  
118 - it "should return 400 bad request error if path not given" do  
119 - post api("/user_teams", admin), {:name => 'test'}  
120 - response.status.should == 400  
121 - end  
122 - end  
123 - end  
124 -  
125 - # Members  
126 -  
127 - describe "GET /user_teams/:id/members" do  
128 - context "when authenticated as user" do  
129 - it "should return user1 as member of user1's user_teams" do  
130 - get api("/user_teams/#{user_team1.id}/members", user1)  
131 - response.status.should == 200  
132 - json_response.first['name'].should == user1.name  
133 - json_response.first['access_level'].should == UsersProject::MASTER  
134 - end  
135 - end  
136 -  
137 - context "when authenticated as admin" do  
138 - it "should return member of any existing user_team" do  
139 - get api("/user_teams/#{user_team2.id}/members", admin)  
140 - response.status.should == 200  
141 - json_response.first['name'].should == user2.name  
142 - json_response.first['access_level'].should == UsersProject::MASTER  
143 - end  
144 - end  
145 - end  
146 -  
147 - describe "POST /user_teams/:id/members" do  
148 - context "when authenticated as user" do  
149 - it "should not add user2 as member of user_team1" do  
150 - post api("/user_teams/#{user_team1.id}/members", user1), user_id: user2.id, access_level: UsersProject::MASTER  
151 - response.status.should == 403  
152 - end  
153 - end  
154 -  
155 - context "when authenticated as admin" do  
156 - it "should return ok and add new member" do  
157 - count_before=user_team1.user_team_user_relationships.count  
158 - post api("/user_teams/#{user_team1.id}/members", admin), user_id: user2.id, access_level: UsersProject::MASTER  
159 - response.status.should == 201  
160 - json_response['name'].should == user2.name  
161 - json_response['access_level'].should == UsersProject::MASTER  
162 - user_team1.user_team_user_relationships.count.should == count_before + 1  
163 - end  
164 - it "should return ok if member already exists" do  
165 - post api("/user_teams/#{user_team2.id}/members", admin), user_id: user2.id, access_level: UsersProject::MASTER  
166 - response.status.should == 409  
167 - end  
168 - it "should return a 400 error when user id is not given" do  
169 - post api("/user_teams/#{user_team2.id}/members", admin), access_level: UsersProject::MASTER  
170 - response.status.should == 400  
171 - end  
172 - it "should return a 400 error when access level is not given" do  
173 - post api("/user_teams/#{user_team2.id}/members", admin), user_id: user2.id  
174 - response.status.should == 400  
175 - end  
176 -  
177 - it "should return a 422 error when access level is not known" do  
178 - post api("/user_teams/#{user_team2.id}/members", admin), user_id: user1.id, access_level: 1234  
179 - response.status.should == 422  
180 - end  
181 -  
182 - end  
183 - end  
184 -  
185 - # Get single member  
186 - describe "GET /user_teams/:id/members/:user_id" do  
187 - context "when authenticated as member" do  
188 - it "should show user1's membership of user_team1" do  
189 - get api("/user_teams/#{user_team1.id}/members/#{user1.id}", user1)  
190 - response.status.should == 200  
191 - json_response['name'].should == user1.name  
192 - json_response['access_level'].should == UsersProject::MASTER  
193 - end  
194 - it "should show that user2 is not member of user_team1" do  
195 - get api("/user_teams/#{user_team1.id}/members/#{user2.id}", user1)  
196 - response.status.should == 404  
197 - end  
198 - end  
199 -  
200 - context "when authenticated as non-member" do  
201 - it "should not show user1's membership of user_team1" do  
202 - get api("/user_teams/#{user_team1.id}/members/#{user1.id}", user2)  
203 - response.status.should == 404  
204 - end  
205 - end  
206 -  
207 - context "when authenticated as admin" do  
208 - it "should show user1's membership of user_team1" do  
209 - get api("/user_teams/#{user_team1.id}/members/#{user1.id}", admin)  
210 - response.status.should == 200  
211 - json_response['name'].should == user1.name  
212 - json_response['access_level'].should == UsersProject::MASTER  
213 - end  
214 - it "should return a 404 error when user id is not known" do  
215 - get api("/user_teams/#{user_team2.id}/members/1328", admin)  
216 - response.status.should == 404  
217 - end  
218 - end  
219 - end  
220 -  
221 - describe "DELETE /user_teams/:id/members/:user_id" do  
222 - context "when authenticated as user" do  
223 - it "should not delete user1's membership of user_team1" do  
224 - delete api("/user_teams/#{user_team1.id}/members/#{user1.id}", user1)  
225 - response.status.should == 403  
226 - end  
227 - end  
228 -  
229 - context "when authenticated as admin" do  
230 - it "should delete user1's membership of user_team1" do  
231 - count_before=user_team1.user_team_user_relationships.count  
232 - delete api("/user_teams/#{user_team1.id}/members/#{user1.id}", admin)  
233 - response.status.should == 200  
234 - user_team1.user_team_user_relationships.count.should == count_before - 1  
235 - end  
236 - it "should return a 404 error when user id is not known" do  
237 - delete api("/user_teams/#{user_team2.id}/members/1328", admin)  
238 - response.status.should == 404  
239 - end  
240 - end  
241 - end  
242 -  
243 - # Projects  
244 -  
245 - describe "GET /user_teams/:id/projects" do  
246 - context "when authenticated as user" do  
247 - it "should return project1 as assigned to user_team1 as member user1" do  
248 - get api("/user_teams/#{user_team1.id}/projects", user1)  
249 - response.status.should == 200  
250 - json_response.first['name'].should == project1.name  
251 - json_response.length.should == user_team1.user_team_project_relationships.count  
252 - end  
253 - end  
254 -  
255 - context "when authenticated as admin" do  
256 - it "should return project2 as assigned to user_team2 as non-member, but admin" do  
257 - get api("/user_teams/#{user_team2.id}/projects", admin)  
258 - response.status.should == 200  
259 - json_response.first['name'].should == project2.name  
260 - json_response.first['greatest_access_level'].should == UsersProject::MASTER  
261 - end  
262 - end  
263 - end  
264 -  
265 - describe "POST /user_teams/:id/projects" do  
266 - context "when authenticated as admin" do  
267 - it "should return ok and add new project" do  
268 - count_before=user_team1.user_team_project_relationships.count  
269 - post api("/user_teams/#{user_team1.id}/projects", admin),  
270 - project_id: project2.id,  
271 - greatest_access_level: UsersProject::MASTER  
272 - response.status.should == 201  
273 - json_response['name'].should == project2.name  
274 - json_response['greatest_access_level'].should == UsersProject::MASTER  
275 - user_team1.user_team_project_relationships.count.should == count_before + 1  
276 - end  
277 - it "should return ok if project already exists" do  
278 - post api("/user_teams/#{user_team2.id}/projects", admin),  
279 - project_id: project2.id,  
280 - greatest_access_level: UsersProject::MASTER  
281 - response.status.should == 409  
282 - end  
283 - it "should return a 400 error when project id is not given" do  
284 - post api("/user_teams/#{user_team2.id}/projects", admin), greatest_access_level: UsersProject::MASTER  
285 - response.status.should == 400  
286 - end  
287 - it "should return a 400 error when access level is not given" do  
288 - post api("/user_teams/#{user_team2.id}/projects", admin), project_id: project2.id  
289 - response.status.should == 400  
290 - end  
291 -  
292 - it "should return a 422 error when access level is not known" do  
293 - post api("/user_teams/#{user_team2.id}/projects", admin),  
294 - project_id: project2.id,  
295 - greatest_access_level: 1234  
296 - response.status.should == 422  
297 - end  
298 -  
299 - end  
300 - end  
301 -  
302 -  
303 - describe "GET /user_teams/:id/projects/:project_id" do  
304 - context "when authenticated as member" do  
305 - it "should show project1's assignment to user_team1" do  
306 - get api("/user_teams/#{user_team1.id}/projects/#{project1.id}", user1)  
307 - response.status.should == 200  
308 - json_response['name'].should == project1.name  
309 - json_response['greatest_access_level'].should == UsersProject::MASTER  
310 - end  
311 - it "should show project2's is not assigned to user_team1" do  
312 - get api("/user_teams/#{user_team1.id}/projects/#{project2.id}", user1)  
313 - response.status.should == 404  
314 - end  
315 - end  
316 -  
317 - context "when authenticated as non-member" do  
318 - it "should not show project1's assignment to user_team1" do  
319 - get api("/user_teams/#{user_team1.id}/projects/#{project1.id}", user2)  
320 - response.status.should == 404  
321 - end  
322 - end  
323 -  
324 - context "when authenticated as admin" do  
325 - it "should show project1's assignment to user_team1" do  
326 - get api("/user_teams/#{user_team1.id}/projects/#{project1.id}", admin)  
327 - response.status.should == 200  
328 - json_response['name'].should == project1.name  
329 - json_response['greatest_access_level'].should == UsersProject::MASTER  
330 - end  
331 - it "should return a 404 error when project id is not known" do  
332 - get api("/user_teams/#{user_team2.id}/projects/1328", admin)  
333 - response.status.should == 404  
334 - end  
335 - end  
336 - end  
337 -  
338 - describe "DELETE /user_teams/:id/projects/:project_id" do  
339 - context "when authenticated as user" do  
340 - it "should not delete project1's assignment to user_team2" do  
341 - delete api("/user_teams/#{user_team2.id}/projects/#{project1.id}", user1)  
342 - response.status.should == 403  
343 - end  
344 - end  
345 -  
346 - context "when authenticated as admin" do  
347 - it "should delete project1's assignment to user_team1" do  
348 - count_before=user_team1.user_team_project_relationships.count  
349 - delete api("/user_teams/#{user_team1.id}/projects/#{project1.id}", admin)  
350 - response.status.should == 200  
351 - user_team1.user_team_project_relationships.count.should == count_before - 1  
352 - end  
353 - it "should return a 404 error when project id is not known" do  
354 - delete api("/user_teams/#{user_team2.id}/projects/1328", admin)  
355 - response.status.should == 404  
356 - end  
357 - end  
358 - end  
359 -  
360 -end