From 8a86fe7bb0785ea69e591fd287430eb5448ac64e Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Sat, 19 Jan 2013 21:06:50 +0400 Subject: [PATCH 01/56] Added UserTeam core models (team and m-t-m relationships) and updated other models --- app/models/concerns/issuable.rb | 1 + app/models/project.rb | 39 +++++---- app/models/user.rb | 33 ++++--- app/models/user_team.rb | 87 +++++++++++++++++++ app/models/user_team_project_relationship.rb | 24 +++++ app/models/user_team_user_relationship.rb | 15 ++++ app/models/users_project.rb | 3 + .../20121219183753_create_user_teams.rb | 11 +++ ..._create_user_team_project_relationships.rb | 11 +++ ...453_create_user_team_user_relationships.rb | 12 +++ db/schema.rb | 25 ++++++ .../user_team_project_relationship_spec.rb | 5 ++ spec/models/user_team_spec.rb | 5 ++ .../user_team_user_relationship_spec.rb | 5 ++ 14 files changed, 248 insertions(+), 28 deletions(-) create mode 100644 app/models/user_team.rb create mode 100644 app/models/user_team_project_relationship.rb create mode 100644 app/models/user_team_user_relationship.rb create mode 100644 db/migrate/20121219183753_create_user_teams.rb create mode 100644 db/migrate/20121220064104_create_user_team_project_relationships.rb create mode 100644 db/migrate/20121220064453_create_user_team_user_relationships.rb create mode 100644 spec/models/user_team_project_relationship_spec.rb create mode 100644 spec/models/user_team_spec.rb create mode 100644 spec/models/user_team_user_relationship_spec.rb diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb index d1717d3bbee..8872cf59a2c 100644 --- a/app/models/concerns/issuable.rb +++ b/app/models/concerns/issuable.rb @@ -22,6 +22,7 @@ module Issuable scope :opened, where(closed: false) scope :closed, where(closed: true) scope :of_group, ->(group) { where(project_id: group.project_ids) } + scope :of_user_team, ->(team) { where(project_id: team.project_ids, assignee_id: team.member_ids) } scope :assigned, ->(u) { where(assignee_id: u.id)} scope :recent, order("created_at DESC") diff --git a/app/models/project.rb b/app/models/project.rb index fa38093b7d5..fa314d9c5f0 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -33,28 +33,31 @@ class Project < ActiveRecord::Base attr_accessor :error_code # Relations - belongs_to :group, foreign_key: "namespace_id", conditions: "type = 'Group'" + belongs_to :creator, foreign_key: "creator_id", class_name: "User" + belongs_to :group, foreign_key: "namespace_id", conditions: "type = 'Group'" belongs_to :namespace - belongs_to :creator, - class_name: "User", - foreign_key: "creator_id" - - has_many :users, through: :users_projects - has_many :events, dependent: :destroy - has_many :merge_requests, dependent: :destroy - has_many :issues, dependent: :destroy, order: "closed, created_at DESC" - has_many :milestones, dependent: :destroy - has_many :users_projects, dependent: :destroy - has_many :notes, dependent: :destroy - has_many :snippets, dependent: :destroy - has_many :deploy_keys, dependent: :destroy, foreign_key: "project_id", class_name: "Key" - has_many :hooks, dependent: :destroy, class_name: "ProjectHook" - has_many :wikis, dependent: :destroy - has_many :protected_branches, dependent: :destroy has_one :last_event, class_name: 'Event', order: 'events.created_at DESC', foreign_key: 'project_id' has_one :gitlab_ci_service, dependent: :destroy + has_many :events, dependent: :destroy + has_many :merge_requests, dependent: :destroy + has_many :issues, dependent: :destroy, order: "closed, created_at DESC" + has_many :milestones, dependent: :destroy + has_many :users_projects, dependent: :destroy + has_many :notes, dependent: :destroy + has_many :snippets, dependent: :destroy + has_many :deploy_keys, dependent: :destroy, class_name: "Key", foreign_key: "project_id" + has_many :hooks, dependent: :destroy, class_name: "ProjectHook" + has_many :wikis, dependent: :destroy + has_many :protected_branches, dependent: :destroy + has_many :user_team_project_relationships, dependent: :destroy + + has_many :users, through: :users_projects + has_many :user_teams, through: :user_team_project_relationships + has_many :user_team_user_relationships, through: :user_teams + has_many :user_teams_members, through: :user_team_user_relationships + delegate :name, to: :owner, allow_nil: true, prefix: true # Validations @@ -77,6 +80,8 @@ class Project < ActiveRecord::Base # Scopes scope :without_user, ->(user) { where("id NOT IN (:ids)", ids: user.authorized_projects.map(&:id) ) } scope :not_in_group, ->(group) { where("id NOT IN (:ids)", ids: group.project_ids ) } + scope :without_team, ->(team) { where("id NOT IN (:ids)", ids: team.projects.map(&:id)) } + scope :in_team, ->(team) { where("id IN (:ids)", ids: team.projects.map(&:id)) } scope :in_namespace, ->(namespace) { where(namespace_id: namespace.id) } scope :sorted_by_activity, ->() { order("(SELECT max(events.created_at) FROM events WHERE events.project_id = projects.id) DESC") } scope :personal, ->(user) { where(namespace_id: user.namespace_id) } diff --git a/app/models/user.rb b/app/models/user.rb index 743d7523bdc..16e07e9ce3f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -45,18 +45,27 @@ class User < ActiveRecord::Base attr_accessor :force_random_password # Namespace for personal projects - has_one :namespace, class_name: "Namespace", foreign_key: :owner_id, conditions: 'type IS NULL', dependent: :destroy - has_many :groups, class_name: "Group", foreign_key: :owner_id + has_one :namespace, dependent: :destroy, foreign_key: :owner_id, class_name: "Namespace", conditions: 'type IS NULL' - has_many :keys, dependent: :destroy - has_many :users_projects, dependent: :destroy - has_many :issues, foreign_key: :author_id, dependent: :destroy - has_many :notes, foreign_key: :author_id, dependent: :destroy - has_many :merge_requests, foreign_key: :author_id, dependent: :destroy - has_many :events, class_name: "Event", foreign_key: :author_id, dependent: :destroy - has_many :recent_events, class_name: "Event", foreign_key: :author_id, order: "id DESC" - has_many :assigned_issues, class_name: "Issue", foreign_key: :assignee_id, dependent: :destroy - has_many :assigned_merge_requests, class_name: "MergeRequest", foreign_key: :assignee_id, dependent: :destroy + has_many :keys, dependent: :destroy + has_many :users_projects, dependent: :destroy + has_many :issues, dependent: :destroy, foreign_key: :author_id + has_many :notes, dependent: :destroy, foreign_key: :author_id + has_many :merge_requests, dependent: :destroy, foreign_key: :author_id + has_many :events, dependent: :destroy, foreign_key: :author_id, class_name: "Event" + has_many :assigned_issues, dependent: :destroy, foreign_key: :assignee_id, class_name: "Issue" + has_many :assigned_merge_requests, dependent: :destroy, foreign_key: :assignee_id, class_name: "MergeRequest" + + has_many :groups, class_name: "Group", foreign_key: :owner_id + has_many :recent_events, class_name: "Event", foreign_key: :author_id, order: "id DESC" + + has_many :projects, through: :users_projects + + has_many :user_team_user_relationships, dependent: :destroy + + has_many :user_teams, through: :user_team_user_relationships + has_many :user_team_project_relationships, through: :user_teams + has_many :team_projects, through: :user_team_project_relationships validates :name, presence: true validates :bio, length: { within: 0..255 } @@ -80,6 +89,8 @@ class User < ActiveRecord::Base scope :blocked, where(blocked: true) scope :active, where(blocked: false) scope :alphabetically, order('name ASC') + scope :in_team, ->(team){ where(id: team.member_ids) } + scope :not_in_team, ->(team){ where('users.id NOT IN (:ids)', ids: team.member_ids) } # # Class methods diff --git a/app/models/user_team.rb b/app/models/user_team.rb new file mode 100644 index 00000000000..d402fd22ea3 --- /dev/null +++ b/app/models/user_team.rb @@ -0,0 +1,87 @@ +class UserTeam < ActiveRecord::Base + attr_accessible :name, :owner_id, :path + + belongs_to :owner, class_name: User + + has_many :user_team_project_relationships, dependent: :destroy + has_many :user_team_user_relationships, dependent: :destroy + + has_many :projects, through: :user_team_project_relationships + has_many :members, through: :user_team_user_relationships, source: :user + + validates :name, presence: true, uniqueness: true + validates :owner, presence: true + validates :path, uniqueness: true, presence: true, length: { within: 1..255 }, + format: { with: Gitlab::Regex.path_regex, + message: "only letters, digits & '_' '-' '.' allowed. Letter should be first" } + + scope :with_member, ->(user){ joins(:user_team_user_relationships).where(user_team_user_relationships: {user_id: user.id}) } + scope :created_by, ->(user){ where(owner_id: user) } + + class << self + def search query + where("name LIKE :query OR path LIKE :query", query: "%#{query}%") + end + + def global_id + 'GLN' + end + + def access_roles + UsersProject.access_roles + end + end + + def to_param + path + end + + def assign_to_projects(projects, access) + projects.each do |project| + assign_to_project(project, access) + end + end + + def assign_to_project(project, access) + Gitlab::UserTeamManager.assign(self, project, access) + end + + def resign_from_project(project) + Gitlab::UserTeamManager.resign(self, project) + end + + def add_members(users, access, group_admin) + users.each do |user| + add_member(user, access, group_admin) + end + end + + def add_member(user, access, group_admin) + Gitlab::UserTeamManager.add_member_into_team(self, user, access, group_admin) + end + + def remove_member(user) + Gitlab::UserTeamManager.remove_member_from_team(self, user) + end + + def max_project_access(project) + user_team_project_relationships.find_by_project_id(project).greatest_access + end + + def human_max_project_access(project) + self.class.access_roles.invert[max_project_access(project)] + end + + def default_projects_access(member) + user_team_user_relationships.find_by_user_id(member).permission + end + + def human_default_projects_access(member) + self.class.access_roles.invert[default_projects_access(member)] + end + + def admin?(member) + user_team_user_relationships.with_user(member).first.group_admin? + end + +end diff --git a/app/models/user_team_project_relationship.rb b/app/models/user_team_project_relationship.rb new file mode 100644 index 00000000000..4413c492a6d --- /dev/null +++ b/app/models/user_team_project_relationship.rb @@ -0,0 +1,24 @@ +class UserTeamProjectRelationship < ActiveRecord::Base + attr_accessible :greatest_access, :project_id, :user_team_id + + belongs_to :user_team + belongs_to :project + + validates :project, presence: true + validates :user_team, presence: true + validate :check_greatest_access + + scope :with_project, ->(project){ where(project_id: project.id) } + + private + + def check_greatest_access + errors.add(:base, :incorrect_access_code) unless correct_access? + end + + def correct_access? + return false if greatest_access.blank? + return true if UsersProject.access_roles.has_value?(greatest_access) + false + end +end diff --git a/app/models/user_team_user_relationship.rb b/app/models/user_team_user_relationship.rb new file mode 100644 index 00000000000..00d12ebf607 --- /dev/null +++ b/app/models/user_team_user_relationship.rb @@ -0,0 +1,15 @@ +class UserTeamUserRelationship < ActiveRecord::Base + attr_accessible :group_admin, :permission, :user_id, :user_team_id + + belongs_to :user_team + belongs_to :user + + validates :user_team, presence: true + validates :user, presence: true + + scope :with_user, ->(user) { where(user_id: user.id) } + + def user_name + user.name + end +end diff --git a/app/models/users_project.rb b/app/models/users_project.rb index 79146289836..d282b2acbfc 100644 --- a/app/models/users_project.rb +++ b/app/models/users_project.rb @@ -39,7 +39,10 @@ class UsersProject < ActiveRecord::Base scope :reporters, where(project_access: REPORTER) scope :developers, where(project_access: DEVELOPER) scope :masters, where(project_access: MASTER) + scope :in_project, ->(project) { where(project_id: project.id) } + scope :in_projects, ->(projects) { where(project_id: projects.map(&:id)) } + scope :with_user, ->(user) { where(user_id: user.id) } class << self diff --git a/db/migrate/20121219183753_create_user_teams.rb b/db/migrate/20121219183753_create_user_teams.rb new file mode 100644 index 00000000000..65c4d053982 --- /dev/null +++ b/db/migrate/20121219183753_create_user_teams.rb @@ -0,0 +1,11 @@ +class CreateUserTeams < ActiveRecord::Migration + def change + create_table :user_teams do |t| + t.string :name + t.string :path + t.integer :owner_id + + t.timestamps + end + end +end diff --git a/db/migrate/20121220064104_create_user_team_project_relationships.rb b/db/migrate/20121220064104_create_user_team_project_relationships.rb new file mode 100644 index 00000000000..8eb654c8728 --- /dev/null +++ b/db/migrate/20121220064104_create_user_team_project_relationships.rb @@ -0,0 +1,11 @@ +class CreateUserTeamProjectRelationships < ActiveRecord::Migration + def change + create_table :user_team_project_relationships do |t| + t.integer :project_id + t.integer :user_team_id + t.integer :greatest_access + + t.timestamps + end + end +end diff --git a/db/migrate/20121220064453_create_user_team_user_relationships.rb b/db/migrate/20121220064453_create_user_team_user_relationships.rb new file mode 100644 index 00000000000..7783b0ae432 --- /dev/null +++ b/db/migrate/20121220064453_create_user_team_user_relationships.rb @@ -0,0 +1,12 @@ +class CreateUserTeamUserRelationships < ActiveRecord::Migration + def change + create_table :user_team_user_relationships do |t| + t.integer :user_id + t.integer :user_team_id + t.boolean :group_admin + t.integer :permission + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 4b3a2243609..88849872ab2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -213,6 +213,31 @@ ActiveRecord::Schema.define(:version => 20130110172407) do t.string "name" end + create_table "user_team_project_relationships", :force => true do |t| + t.integer "project_id" + t.integer "user_team_id" + t.integer "greatest_access" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + + create_table "user_team_user_relationships", :force => true do |t| + t.integer "user_id" + t.integer "user_team_id" + t.boolean "group_admin" + t.integer "permission" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + + create_table "user_teams", :force => true do |t| + t.string "name" + t.string "path" + t.integer "owner_id" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "users", :force => true do |t| t.string "email", :default => "", :null => false t.string "encrypted_password", :default => "", :null => false diff --git a/spec/models/user_team_project_relationship_spec.rb b/spec/models/user_team_project_relationship_spec.rb new file mode 100644 index 00000000000..81051d59971 --- /dev/null +++ b/spec/models/user_team_project_relationship_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe UserTeamProjectRelationship do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/user_team_spec.rb b/spec/models/user_team_spec.rb new file mode 100644 index 00000000000..2d1b99db6f8 --- /dev/null +++ b/spec/models/user_team_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe UserTeam do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/user_team_user_relationship_spec.rb b/spec/models/user_team_user_relationship_spec.rb new file mode 100644 index 00000000000..309f1975e51 --- /dev/null +++ b/spec/models/user_team_user_relationship_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe UserTeamUserRelationship do + pending "add some examples to (or delete) #{__FILE__}" +end From 82499a4cbfdd9605312322fea80b76f034230b1b Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Sat, 19 Jan 2013 21:11:11 +0400 Subject: [PATCH 02/56] Admin teams section added --- app/controllers/admin/teams_controller.rb | 104 ++++++++++ app/views/admin/teams/edit.html.haml | 28 +++ app/views/admin/teams/index.html.haml | 37 ++++ app/views/admin/teams/new.html.haml | 21 ++ app/views/admin/teams/show.html.haml | 104 ++++++++++ app/views/layouts/admin.html.haml | 2 + config/routes.rb | 8 + features/admin/teams.feature | 73 +++++++ features/steps/admin/admin_teams.rb | 222 ++++++++++++++++++++++ features/steps/shared/paths.rb | 4 + 10 files changed, 603 insertions(+) create mode 100644 app/controllers/admin/teams_controller.rb create mode 100644 app/views/admin/teams/edit.html.haml create mode 100644 app/views/admin/teams/index.html.haml create mode 100644 app/views/admin/teams/new.html.haml create mode 100644 app/views/admin/teams/show.html.haml create mode 100644 features/admin/teams.feature create mode 100644 features/steps/admin/admin_teams.rb diff --git a/app/controllers/admin/teams_controller.rb b/app/controllers/admin/teams_controller.rb new file mode 100644 index 00000000000..fd25d3fe219 --- /dev/null +++ b/app/controllers/admin/teams_controller.rb @@ -0,0 +1,104 @@ +class Admin::TeamsController < AdminController + before_filter :user_team, + only: [ :edit, :show, :update, :destroy, + :delegate_projects, :relegate_project, + :add_members, :remove_member ] + + def index + @teams = UserTeam.order('name ASC') + @teams = @teams.search(params[:name]) if params[:name].present? + @teams = @teams.page(params[:page]).per(20) + end + + def show + @projects = Project.scoped + @projects = @projects.without_team(@team) if @team.projects.any? + #@projects.reject!(&:empty_repo?) + + @users = User.active + @users = @users.not_in_team(@team) if @team.members.any? + @users = UserDecorator.decorate @users + end + + def new + @team = UserTeam.new + end + + def edit + end + + def create + @team = UserTeam.new(params[:user_team]) + @team.path = @team.name.dup.parameterize if @team.name + @team.owner = current_user + + if @team.save + redirect_to admin_team_path(@team), notice: 'UserTeam was successfully created.' + else + render action: "new" + end + end + + def update + user_team_params = params[:user_team].dup + owner_id = user_team_params.delete(:owner_id) + + if owner_id + @team.owner = User.find(owner_id) + end + + if @team.update_attributes(user_team_params) + redirect_to admin_team_path(@team), notice: 'UserTeam was successfully updated.' + else + render action: "edit" + end + end + + def destroy + @team.destroy + + redirect_to admin_user_teams_path, notice: 'UserTeam was successfully deleted.' + end + + def delegate_projects + unless params[:project_ids].blank? + project_ids = params[:project_ids] + access = params[:greatest_project_access] + @team.assign_to_projects(project_ids, access) + end + + redirect_to admin_team_path(@team), notice: 'Projects was successfully added.' + end + + def relegate_project + project = params[:project_id] + @team.resign_from_project(project) + + redirect_to admin_team_path(@team), notice: 'Project was successfully removed.' + end + + def add_members + unless params[:user_ids].blank? + user_ids = params[:user_ids] + access = params[:default_project_access] + is_admin = params[:group_admin] + @team.add_members(user_ids, access, is_admin) + end + + redirect_to admin_team_path(@team), notice: 'Members was successfully added.' + end + + def remove_member + member = params[:member_id] + @team.remove_member(member) + + redirect_to admin_team_path(@team), notice: 'Member was successfully removed.' + end + + private + + def user_team + @team = UserTeam.find_by_path(params[:id]) + end + +end diff --git a/app/views/admin/teams/edit.html.haml b/app/views/admin/teams/edit.html.haml new file mode 100644 index 00000000000..15ec267f45f --- /dev/null +++ b/app/views/admin/teams/edit.html.haml @@ -0,0 +1,28 @@ +%h3.page_title Rename Team +%hr += form_for [:admin, @team] do |f| + - if @team.errors.any? + .alert-message.block-message.error + %span= @team.errors.full_messages.first + .clearfix.team_name_holder + = f.label :name do + Team name is + .input + = f.text_field :name, placeholder: "Example Team", class: "xxlarge" + + + + .clearfix.team_name_holder + = f.label :path do + %span.cred Team path is + .input + = f.text_field :path, placeholder: "example-team", class: "xxlarge danger" + %ul.cred + %li Changing team path can have unintended side effects. + %li Renaming team path will rename directory for all related projects + %li It will change web url for access team and team projects. + %li It will change the git path to repositories under this team. + + .form-actions + = f.submit 'Rename team', class: "btn danger" + = link_to 'Cancel', admin_teams_path, class: "btn cancel-btn" diff --git a/app/views/admin/teams/index.html.haml b/app/views/admin/teams/index.html.haml new file mode 100644 index 00000000000..8b6928e906e --- /dev/null +++ b/app/views/admin/teams/index.html.haml @@ -0,0 +1,37 @@ +%h3.page_title + Teams + %small + simple Teams description + + = link_to 'New Team', new_admin_team_path, class: "btn small right" + %br + += form_tag admin_teams_path, method: :get, class: 'form-inline' do + = text_field_tag :name, params[:name], class: "xlarge" + = submit_tag "Search", class: "btn submit primary" + +%table + %thead + %tr + %th + Name + %i.icon-sort-down + %th Path + %th Projects + %th Members + %th Owner + %th.cred Danger Zone! + + - @teams.each do |team| + %tr + %td + %strong= link_to team.name, admin_team_path(team) + %td= team.path + %td= team.projects.count + %td= team.members.count + %td + = link_to team.owner.name, admin_user_path(team.owner_id) + %td.bgred + = link_to 'Rename', edit_admin_team_path(team), id: "edit_#{dom_id(team)}", class: "btn small" + = link_to 'Destroy', admin_team_path(team), confirm: "REMOVE #{team.name}? Are you sure?", method: :delete, class: "btn small danger" += paginate @teams, theme: "admin" diff --git a/app/views/admin/teams/new.html.haml b/app/views/admin/teams/new.html.haml new file mode 100644 index 00000000000..c936b66b32e --- /dev/null +++ b/app/views/admin/teams/new.html.haml @@ -0,0 +1,21 @@ +%h3.page_title New Team +%hr += form_for @team, url: admin_teams_path do |f| + - if @team.errors.any? + .alert-message.block-message.error + %span= @team.errors.full_messages.first + .clearfix + = f.label :name do + Team name is + .input + = f.text_field :name, placeholder: "Ex. OpenSource", class: "xxlarge left" +   + = f.submit 'Create team', class: "btn primary" + %hr + .padded + %ul + %li Team is kind of directory for several projects + %li All created teams are private + %li People within a team see only projects they have access to + %li All projects of team will be stored in team directory + %li You will be able to move existing projects into team diff --git a/app/views/admin/teams/show.html.haml b/app/views/admin/teams/show.html.haml new file mode 100644 index 00000000000..0f47717ae0e --- /dev/null +++ b/app/views/admin/teams/show.html.haml @@ -0,0 +1,104 @@ +%h3.page_title + Team: #{@team.name} + +%br +%table.zebra-striped + %thead + %tr + %th Team + %th + %tr + %td + %b + Name: + %td + = @team.name +   + = link_to edit_admin_team_path(@team), class: "btn btn-small right" do + %i.icon-edit + Rename + %tr + %td + %b + Owner: + %td + = @team.owner.name + .right + = link_to "#", class: "btn btn-small change-owner-link" do + %i.icon-edit + Change owner + + %tr.change-owner-holder.hide + %td.bgred + %b.cred + New Owner: + %td.bgred + = form_for @team, url: admin_team_path(@team) do |f| + = f.select :owner_id, User.all.map { |user| [user.name, user.id] }, {}, {class: 'chosen'} + %div + = f.submit 'Change Owner', class: "btn danger" + = link_to "Cancel", "#", class: "btn change-owner-cancel-link" + +%fieldset + %legend Members (#{@team.members.count}) + = form_tag add_members_admin_team_path(@team), id: "team_members", class: "bulk_import", method: :post do + %table#members_list + %thead + %tr + %th User name + %th Default project access + %th Team access + %th.cred Danger Zone! + - @team.members.each do |member| + %tr.member + %td + = link_to [:admin, member] do + = member.name + %small= "(#{member.email})" + %td= @team.human_default_projects_access(member) + %td= @team.admin?(member) ? "Admin" : "Member" + %td.bgred + = link_to 'Remove', remove_member_admin_team_path(@team, member_id: member.id), confirm: 'Remove project from team and move to global namespace. Are you sure?', method: :delete, class: "btn danger small" + %tr + %td= select_tag :user_ids, options_from_collection_for_select(@users , :id, :name_with_email), multiple: true, data: {placeholder: 'Select users'}, class: 'chosen span5' + %td= select_tag :default_project_access, options_for_select(Project.access_options), {class: "project-access-select chosen span3" } + %td + %span= check_box_tag :group_admin + %span Admin? + %td= submit_tag 'Add', class: "btn primary", id: :add_members_to_team + +%fieldset + %legend Projects (#{@team.projects.count}) + = form_tag delegate_projects_admin_team_path(@team), id: "assign_projects", class: "bulk_import", method: :post do + %table#projects_list + %thead + %tr + %th Project name + %th Max access + %th.cred Danger Zone! + - @team.projects.each do |project| + %tr.project + %td + = link_to project.name_with_namespace, [:admin, project] + %td + %span= @team.human_max_project_access(project) + %td.bgred + = link_to 'Relegate', relegate_project_admin_team_path(@team, project_id: project.id), confirm: 'Remove project from team and move to global namespace. Are you sure?', method: :delete, class: "btn danger small" + %tr + %td= select_tag :project_ids, options_from_collection_for_select(@projects , :id, :name_with_namespace), multiple: true, data: {placeholder: 'Select projects'}, class: 'chosen span5' + %td= select_tag :greatest_project_access, options_for_select(Project.access_options), {class: "project-access-select chosen span3" } + %td= submit_tag 'Add', class: "btn primary", id: :assign_projects_to_team + +:javascript + $(function(){ + var modal = $('.change-owner-holder'); + $('.change-owner-link').bind("click", function(){ + $(this).hide(); + modal.show(); + }); + $('.change-owner-cancel-link').bind("click", function(){ + modal.hide(); + $('.change-owner-link').show(); + }) + }) + diff --git a/app/views/layouts/admin.html.haml b/app/views/layouts/admin.html.haml index a60e7febe76..28626b9c682 100644 --- a/app/views/layouts/admin.html.haml +++ b/app/views/layouts/admin.html.haml @@ -10,6 +10,8 @@ = link_to "Stats", admin_root_path = nav_link(controller: :projects) do = link_to "Projects", admin_projects_path + = nav_link(controller: :teams) do + = link_to "Teams", admin_teams_path = nav_link(controller: :groups) do = link_to "Groups", admin_groups_path = nav_link(controller: :users) do diff --git a/config/routes.rb b/config/routes.rb index 6d7e615187d..d364f80551e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -69,6 +69,14 @@ Gitlab::Application.routes.draw do put :team_update end end + resources :teams do #, constraints: { id: /[^\/]+/ } do end + member do + post :delegate_projects + delete :relegate_project + post :add_members + delete :remove_member + end + end resources :team_members, only: [:edit, :update, :destroy] resources :hooks, only: [:index, :create, :destroy] do get :test diff --git a/features/admin/teams.feature b/features/admin/teams.feature new file mode 100644 index 00000000000..e070a90ae02 --- /dev/null +++ b/features/admin/teams.feature @@ -0,0 +1,73 @@ +Feature: Admin Teams + Background: + Given I sign in as an admin + #And there are projects in system + #And system has users + #And I have own project + And Create gitlab user "John" + + Scenario: Create a team + When I visit admin teams page + And I click new team link + And submit form with new team info + Then I should be redirected to team page + And I should see newly created team + + Scenario: Add user to team + When I visit admin teams page + When I have clean "HardCoders" team + And I visit "HardCoders" team page + #Then I should see only me in members table + When I select user "John" from user list as "Developer" + And submit form with new team member info + Then I should see "John" in teams members list as "Developer" + When I visit "John" user admin page + Then I should see "HardCoders" team in teams table + + Scenario: Assign team to existing project + When I visit admin teams page + When I have "HardCoders" team with "John" member with "Developer" role + When I have "Shop" project + And I visit "HardCoders" team page + Then I should see empty projects table + When I select project "Shop" with max access "Reporter" + And submit form with new team project info + Then I should see "Shop" project in projects list + When I visit "Shop" project admin page + Then I should see "John" user with role "Reporter" in team table + + Scenario: Add user to team with ptojects + When I visit admin teams page + When I have "HardCoders" team with "John" member with "Developer" role + And "HardCoders" team assigned to "Shop" project with "Developer" max role access + When I have gitlab user "Jimm" + And I visit "HardCoders" team page + Then I should see members table without "Jimm" member + When I select user "Jimm" ub team members list as "Master" + And submit form with new team member info + Then I should see "Jimm" in teams members list as "Master" + + Scenario: Remove member from team + Given I have users team "HardCoders" + And gitlab user "John" is a member "HardCoders" team + And gitlab user "Jimm" is a member "HardCoders" team + And "HardCoders" team is assigned to "Shop" project + When I visit admin teams page + When I visit "HardCoders" team admin page + Then I shoould see "John" in members list + And I should see "Jimm" in members list + And I should see "Shop" in projects list + When I click on remove "Jimm" user link + Then I should be redirected to "HardCoders" team admin page + And I should not to see "Jimm" user in members list + + Scenario: Remove project from team + Given I have users team "HardCoders" + And gitlab user "John" is a member "HardCoders" team + And gitlab user "Jimm" is a member "HardCoders" team + And "HardCoders" team is assigned to "Shop" project + When I visit admin teams page + When I visit "HardCoders" team admin page + Then I should see "Shop" project in projects list + When I click on "Relegate" link on "Shop" project + Then I should see projects liston team page without "Shop" project diff --git a/features/steps/admin/admin_teams.rb b/features/steps/admin/admin_teams.rb new file mode 100644 index 00000000000..7bb1dacabcb --- /dev/null +++ b/features/steps/admin/admin_teams.rb @@ -0,0 +1,222 @@ +class AdminTeams < Spinach::FeatureSteps + include SharedAuthentication + include SharedPaths + include SharedActiveTab + include SharedAdmin + + And 'I have own project' do + create :project + end + + And 'Create gitlab user "John"' do + @user = create(:user, :name => "John") + end + + And 'I click new team link' do + click_link "New Team" + end + + And 'submit form with new team info' do + fill_in 'user_team_name', with: 'gitlab' + click_button 'Create team' + end + + Then 'I should be redirected to team page' do + current_path.should == admin_team_path(UserTeam.last) + end + + And 'I should see newly created team' do + page.should have_content "Team: gitlab" + end + + When 'I visit admin teams page' do + visit admin_teams_path + end + + When 'I have clean "HardCoders" team' do + @team = create :user_team, name: "HardCoders", owner: current_user + end + + And 'I visit "HardCoders" team page' do + visit admin_team_path(UserTeam.find_by_name("HardCoders")) + end + + Then 'I should see only me in members table' do + members_list = find("#members_list .member") + members_list.should have_content(current_user.name) + members_list.should have_content(current_user.email) + end + + When 'I select user "John" from user list as "Developer"' do + @user ||= User.find_by_name("John") + within "#team_members" do + select user.name, :from => "user_ids" + select "Developer", :from => "default_project_access" + end + end + + And 'submit form with new team member info' do + click_button 'add_members_to_team' + end + + Then 'I should see "John" in teams members list as "Developer"' do + @user ||= User.find_by_name("John") + find_in_list("#members_list .member", user).must_equal true + end + + When 'I visit "John" user admin page' do + pending 'step not implemented' + end + + Then 'I should see "HardCoders" team in teams table' do + pending 'step not implemented' + end + + When 'I have "HardCoders" team with "John" member with "Developer" role' do + @team = create :user_team, name: "HardCoders", owner: current_user + @user ||= User.find_by_name("John") + @team.add_member(@user, UserTeam.access_roles["Developer"], group_admin: false) + end + + When 'I have "Shop" project' do + @project = create :project, name: "Shop" + end + + Then 'I should see empty projects table' do + projects_list = find("#projects_list") + projects_list.has_content?("Relegate").must_equal false + end + + When 'I select project "Shop" with max access "Reporter"' do + @project ||= Project.find_by_name("Shop") + within "#assign_projects" do + select @project.name, :from => "project_ids" + select "Reporter", :from => "greatest_project_access" + end + + end + + And 'submit form with new team project info' do + click_button 'assign_projects_to_team' + end + + Then 'I should see "Shop" project in projects list' do + project = Project.find_by_name("Shop") + find_in_list("#projects_list .project", project).must_equal true + end + + When 'I visit "Shop" project admin page' do + project = Project.find_by_name("Shop") + visit admin_project_path(project) + end + + And '"HardCoders" team assigned to "Shop" project with "Developer" max role access' do + @team = UserTeam.find_by_name("HardCoders") + @project = create :project, name: "Shop" + @team.assign_to_project(@project, UserTeam.access_roles["Developer"]) + end + + When 'I have gitlab user "Jimm"' do + create :user, name: "Jimm" + end + + Then 'I should see members table without "Jimm" member' do + user = User.find_by_name("Jimm") + find_in_list("#members_list .member", user).must_equal false + end + + When 'I select user "Jimm" ub team members list as "Master"' do + user = User.find_by_name("Jimm") + within "#team_members" do + select user.name, :from => "user_ids" + select "Developer", :from => "default_project_access" + end + end + + Then 'I should see "Jimm" in teams members list as "Master"' do + user = User.find_by_name("Jimm") + find_in_list("#members_list .member", user).must_equal true + end + + Given 'I have users team "HardCoders"' do + @team = create :user_team, name: "HardCoders" + end + + And 'gitlab user "John" is a member "HardCoders" team' do + @team = UserTeam.find_by_name("HardCoders") + @user = User.find_by_name("John") + @user = create :user, name: "John" unless @user + @team.add_member(@user, UserTeam.access_roles["Master"], group_admin: false) + end + + And 'gitlab user "Jimm" is a member "HardCoders" team' do + @team = UserTeam.find_by_name("HardCoders") + @user = User.find_by_name("Jimm") + @user = create :user, name: "Jimm" unless @user + @team.add_member(@user, UserTeam.access_roles["Master"], group_admin: false) + end + + And '"HardCoders" team is assigned to "Shop" project' do + @team = UserTeam.find_by_name("HardCoders") + @project = create :project, name: "Shop" + @team.assign_to_project(@project, UserTeam.access_roles["Developer"]) + end + + When 'I visit "HardCoders" team admin page' do + visit admin_team_path(UserTeam.find_by_name("HardCoders")) + end + + Then 'I shoould see "John" in members list' do + user = User.find_by_name("John") + find_in_list("#members_list .member", user).must_equal true + end + + And 'I should see "Jimm" in members list' do + user = User.find_by_name("Jimm") + find_in_list("#members_list .member", user).must_equal true + end + + And 'I should see "Shop" in projects list' do + + end + + When 'I click on remove "Jimm" user link' do + + end + + Then 'I should be redirected to "HardCoders" team admin page' do + current_path.should admin_team_peth(UserTeam.find_by_name("HardCoders")) + end + + And 'I should not to see "Jimm" user in members list' do + + end + + When 'I click on "Relegate" link on "Shop" project' do + + end + + Then 'I should see projects liston team page without "Shop" project' do + + end + + Then 'I should see "John" user with role "Reporter" in team table' do + user = User.find_by_name("John") + find_in_list(".team_members", user).must_equal true + end + + protected + + def current_team + @team ||= Team.first + end + + def find_in_list(selector, item) + members_list = all(selector) + entered = false + members_list.each do |member_item| + entered = true if member_item.has_content?(item.name) + end + entered + end +end diff --git a/features/steps/shared/paths.rb b/features/steps/shared/paths.rb index c046c4e63e6..e397ff87f41 100644 --- a/features/steps/shared/paths.rb +++ b/features/steps/shared/paths.rb @@ -105,6 +105,10 @@ module SharedPaths visit admin_groups_path end + When 'I visit admin teams page' do + visit admin_teams_path + end + # ---------------------------------------- # Generic Project # ---------------------------------------- From 695becc4cb017d76329efb55aae7ddb9a208895b Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Sat, 19 Jan 2013 21:32:09 +0400 Subject: [PATCH 03/56] Add teams into Public sections --- app/controllers/teams_controller.rb | 113 ++++++++++ app/views/teams/_filter.html.haml | 33 +++ app/views/teams/_projects.html.haml | 22 ++ app/views/teams/_team_head.html.haml | 19 ++ app/views/teams/edit.html.haml | 32 +++ app/views/teams/index.html.haml | 37 ++++ app/views/teams/issues.html.haml | 25 +++ app/views/teams/merge_requests.html.haml | 24 +++ app/views/teams/new.html.haml | 21 ++ app/views/teams/search.html.haml | 11 + app/views/teams/show.html.haml | 30 +++ config/routes.rb | 14 ++ features/steps/userteams/userteams.rb | 250 +++++++++++++++++++++++ features/teams/team.feature | 75 +++++++ 14 files changed, 706 insertions(+) create mode 100644 app/controllers/teams_controller.rb create mode 100644 app/views/teams/_filter.html.haml create mode 100644 app/views/teams/_projects.html.haml create mode 100644 app/views/teams/_team_head.html.haml create mode 100644 app/views/teams/edit.html.haml create mode 100644 app/views/teams/index.html.haml create mode 100644 app/views/teams/issues.html.haml create mode 100644 app/views/teams/merge_requests.html.haml create mode 100644 app/views/teams/new.html.haml create mode 100644 app/views/teams/search.html.haml create mode 100644 app/views/teams/show.html.haml create mode 100644 features/steps/userteams/userteams.rb create mode 100644 features/teams/team.feature diff --git a/app/controllers/teams_controller.rb b/app/controllers/teams_controller.rb new file mode 100644 index 00000000000..4e3703d72d4 --- /dev/null +++ b/app/controllers/teams_controller.rb @@ -0,0 +1,113 @@ +class TeamsController < ApplicationController + respond_to :html + layout 'user_team', only: [:show, :edit, :update, :destroy, :issues, :merge_requests, :search] + + before_filter :user_team, only: [:show, :edit, :update, :destroy, :issues, :merge_requests, :search] + before_filter :projects, only: [:show, :edit, :update, :destroy, :issues, :merge_requests, :search] + + # Authorize + before_filter :authorize_manage_user_team!, only: [:edit, :update] + before_filter :authorize_admin_user_team!, only: [:destroy] + + def index + @teams = UserTeam.all + end + + def show + @events = Event.in_projects(project_ids).limit(20).offset(params[:offset] || 0) + + respond_to do |format| + format.html + format.js + format.atom { render layout: false } + end + end + + def edit + + end + + def update + if user_team.update_attributes(params[:user_team]) + redirect_to team_path(user_team) + else + render action: :edit + end + end + + def destroy + user_team.destroy + redirect_to teams_path + end + + def new + @team = UserTeam.new + end + + def create + @team = UserTeam.new(params[:user_team]) + @team.owner = current_user unless params[:owner] + @team.path = @team.name.dup.parameterize if @team.name + + if @team.save + redirect_to team_path(@team) + else + render action: :new + end + end + + # Get authored or assigned open merge requests + def merge_requests + @merge_requests = MergeRequest.of_user_team(@user_team) + @merge_requests = FilterContext.new(@merge_requests, params).execute + @merge_requests = @merge_requests.recent.page(params[:page]).per(20) + end + + # Get only assigned issues + def issues + @issues = Issue.of_user_team(@user_team) + @issues = FilterContext.new(@issues, params).execute + @issues = @issues.recent.page(params[:page]).per(20) + @issues = @issues.includes(:author, :project) + + respond_to do |format| + format.html + format.atom { render layout: false } + end + end + + def search + result = SearchContext.new(project_ids, params).execute + + @projects = result[:projects] + @merge_requests = result[:merge_requests] + @issues = result[:issues] + @wiki_pages = result[:wiki_pages] + end + + protected + + def user_team + @user_team ||= UserTeam.find_by_path(params[:id]) + end + + def projects + @projects ||= user_team.projects.sorted_by_activity + end + + def project_ids + projects.map(&:id) + end + + def authorize_manage_user_team! + unless user_team.present? or can?(current_user, :manage_user_team, user_team) + return render_404 + end + end + + def authorize_admin_user_team! + unless user_team.owner == current_user || current_user.admin? + return render_404 + end + end +end diff --git a/app/views/teams/_filter.html.haml b/app/views/teams/_filter.html.haml new file mode 100644 index 00000000000..8e358319651 --- /dev/null +++ b/app/views/teams/_filter.html.haml @@ -0,0 +1,33 @@ += form_tag team_filter_path(entity), method: 'get' do + %fieldset.dashboard-search-filter + = search_field_tag "search", params[:search], { placeholder: 'Search', class: 'search-text-input' } + = button_tag type: 'submit', class: 'btn' do + %i.icon-search + + %fieldset + %legend Status: + %ul.nav.nav-pills.nav-stacked + %li{class: ("active" if !params[:status])} + = link_to team_filter_path(entity, status: nil) do + Open + %li{class: ("active" if params[:status] == 'closed')} + = link_to team_filter_path(entity, status: 'closed') do + Closed + %li{class: ("active" if params[:status] == 'all')} + = link_to team_filter_path(entity, status: 'all') do + All + + %fieldset + %legend Projects: + %ul.nav.nav-pills.nav-stacked + - @projects.each do |project| + - unless entities_per_project(project, entity).zero? + %li{class: ("active" if params[:project_id] == project.id.to_s)} + = link_to team_filter_path(entity, project_id: project.id) do + = project.name_with_namespace + %small.right= entities_per_project(project, entity) + + %fieldset + %hr + = link_to "Reset", team_filter_path(entity), class: 'btn right' + diff --git a/app/views/teams/_projects.html.haml b/app/views/teams/_projects.html.haml new file mode 100644 index 00000000000..040d1ae94aa --- /dev/null +++ b/app/views/teams/_projects.html.haml @@ -0,0 +1,22 @@ +.projects_box + %h5.title + Projects + %small + (#{projects.count}) + - if can? current_user, :manage_group, @group + %span.right + = link_to new_project_path(namespace_id: @group.id), class: "btn very_small info" do + %i.icon-plus + New Project + %ul.well-list + - if projects.blank? + %p.nothing_here_message This groups has no projects yet + - projects.each do |project| + %li + = link_to project_path(project), class: dom_class(project) do + %strong.well-title= truncate(project.name, length: 25) + %span.arrow + → + %span.last_activity + %strong Last activity: + %span= project_last_activity(project) diff --git a/app/views/teams/_team_head.html.haml b/app/views/teams/_team_head.html.haml new file mode 100644 index 00000000000..53796623de1 --- /dev/null +++ b/app/views/teams/_team_head.html.haml @@ -0,0 +1,19 @@ +%ul.nav.nav-tabs + = nav_link(path: 'teams#show') do + = link_to team_path(@user_team), class: "activities-tab tab" do + %i.icon-home + Show + = nav_link(controller: [:members]) do + = link_to team_members_path(@user_team), class: "team-tab tab" do + %i.icon-user + Members + = nav_link(controller: [:projects]) do + = link_to team_projects_path(@user_team), class: "team-tab tab" do + %i.icon-briefcase + Projects + + - if can? current_user, :manage_user_team, @user_team + = nav_link(path: 'teams#edit', html_options: {class: 'right'}) do + = link_to edit_team_path(@user_team), class: "stat-tab tab " do + %i.icon-edit + Edit diff --git a/app/views/teams/edit.html.haml b/app/views/teams/edit.html.haml new file mode 100644 index 00000000000..4c239e8fa41 --- /dev/null +++ b/app/views/teams/edit.html.haml @@ -0,0 +1,32 @@ += render "team_head" + +%h3.page_title= "Edit Team #{@user_team.name}" +%hr += form_for @user_team, url: teams_path do |f| + - if @user_team.errors.any? + .alert-message.block-message.error + %span= @user_team.errors.full_messages.first + .clearfix + = f.label :name do + Team name is + .input + = f.text_field :name, placeholder: "Ex. OpenSource", class: "xxlarge left" + + .clearfix + = f.label :path do + Team path is + .input + = f.text_field :path, placeholder: "opensource", class: "xxlarge left" + .clearfix + .input.span3.center + = f.submit 'Save team changes', class: "btn primary" + .input.span3.center + = link_to 'Delete team', team_path(@user_team), method: :delete, confirm: "You are shure?", class: "btn danger" + %hr + .padded + %ul + %li Team is kind of directory for several projects + %li All created teams are private + %li People within a team see only projects they have access to + %li All projects of team will be stored in team directory + %li You will be able to move existing projects into team diff --git a/app/views/teams/index.html.haml b/app/views/teams/index.html.haml new file mode 100644 index 00000000000..9ac54594521 --- /dev/null +++ b/app/views/teams/index.html.haml @@ -0,0 +1,37 @@ +%h3.page_title + Teams + %small + list of all teams + + = link_to 'New Team', new_team_path, class: "btn small right" + %br + += form_tag search_teams_path, method: :get, class: 'form-inline' do + = text_field_tag :name, params[:name], class: "xlarge" + = submit_tag "Search", class: "btn submit primary" + +%table.teams_list + %thead + %tr + %th + Name + %i.icon-sort-down + %th Path + %th Projects + %th Members + %th Owner + %th + + - @teams.each do |team| + %tr + %td + %strong= link_to team.name, team_path(team) + %td= team.path + %td= link_to team.projects.count, team_projects_path(team) + %td= link_to team.members.count, team_members_path(team) + %td= link_to team.owner.name, team_member_path(team, team.owner) + %td + - if current_user.can?(:manage_user_team, team) + - if team.owner == current_user + = link_to "Destroy", team_path(team), method: :delete, confirm: "You are shure?", class: "danger btn small right" + = link_to "Edit", edit_team_path(team), class: "btn small right" diff --git a/app/views/teams/issues.html.haml b/app/views/teams/issues.html.haml new file mode 100644 index 00000000000..3c17e85a115 --- /dev/null +++ b/app/views/teams/issues.html.haml @@ -0,0 +1,25 @@ += render "team_head" + +%h3.page_title + Issues + %small (in Team projects assigned to Team members) + %small.right #{@issues.total_count} issues + +%hr +.row + .span3 + = render 'filter', entity: 'issue' + .span9 + - if @issues.any? + - @issues.group_by(&:project).each do |group| + %div.ui-box + - @project = group[0] + %h5.title + = link_to_project @project + %ul.well-list.issues_table + - group[1].each do |issue| + = render(partial: 'issues/show', locals: {issue: issue}) + %hr + = paginate @issues, theme: "gitlab" + - else + %p.nothing_here_message Nothing to show here diff --git a/app/views/teams/merge_requests.html.haml b/app/views/teams/merge_requests.html.haml new file mode 100644 index 00000000000..c9af529e113 --- /dev/null +++ b/app/views/teams/merge_requests.html.haml @@ -0,0 +1,24 @@ +%h3.page_title + Merge Requests + %small (authored by or assigned to Team members) + %small.right #{@merge_requests.total_count} merge requests + +%hr +.row + .span3 + = render 'filter', entity: 'merge_request' + .span9 + - if @merge_requests.any? + - @merge_requests.group_by(&:project).each do |group| + .ui-box + - @project = group[0] + %h5.title + = link_to_project @project + %ul.well-list + - group[1].each do |merge_request| + = render(partial: 'merge_requests/merge_request', locals: {merge_request: merge_request}) + %hr + = paginate @merge_requests, theme: "gitlab" + + - else + %h3.nothing_here_message Nothing to show here diff --git a/app/views/teams/new.html.haml b/app/views/teams/new.html.haml new file mode 100644 index 00000000000..d8312e0e913 --- /dev/null +++ b/app/views/teams/new.html.haml @@ -0,0 +1,21 @@ +%h3.page_title New Team +%hr += form_for @team, url: teams_path do |f| + - if @team.errors.any? + .alert-message.block-message.error + %span= @team.errors.full_messages.first + .clearfix + = f.label :name do + Team name is + .input + = f.text_field :name, placeholder: "Ex. OpenSource", class: "xxlarge left" +   + = f.submit 'Create team', class: "btn primary" + %hr + .padded + %ul + %li Team is kind of directory for several projects + %li All created teams are private + %li People within a team see only projects they have access to + %li All projects of team will be stored in team directory + %li You will be able to move existing projects into team diff --git a/app/views/teams/search.html.haml b/app/views/teams/search.html.haml new file mode 100644 index 00000000000..601f2d57c8b --- /dev/null +++ b/app/views/teams/search.html.haml @@ -0,0 +1,11 @@ += render "team_head" + += form_tag search_team_path(@user_team), method: :get, class: 'form-inline' do |f| + .padded + = label_tag :search do + %strong Looking for + .input + = search_field_tag :search, params[:search], placeholder: "issue 143", class: "input-xxlarge search-text-input", id: "dashboard_search" + = submit_tag 'Search', class: "btn primary wide" +- if params[:search].present? + = render 'search/result' diff --git a/app/views/teams/show.html.haml b/app/views/teams/show.html.haml new file mode 100644 index 00000000000..9acbf3e1ecf --- /dev/null +++ b/app/views/teams/show.html.haml @@ -0,0 +1,30 @@ += render "team_head" + +.projects + .activities.span8 + = link_to dashboard_path, class: 'btn very_small' do + ← To dashboard +   + %span.cgray Events and projects are filtered in scope of team + %hr + - if @events.any? + .content_list + - else + %p.nothing_here_message Projects activity will be displayed here + .loading.hide + .side.span4 + = render "projects", projects: @projects + %div + %span.rss-icon + = link_to dashboard_path(:atom, { private_token: current_user.private_token }) do + = image_tag "rss_ui.png", title: "feed" + %strong News Feed + + %hr + .gitlab-promo + = link_to "Homepage", "http://gitlabhq.com" + = link_to "Blog", "http://blog.gitlabhq.com" + = link_to "@gitlabhq", "https://twitter.com/gitlabhq" + +:javascript + $(function(){ Pager.init(20, true); }); diff --git a/config/routes.rb b/config/routes.rb index d364f80551e..4a6b0d0b74d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -130,6 +130,20 @@ Gitlab::Application.routes.draw do end end + resources :teams do + member do + get :issues + get :merge_requests + get :search + post :delegate_projects + delete :relegate_project + put :update_access + end + collection do + get :search + end + end + resources :projects, constraints: { id: /[^\/]+/ }, only: [:new, :create] devise_for :users, controllers: { omniauth_callbacks: :omniauth_callbacks, registrations: :registrations } diff --git a/features/steps/userteams/userteams.rb b/features/steps/userteams/userteams.rb new file mode 100644 index 00000000000..59ec3d2de6e --- /dev/null +++ b/features/steps/userteams/userteams.rb @@ -0,0 +1,250 @@ +class Userteams < Spinach::FeatureSteps + include SharedAuthentication + include SharedPaths + include SharedProject + + When 'I do not have teams with me' do + UserTeam.with_member(current_user).destroy_all + end + + Then 'I should see dashboard page without teams info block' do + page.has_no_css?(".teams_box").must_equal true + end + + When 'I have teams with my membership' do + team = create :user_team + team.add_member(current_user, UserTeam.access_roles["Master"], true) + end + + Then 'I should see dashboard page with teams information block' do + page.should have_css(".teams_box") + end + + When 'exist user teams' do + team = create :user_team + team.add_member(current_user, UserTeam.access_roles["Master"], true) + end + + And 'I click on "All teams" link' do + click_link("All Teams") + end + + Then 'I should see "All teams" page' do + current_path.should == teams_path + end + + And 'I should see exist teams in teams list' do + team = UserTeam.last + find_in_list(".teams_list tr", team).must_equal true + end + + When 'I click to "New team" link' do + click_link("New Team") + end + + And 'I submit form with new team info' do + fill_in 'name', with: 'gitlab' + click_button 'Create team' + end + + Then 'I should be redirected to new team page' do + team = UserTeam.last + current_path.should == team_path(team) + end + + When 'I have teams with projects and members' do + team = create :user_team + @project = create :project + team.add_member(current_user, UserTeam.access_roles["Master"], true) + team.assign_to_project(@project, UserTeam.access_roles["Master"]) + @event = create(:closed_issue_event, project: @project) + end + + When 'I visit team page' do + visit team_path(UserTeam.last) + end + + Then 'I should see projects list' do + page.should have_css(".projects_box") + projects_box = find(".projects_box") + projects_box.should have_content(@project.name) + end + + And 'project from team has issues assigned to me' do + team = UserTeam.last + team.projects.each do |project| + project.issues << create(:issue, assignee: current_user) + end + end + + When 'I visit team issues page' do + team = UserTeam.last + visit issues_team_path(team) + end + + Then 'I should see issues from this team assigned to me' do + team = UserTeam.last + team.projects.each do |project| + project.issues.assigned(current_user).each do |issue| + page.should have_content issue.title + end + end + end + + Given 'I have team with projects and members' do + team = create :user_team + project = create :project + user = create :user + team.add_member(current_user, UserTeam.access_roles["Master"], true) + team.add_member(user, UserTeam.access_roles["Developer"], false) + team.assign_to_project(project, UserTeam.access_roles["Master"]) + end + + Given 'project from team has issues assigned to teams members' do + team = UserTeam.last + team.projects.each do |project| + team.members.each do |member| + project.issues << create(:issue, assignee: member) + end + end + end + + Then 'I should see issues from this team assigned to teams members' do + team = UserTeam.last + team.projects.each do |project| + team.members.each do |member| + project.issues.assigned(member).each do |issue| + page.should have_content issue.title + end + end + end + end + + Given 'project from team has merge requests assigned to me' do + team = UserTeam.last + team.projects.each do |project| + team.members.each do |member| + 3.times { project.merge_requests << create(:merge_request, assignee: member) } + end + end + end + + When 'I visit team merge requests page' do + team = UserTeam.last + visit merge_requests_team_path(team) + end + + Then 'I should see merge requests from this team assigned to me' do + team = UserTeam.last + team.projects.each do |project| + team.members.each do |member| + project.issues.assigned(member).each do |merge_request| + page.should have_content merge_request.title + end + end + end + end + + Given 'project from team has merge requests assigned to team members' do + team = UserTeam.last + team.projects.each do |project| + team.members.each do |member| + 3.times { project.merge_requests << create(:merge_request, assignee: member) } + end + end + end + + Then 'I should see merge requests from this team assigned to me' do + team = UserTeam.last + team.projects.each do |project| + team.members.each do |member| + project.issues.assigned(member).each do |merge_request| + page.should have_content merge_request.title + end + end + end + end + + Given 'I have new user "John"' do + create :user, name: "John" + end + + When 'I visit team people page' do + team = UserTeam.last + visit team_members_path(team) + end + + And 'I select user "John" from list with role "Reporter"' do + pending 'step not implemented' + end + + Then 'I should see user "John" in team list' do + user = User.find_by_name("John") + team_members_list = find(".team-table") + team_members_list.should have_content user.name + end + + And 'I have my own project without teams' do + project = create :project, creator: current_user + end + + And 'I visit my team page' do + team = UserTeam.last + visit team_path(team) + end + + When 'I click on link "Projects"' do + click_link "Projects" + end + + Then 'I should see form with my own project in avaliable projects list' do + project = current_user.projects.first + projects_select = find("#project_ids") + projects_select.should have_content(project.name) + end + + When 'I submit form with selected project and max access' do + project = current_user.projects.first + within "#team_projects" do + select project.name, :from => "project_ids" + select "Reporter", :from => "greatest_project_access" + end + click_button "Add" + end + + Then 'I should see my own project in team projects list' do + project = current_user.projects.first + projects = all("table .project") + projects.each do |project_row| + project_row.should have_content(project.name) + end + end + + When 'I click link "New Team Member"' do + click_link "New Team Member" + end + + protected + + def current_team + @user_team ||= Team.first + end + + def project + current_team.projects.first + end + + def assigned_to_user key, user + project.send(key).where(assignee_id: user) + end + + def find_in_list(selector, item) + members_list = all(selector) + entered = false + members_list.each do |member_item| + entered = true if member_item.has_content?(item.name) + end + entered + end + +end diff --git a/features/teams/team.feature b/features/teams/team.feature new file mode 100644 index 00000000000..d914313efb6 --- /dev/null +++ b/features/teams/team.feature @@ -0,0 +1,75 @@ +Feature: UserTeams + Background: + Given I sign in as a user + And I own project "Shop" + And project "Shop" has push event + + Scenario: No teams, no dashboard info block + When I do not have teams with me + And I visit dashboard page + Then I should see dashboard page without teams info block + + Scenario: I should see teams info block + When I have teams with my membership + And I visit dashboard page + Then I should see dashboard page with teams information block + + Scenario: I should see all teams list + When exist user teams + And I visit dashboard page + And I click on "All teams" link + Then I should see "All teams" page + And I should see exist teams in teams list + + Scenario: I should can create new team + When I have teams with my membership + And I visit dashboard page + When I click to "New team" link + And I submit form with new team info + Then I should be redirected to new team page + + Scenario: I should see team dashboard list + When I have teams with projects and members + When I visit team page + Then I should see projects list + + Scenario: I should see team issues list + Given I have team with projects and members + And project from team has issues assigned to me + When I visit team issues page + Then I should see issues from this team assigned to me + + Scenario: I should see teams members issues list + Given I have team with projects and members + Given project from team has issues assigned to teams members + When I visit team issues page + Then I should see issues from this team assigned to teams members + + Scenario: I should see team merge requests list + Given I have team with projects and members + Given project from team has merge requests assigned to me + When I visit team merge requests page + Then I should see merge requests from this team assigned to me + + Scenario: I should see teams members merge requests list + Given I have team with projects and members + Given project from team has merge requests assigned to team members + When I visit team merge requests page + Then I should see merge requests from this team assigned to me + + Scenario: I should add user to projects in Team + Given I have team with projects and members + Given I have new user "John" + When I visit team people page + When I click link "New Team Member" + And I select user "John" from list with role "Reporter" + Then I should see user "John" in team list + + Scenario: I should assign my team to my own project + Given I have team with projects and members + And I have my own project without teams + And I visit my team page + When I click on link "Projects" + Then I should see form with my own project in avaliable projects list + When I submit form with selected project and max access + Then I should see my own project in team projects list From 7d3efec7d190948423d7e40a3f87e2d62b4ea808 Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Sat, 19 Jan 2013 21:32:55 +0400 Subject: [PATCH 04/56] Add ability to teams --- app/models/ability.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/models/ability.rb b/app/models/ability.rb index 9d33501fdbc..63d720164a1 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -8,6 +8,7 @@ class Ability when "Snippet" then snippet_abilities(object, subject) when "MergeRequest" then merge_request_abilities(object, subject) when "Group", "Namespace" then group_abilities(object, subject) + when "UserTeam" then user_team_abilities(object, subject) else [] end end @@ -110,6 +111,22 @@ class Ability rules.flatten end + def user_team_abilities user, team + rules = [] + + # Only group owner and administrators can manage group + if team.owner == user || team.admin?(user) || user.admin? + rules << [ :manage_user_team ] + end + + if team.owner == user || user.admin? + rules << [ :admin_user_team ] + end + + rules.flatten + end + + [:issue, :note, :snippet, :merge_request].each do |name| define_method "#{name}_abilities" do |user, subject| if subject.author == user From 911f6eb1067f27606c9f6f1f8e554fba0cf02d19 Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Sat, 19 Jan 2013 21:33:38 +0400 Subject: [PATCH 05/56] merge into public --- app/views/dashboard/_teams.html.haml | 23 +++++++++++++++++++++++ app/views/layouts/user_team.html.haml | 22 ++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 app/views/dashboard/_teams.html.haml create mode 100644 app/views/layouts/user_team.html.haml diff --git a/app/views/dashboard/_teams.html.haml b/app/views/dashboard/_teams.html.haml new file mode 100644 index 00000000000..cbf97b93097 --- /dev/null +++ b/app/views/dashboard/_teams.html.haml @@ -0,0 +1,23 @@ +.teams_box + %h5.title + My Teams + %small + (#{teams.count}) + %span.right + = link_to new_team_path, class: "btn very_small info" do + %i.icon-plus + New Team + %span.right + = link_to teams_path, class: "btn very_small info" do + %i.icon-user + All Teams + %ul.well-list + - teams.each do |team| + %li + = link_to team_path(id: team.path), class: dom_class(team) do + %strong.well-title= truncate(team.name, length: 35) + %span.arrow + → + %span.last_activity + %strong Projects: + %span= current_user.authorized_projects.in_team(team).count diff --git a/app/views/layouts/user_team.html.haml b/app/views/layouts/user_team.html.haml new file mode 100644 index 00000000000..bd3dfe0d418 --- /dev/null +++ b/app/views/layouts/user_team.html.haml @@ -0,0 +1,22 @@ +!!! 5 +%html{ lang: "en"} + = render "layouts/head", title: "#{@user_team.name}" + %body{class: "#{app_theme} application"} + = render "layouts/flash" + = render "layouts/head_panel", title: "#{@user_team.name}" + .container + %ul.main_menu + = nav_link(path: 'teams#show', html_options: {class: 'home'}) do + = link_to "Home", team_path(@user_team), title: "Home" + = nav_link(path: 'teams#issues') do + = link_to issues_team_path(@user_team) do + Issues + %span.count= Issue.opened.of_user_team(@user_team).count + = nav_link(path: 'teams#merge_requests') do + = link_to merge_requests_team_path(@user_team) do + Merge Requests + %span.count= MergeRequest.opened.of_user_team(@user_team).count + = nav_link(path: 'teams#search') do + = link_to "Search", search_team_path(@user_team) + + .content= yield From 360aa1b4075ba6ffa9927971c580db0059ab4842 Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Sat, 19 Jan 2013 21:43:07 +0400 Subject: [PATCH 06/56] Team core management --- lib/gitlab/user_team_manager.rb | 93 +++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 lib/gitlab/user_team_manager.rb diff --git a/lib/gitlab/user_team_manager.rb b/lib/gitlab/user_team_manager.rb new file mode 100644 index 00000000000..d010c79223e --- /dev/null +++ b/lib/gitlab/user_team_manager.rb @@ -0,0 +1,93 @@ +# UserTeamManager class +# +# Used for manage User teams with project repositories +module Gitlab + class UserTeamManager + class << self + def assign(team, project, access) + project = Project.find(project) unless project.is_a? Project + searched_project = team.user_team_project_relationships.find_by_project_id(project.id) + + unless searched_project.present? + team.user_team_project_relationships.create(project_id: project.id, greatest_access: access) + update_team_users_access_in_project(team, project) + end + end + + def resign(team, project) + project = Project.find(project) unless project.is_a? Project + + team.user_team_project_relationships.with_project(project).destroy_all + + update_team_users_access_in_project(team, project) + end + + def update_team_users_access_in_project(team, project) + members = team.members + members.each do |member| + update_team_user_access_in_project(team, member, project) + end + end + + def update_team_user_access_in_project(team, user, project) + granted_access = max_teams_member_permission_in_project(user, project) + + project_team_user = UsersProject.find_by_user_id_and_project_id(user.id, project.id) + + if project_team_user.present? + project_team_user.destroy + end + + if project_team_user.blank? && granted_access > 0 + UsersProject.add_users_into_projects([project.id], [user.id], granted_access) + end + end + + def max_teams_member_permission_in_project(user, project, teams = nil) + result_access = 0 + + user_teams = project.user_teams.with_member(user) + + teams ||= user_teams + + if teams.any? + teams.each do |team| + granted_access = max_team_member_permission_in_project(team, user, project) + result_access = [granted_access, result_access].max + end + end + result_access + end + + def max_team_member_permission_in_project(team, user, project) + member_access = team.default_projects_access(user) + team_access = team.user_team_project_relationships.find_by_project_id(project.id).greatest_access + + [team_access, member_access].min + end + + def add_member_into_team(team, user, access, admin) + user = User.find(user) unless user.is_a? User + + team.user_team_user_relationships.create(user_id: user.id, permission: access, group_admin: admin) + team.projects.each do |project| + update_team_user_access_in_project(team, user, project) + end + end + + def remove_member_from_team(team, user) + user = User.find(user) unless user.is_a? User + + team.user_team_user_relationships.with_user(user).destroy_all + other_teams = [] + team.projects.each do |project| + other_teams << project.user_teams.with_member(user) + end + other_teams.uniq + unless other_teams.any? + UsersProject.in_projects(team.projects).with_user(user).destroy_all + end + end + end + end +end From ea6f46cb87c7ba8c0c620a8ff954f203b3276a7c Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Sat, 19 Jan 2013 21:47:08 +0400 Subject: [PATCH 07/56] Team members public section --- app/controllers/teams/members_controller.rb | 58 ++++++++++++++++++++ app/views/teams/members/_form.html.haml | 23 ++++++++ app/views/teams/members/_show.html.haml | 31 +++++++++++ app/views/teams/members/_team.html.haml | 16 ++++++ app/views/teams/members/index.html.haml | 18 +++++++ app/views/teams/members/new.html.haml | 2 + app/views/teams/members/show.html.haml | 60 +++++++++++++++++++++ config/routes.rb | 4 ++ 8 files changed, 212 insertions(+) create mode 100644 app/controllers/teams/members_controller.rb create mode 100644 app/views/teams/members/_form.html.haml create mode 100644 app/views/teams/members/_show.html.haml create mode 100644 app/views/teams/members/_team.html.haml create mode 100644 app/views/teams/members/index.html.haml create mode 100644 app/views/teams/members/new.html.haml create mode 100644 app/views/teams/members/show.html.haml diff --git a/app/controllers/teams/members_controller.rb b/app/controllers/teams/members_controller.rb new file mode 100644 index 00000000000..ab1c2878331 --- /dev/null +++ b/app/controllers/teams/members_controller.rb @@ -0,0 +1,58 @@ +class Teams::MembersController < Teams::ApplicationController + # Authorize + before_filter :authorize_manage_user_team!, only: [:new, :edit] + + def index + @members = @user_team.members + end + + def show + @team_member = @user_team.members.find(params[:id]) + @events = @team_member.recent_events.limit(7) + end + + def new + @team_member = @user_team.members.new + end + + def create + users = User.where(id: params[:user_ids]) + + @project.team << [users, params[:default_project_access]] + + if params[:redirect_to] + redirect_to params[:redirect_to] + else + redirect_to project_team_index_path(@project) + end + end + + def update + @team_member = @user_team.members.find(params[:id]) + @team_member.update_attributes(params[:team_member]) + + unless @team_member.valid? + flash[:alert] = "User should have at least one role" + end + redirect_to team_member_path(@project) + end + + def destroy + @team_member = project.users_projects.find(params[:id]) + @team_member.destroy + + respond_to do |format| + format.html { redirect_to project_team_index_path(@project) } + format.js { render nothing: true } + end + end + + def apply_import + giver = Project.find(params[:source_project_id]) + status = @project.team.import(giver) + notice = status ? "Succesfully imported" : "Import failed" + + redirect_to project_team_members_path(project), notice: notice + end + +end diff --git a/app/views/teams/members/_form.html.haml b/app/views/teams/members/_form.html.haml new file mode 100644 index 00000000000..a963e462a78 --- /dev/null +++ b/app/views/teams/members/_form.html.haml @@ -0,0 +1,23 @@ +%h3.page_title + = "New Team member(s)" +%hr += form_for @team_member, as: :team_member, url: project_team_members_path(@project, @team_member) do |f| + -if @team_member.errors.any? + .alert-message.block-message.error + %ul + - @team_member.errors.full_messages.each do |msg| + %li= msg + + %h6 1. Choose people you want in the team + .clearfix + = f.label :user_ids, "People" + .input= select_tag(:user_ids, options_from_collection_for_select(User.active.not_in_project(@project).alphabetically, :id, :name), {data: {placeholder: "Select users"}, class: "chosen xxlarge", multiple: true}) + + %h6 2. Set access level for them + .clearfix + = f.label :project_access, "Project Access" + .input= select_tag :project_access, options_for_select(Project.access_options, @team_member.project_access), class: "project-access-select chosen" + + .actions + = f.submit 'Save', class: "btn save-btn" + = link_to "Cancel", project_team_index_path(@project), class: "btn cancel-btn" diff --git a/app/views/teams/members/_show.html.haml b/app/views/teams/members/_show.html.haml new file mode 100644 index 00000000000..dfe73c77652 --- /dev/null +++ b/app/views/teams/members/_show.html.haml @@ -0,0 +1,31 @@ +- user = member.user +- allow_admin = can? current_user, :manage_user_team, @user_team +%li{id: dom_id(member), class: "team_member_row user_#{user.id}"} + .row + .span5 + = link_to team_member_path(@user_team, user), title: user.name, class: "dark" do + = image_tag gravatar_icon(user.email, 40), class: "avatar s32" + = link_to team_member_path(@user_team, user), title: user.name, class: "dark" do + %strong= truncate(user.name, lenght: 40) + %br + %small.cgray= user.email + + .span6.right + - if allow_admin + .left.span2 + = form_for(member, as: :team_member, url: team_member_path(@user_team, user)) do |f| + = f.select :permission, options_for_select(UsersProject.access_roles, @user_team.default_projects_access(user)), {}, class: "medium project-access-select span2" + .left.span2 + %span + Admin access + = check_box_tag :group_admin + .right + - if current_user == user + %span.btn.disabled This is you! + - if @user_team.owner == user + %span.btn.disabled.success Owner + - elsif user.blocked + %span.btn.disabled.blocked Blocked + - elsif allow_admin + = link_to team_member_path(@user_team, user), confirm: remove_from_team_message(@user_team, user), method: :delete, class: "very_small btn danger" do + %i.icon-minus.icon-white diff --git a/app/views/teams/members/_team.html.haml b/app/views/teams/members/_team.html.haml new file mode 100644 index 00000000000..e1fbf6d1e75 --- /dev/null +++ b/app/views/teams/members/_team.html.haml @@ -0,0 +1,16 @@ +- grouped_user_team_members(@user_team).each do |access, members| + .ui-box + %h5.title + = Project.access_options.key(access).pluralize + %small= members.size + %ul.well-list + - members.sort_by(&:user_name).each do |up| + = render(partial: 'teams/members/show', locals: {member: up}) + + +:javascript + $(function(){ + $('.repo-access-select, .project-access-select').live("change", function() { + $(this.form).submit(); + }); + }) diff --git a/app/views/teams/members/index.html.haml b/app/views/teams/members/index.html.haml new file mode 100644 index 00000000000..5b125b32769 --- /dev/null +++ b/app/views/teams/members/index.html.haml @@ -0,0 +1,18 @@ += render "teams/team_head" +%h3.page_title + Team Members + (#{@members.count}) + %small + Read more about project permissions + %strong= link_to "here", help_permissions_path, class: "vlink" + + - if can? current_user, :manage_user_team, @user_team + %span.right + = link_to new_team_member_path(@user_team), class: "btn success small grouped", title: "New Team Member" do + New Team Member +%hr + + +.clearfix +%div.team-table + = render partial: "teams/members/team", locals: {project: @user_team} diff --git a/app/views/teams/members/new.html.haml b/app/views/teams/members/new.html.haml new file mode 100644 index 00000000000..40eb4cebf08 --- /dev/null +++ b/app/views/teams/members/new.html.haml @@ -0,0 +1,2 @@ += render "projects/project_head" += render "team_members/form" diff --git a/app/views/teams/members/show.html.haml b/app/views/teams/members/show.html.haml new file mode 100644 index 00000000000..4008e8bd23e --- /dev/null +++ b/app/views/teams/members/show.html.haml @@ -0,0 +1,60 @@ +- allow_admin = can? current_user, :admin_project, @project +- user = @team_member.user + +.team_member_show + - if can? current_user, :admin_project, @project + = link_to 'Remove from team', project_team_member_path(project_id: @project, id: @team_member.id), confirm: 'Are you sure?', method: :delete, class: "right btn danger" + .profile_avatar_holder + = image_tag gravatar_icon(user.email, 60), class: "borders" + %h3.page_title + = user.name + %small (@#{user.username}) + + %hr + .back_link + %br + = link_to project_team_index_path(@project), class: "" do + ← To team list + %br + .row + .span6 + %table.lite + %tr + %td Email + %td= mail_to user.email + %tr + %td Skype + %td= user.skype + - unless user.linkedin.blank? + %tr + %td LinkedIn + %td= user.linkedin + - unless user.twitter.blank? + %tr + %td Twitter + %td= user.twitter + - unless user.bio.blank? + %tr + %td Bio + %td= user.bio + .span6 + %table.lite + %tr + %td Member since + %td= @team_member.created_at.stamp("Aug 21, 2011") + %tr + %td + Project Access: + %small (#{link_to "read more", help_permissions_path, class: "vlink"}) + %td + = form_for(@team_member, as: :team_member, url: project_team_member_path(@project, @team_member)) do |f| + = f.select :project_access, options_for_select(Project.access_options, @team_member.project_access), {}, class: "project-access-select", disabled: !allow_admin + %hr + = render @events +:javascript + $(function(){ + $('.repo-access-select, .project-access-select').live("change", function() { + $(this.form).submit(); + }); + }) + diff --git a/config/routes.rb b/config/routes.rb index 4a6b0d0b74d..44678ca0266 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -139,6 +139,10 @@ Gitlab::Application.routes.draw do delete :relegate_project put :update_access end + scope module: :teams do + resources :members + end + end collection do get :search end From a96cf3ad09c06fb5bfe668a77edc5d7adb2d092f Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Sat, 19 Jan 2013 21:48:05 +0400 Subject: [PATCH 08/56] Team projects public section --- app/controllers/teams/projects_controller.rb | 21 ++++++++++++ app/views/teams/projects/edit.html.haml | 4 +++ app/views/teams/projects/index.html.haml | 34 ++++++++++++++++++++ app/views/teams/projects/new.html.haml | 4 +++ app/views/teams/projects/show.html.haml | 4 +++ config/routes.rb | 2 ++ 6 files changed, 69 insertions(+) create mode 100644 app/controllers/teams/projects_controller.rb create mode 100644 app/views/teams/projects/edit.html.haml create mode 100644 app/views/teams/projects/index.html.haml create mode 100644 app/views/teams/projects/new.html.haml create mode 100644 app/views/teams/projects/show.html.haml diff --git a/app/controllers/teams/projects_controller.rb b/app/controllers/teams/projects_controller.rb new file mode 100644 index 00000000000..796f37f6d5d --- /dev/null +++ b/app/controllers/teams/projects_controller.rb @@ -0,0 +1,21 @@ +class Teams::ProjectsController < Teams::ApplicationController + def index + @projects = @user_team.projects + @avaliable_projects = current_user.admin? ? Project.without_team(@user_team) : (Project.personal(current_user) + current_user.projects).uniq + end + + def new + end + + def create + end + + def edit + end + + def update + end + + def destroy + end +end diff --git a/app/views/teams/projects/edit.html.haml b/app/views/teams/projects/edit.html.haml new file mode 100644 index 00000000000..66c9f0671ff --- /dev/null +++ b/app/views/teams/projects/edit.html.haml @@ -0,0 +1,4 @@ += render "teams/team_head" + +%h1 Teams::Projects#edit +%p Find me in app/views/teams/projects/edit.html.haml diff --git a/app/views/teams/projects/index.html.haml b/app/views/teams/projects/index.html.haml new file mode 100644 index 00000000000..66cb12a8421 --- /dev/null +++ b/app/views/teams/projects/index.html.haml @@ -0,0 +1,34 @@ += render "teams/team_head" + +%fieldset + %legend Projects (#{@user_team.projects.count}) + = form_tag delegate_projects_team_path(@user_team), id: "team_projects", class: "bulk_import", method: :post do + %table + %thead + %tr + %th Project name + %th Max access + %th + - @user_team.projects.each do |project| + %tr.project + %td + = link_to project.name_with_namespace, project + %td + %span= @user_team.human_max_project_access(project) + -# if current_user.can?(:manage_user_team, @user_team) + - relation = project.user_team_project_relationships.find_by_user_team_id(@user_team) + = form_for(relation, as: :project, url: team_project_path(@user_team, project)) do |f| + = f.select :greatest_access, options_for_select(UsersProject.access_roles, @user_team.max_project_access(project)), {}, class: "medium project-access-select span2" + + - if current_user.can?(:admin_user_team, @user_team) + %td.bgred + -#= link_to 'Edit max access', edit_project_team_path(@user_team, project), class: "btn small" + = link_to 'Relegate', relegate_project_team_path(@user_team, project_id: project.id), confirm: 'Remove project from team and move to global namespace. Are you sure?', method: :delete, class: "btn danger small" + - else + %td + + - if @avaliable_projects.any? + %tr + %td= select_tag :project_ids, options_from_collection_for_select(@avaliable_projects , :id, :name_with_namespace), multiple: true, data: {placeholder: 'Select projects'}, class: 'chosen span5' + %td= select_tag :greatest_project_access, options_for_select(Project.access_options), {class: "project-access-select chosen span3" } + %td= submit_tag 'Add', class: "btn primary" diff --git a/app/views/teams/projects/new.html.haml b/app/views/teams/projects/new.html.haml new file mode 100644 index 00000000000..24d2d4c34ca --- /dev/null +++ b/app/views/teams/projects/new.html.haml @@ -0,0 +1,4 @@ += render "teams/team_head" + +%h1 Teams::Projects#new +%p Find me in app/views/teams/projects/new.html.haml diff --git a/app/views/teams/projects/show.html.haml b/app/views/teams/projects/show.html.haml new file mode 100644 index 00000000000..66c9f0671ff --- /dev/null +++ b/app/views/teams/projects/show.html.haml @@ -0,0 +1,4 @@ += render "teams/team_head" + +%h1 Teams::Projects#edit +%p Find me in app/views/teams/projects/edit.html.haml diff --git a/config/routes.rb b/config/routes.rb index 44678ca0266..69ad2e68642 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,7 @@ require 'sidekiq/web' Gitlab::Application.routes.draw do + # # Search # @@ -141,6 +142,7 @@ Gitlab::Application.routes.draw do end scope module: :teams do resources :members + resources :projects, only: [:index, :show] do end end collection do From 3c6e144608b655ff1b43ec33baf020d19d460ba8 Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Sat, 19 Jan 2013 21:48:46 +0400 Subject: [PATCH 09/56] add dashboard teams block --- app/controllers/dashboard_controller.rb | 2 ++ app/views/dashboard/_sidebar.html.haml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index c0ec4708e0a..1322973489c 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -18,6 +18,8 @@ class DashboardController < ApplicationController @projects end + @teams = (UserTeam.with_member(current_user) + UserTeam.created_by(current_user)).uniq + @projects = @projects.page(params[:page]).per(30) @events = Event.in_projects(current_user.authorized_projects.pluck(:id)) diff --git a/app/views/dashboard/_sidebar.html.haml b/app/views/dashboard/_sidebar.html.haml index 9830cdf4f6b..7c6daf6ec31 100644 --- a/app/views/dashboard/_sidebar.html.haml +++ b/app/views/dashboard/_sidebar.html.haml @@ -1,3 +1,5 @@ +- if @teams.present? + = render "teams", teams: @teams - if @groups.present? = render "groups", groups: @groups = render "projects", projects: @projects From b9a7bcb6a45c343f51aea49bccf38722e49c949c Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Sat, 19 Jan 2013 21:49:15 +0400 Subject: [PATCH 10/56] add teams application controller --- app/controllers/teams/application_controller.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 app/controllers/teams/application_controller.rb diff --git a/app/controllers/teams/application_controller.rb b/app/controllers/teams/application_controller.rb new file mode 100644 index 00000000000..1cfb0e0991a --- /dev/null +++ b/app/controllers/teams/application_controller.rb @@ -0,0 +1,10 @@ +class Teams::ApplicationController < ApplicationController + before_filter :user_team, only: [:index, :show, :edit, :update, :destroy, :issues, :merge_requests, :search, :members] + + protected + + def user_team + @user_team ||= UserTeam.find_by_path(params[:team_id]) + end + +end From c098ac64309b2eb75195324fec08f552c839cf32 Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Sat, 19 Jan 2013 21:50:03 +0400 Subject: [PATCH 11/56] update stylesheets (for teams block) --- app/assets/stylesheets/sections/projects.scss | 1 + 1 file changed, 1 insertion(+) diff --git a/app/assets/stylesheets/sections/projects.scss b/app/assets/stylesheets/sections/projects.scss index 4bdc56d2884..ee2c379f2ab 100644 --- a/app/assets/stylesheets/sections/projects.scss +++ b/app/assets/stylesheets/sections/projects.scss @@ -7,6 +7,7 @@ @extend .right; .groups_box, + .teams_box, .projects_box { > .title { padding: 2px 15px; From b6458ae3b3afd872720e1abbd5e0a284752c2323 Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Sat, 19 Jan 2013 21:51:01 +0400 Subject: [PATCH 12/56] add into user decorator (presenter) to full user name --- app/decorators/user_decorator.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/decorators/user_decorator.rb b/app/decorators/user_decorator.rb index af9c6a63e75..b781f237352 100644 --- a/app/decorators/user_decorator.rb +++ b/app/decorators/user_decorator.rb @@ -8,4 +8,8 @@ class UserDecorator < ApplicationDecorator def tm_of(project) project.team_member_by_id(self.id) end + + def name_with_email + "#{name} (#{email})" + end end From 3a0d4865f63fd078b54436864c201a7c41a9ddf9 Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Sat, 19 Jan 2013 21:51:42 +0400 Subject: [PATCH 13/56] update projects show css selector --- app/views/admin/projects/show.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/projects/show.html.haml b/app/views/admin/projects/show.html.haml index 8e0d82328df..12cad07c9c4 100644 --- a/app/views/admin/projects/show.html.haml +++ b/app/views/admin/projects/show.html.haml @@ -116,7 +116,7 @@ %small (#{@project.users_projects.count}) %br -%table.zebra-striped +%table.zebra-striped.team_members %thead %tr %th Name From 17e9207dff39374ae33574b19123d1a1320fff4c Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Sat, 19 Jan 2013 21:53:03 +0400 Subject: [PATCH 14/56] add user team factories --- spec/factories/user_team_project_relationships.rb | 9 +++++++++ spec/factories/user_team_user_relationships.rb | 10 ++++++++++ spec/factories/user_teams.rb | 9 +++++++++ 3 files changed, 28 insertions(+) create mode 100644 spec/factories/user_team_project_relationships.rb create mode 100644 spec/factories/user_team_user_relationships.rb create mode 100644 spec/factories/user_teams.rb diff --git a/spec/factories/user_team_project_relationships.rb b/spec/factories/user_team_project_relationships.rb new file mode 100644 index 00000000000..fa0f26e7455 --- /dev/null +++ b/spec/factories/user_team_project_relationships.rb @@ -0,0 +1,9 @@ +# Read about factories at https://github.com/thoughtbot/factory_girl + +FactoryGirl.define do + factory :user_team_project_relationship do + project_id 1 + user_team_id 1 + greatest_access 1 + end +end diff --git a/spec/factories/user_team_user_relationships.rb b/spec/factories/user_team_user_relationships.rb new file mode 100644 index 00000000000..9b655e00686 --- /dev/null +++ b/spec/factories/user_team_user_relationships.rb @@ -0,0 +1,10 @@ +# Read about factories at https://github.com/thoughtbot/factory_girl + +FactoryGirl.define do + factory :user_team_user_relationship do + user_id 1 + user_team_id 1 + group_admin false + permission 1 + end +end diff --git a/spec/factories/user_teams.rb b/spec/factories/user_teams.rb new file mode 100644 index 00000000000..f4fe45cbb8a --- /dev/null +++ b/spec/factories/user_teams.rb @@ -0,0 +1,9 @@ +# Read about factories at https://github.com/thoughtbot/factory_girl + +FactoryGirl.define do + factory :user_team do + sequence(:name) { |n| "team#{n}" } + path { name.downcase.gsub(/\s/, '_') } + owner + end +end From a987f1469e2480559b675c251d49509f6200112f Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Sat, 19 Jan 2013 21:55:59 +0400 Subject: [PATCH 15/56] commit user team helper --- app/helpers/user_teams_helper.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 app/helpers/user_teams_helper.rb diff --git a/app/helpers/user_teams_helper.rb b/app/helpers/user_teams_helper.rb new file mode 100644 index 00000000000..01e10de52fb --- /dev/null +++ b/app/helpers/user_teams_helper.rb @@ -0,0 +1,26 @@ +module UserTeamsHelper + def team_filter_path(entity, options={}) + exist_opts = { + status: params[:status], + project_id: params[:project_id], + } + + options = exist_opts.merge(options) + + case entity + when 'issue' then + issues_team_path(@user_team, options) + when 'merge_request' + merge_requests_team_path(@user_team, options) + end + end + + def grouped_user_team_members(team) + team.user_team_user_relationships.sort_by(&:permission).reverse.group_by(&:permission) + end + + def remove_from_team_message(team, member) + "You are going to remove #{member.name} from #{team.name}. Are you sure?" + end + +end From c5f427b0a499136568bcf3cc738e5f1a8575e358 Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Sat, 19 Jan 2013 21:58:13 +0400 Subject: [PATCH 16/56] save commit --- app/views/teams/members/edit.html.haml | 2 + app/views/teams/members/import.html.haml | 17 ++++++ .../admin/teams_controller_spec.rb | 47 ++++++++++++++++ .../teams/members_controller_spec.rb | 47 ++++++++++++++++ .../teams/projects_controller_spec.rb | 47 ++++++++++++++++ spec/controllers/teams_controller_spec.rb | 54 +++++++++++++++++++ spec/helpers/admin/teams_helper_spec.rb | 15 ++++++ spec/helpers/teams/members_helper_spec.rb | 15 ++++++ spec/helpers/teams/projects_helper_spec.rb | 15 ++++++ spec/helpers/teams_helper_spec.rb | 15 ++++++ .../admin/teams/create.html.haml_spec.rb | 5 ++ .../admin/teams/destroy.html.haml_spec.rb | 5 ++ spec/views/admin/teams/edit.html.haml_spec.rb | 5 ++ .../views/admin/teams/index.html.haml_spec.rb | 5 ++ spec/views/admin/teams/show.html.haml_spec.rb | 5 ++ .../admin/teams/update.html.haml_spec.rb | 5 ++ spec/views/teams/create.html.haml_spec.rb | 5 ++ spec/views/teams/destroy.html.haml_spec.rb | 5 ++ spec/views/teams/edit.html.haml_spec.rb | 5 ++ spec/views/teams/index.html.haml_spec.rb | 5 ++ .../teams/members/create.html.haml_spec.rb | 5 ++ .../teams/members/destroy.html.haml_spec.rb | 5 ++ .../teams/members/edit.html.haml_spec.rb | 5 ++ .../teams/members/index.html.haml_spec.rb | 5 ++ .../views/teams/members/new.html.haml_spec.rb | 5 ++ .../teams/members/update.html.haml_spec.rb | 5 ++ spec/views/teams/new.html.haml_spec.rb | 5 ++ .../teams/projects/create.html.haml_spec.rb | 5 ++ .../teams/projects/destroy.html.haml_spec.rb | 5 ++ .../teams/projects/edit.html.haml_spec.rb | 5 ++ .../teams/projects/index.html.haml_spec.rb | 5 ++ .../teams/projects/new.html.haml_spec.rb | 5 ++ .../teams/projects/update.html.haml_spec.rb | 5 ++ spec/views/teams/show.html.haml_spec.rb | 5 ++ spec/views/teams/update.html.haml_spec.rb | 5 ++ 35 files changed, 399 insertions(+) create mode 100644 app/views/teams/members/edit.html.haml create mode 100644 app/views/teams/members/import.html.haml create mode 100644 spec/controllers/admin/teams_controller_spec.rb create mode 100644 spec/controllers/teams/members_controller_spec.rb create mode 100644 spec/controllers/teams/projects_controller_spec.rb create mode 100644 spec/controllers/teams_controller_spec.rb create mode 100644 spec/helpers/admin/teams_helper_spec.rb create mode 100644 spec/helpers/teams/members_helper_spec.rb create mode 100644 spec/helpers/teams/projects_helper_spec.rb create mode 100644 spec/helpers/teams_helper_spec.rb create mode 100644 spec/views/admin/teams/create.html.haml_spec.rb create mode 100644 spec/views/admin/teams/destroy.html.haml_spec.rb create mode 100644 spec/views/admin/teams/edit.html.haml_spec.rb create mode 100644 spec/views/admin/teams/index.html.haml_spec.rb create mode 100644 spec/views/admin/teams/show.html.haml_spec.rb create mode 100644 spec/views/admin/teams/update.html.haml_spec.rb create mode 100644 spec/views/teams/create.html.haml_spec.rb create mode 100644 spec/views/teams/destroy.html.haml_spec.rb create mode 100644 spec/views/teams/edit.html.haml_spec.rb create mode 100644 spec/views/teams/index.html.haml_spec.rb create mode 100644 spec/views/teams/members/create.html.haml_spec.rb create mode 100644 spec/views/teams/members/destroy.html.haml_spec.rb create mode 100644 spec/views/teams/members/edit.html.haml_spec.rb create mode 100644 spec/views/teams/members/index.html.haml_spec.rb create mode 100644 spec/views/teams/members/new.html.haml_spec.rb create mode 100644 spec/views/teams/members/update.html.haml_spec.rb create mode 100644 spec/views/teams/new.html.haml_spec.rb create mode 100644 spec/views/teams/projects/create.html.haml_spec.rb create mode 100644 spec/views/teams/projects/destroy.html.haml_spec.rb create mode 100644 spec/views/teams/projects/edit.html.haml_spec.rb create mode 100644 spec/views/teams/projects/index.html.haml_spec.rb create mode 100644 spec/views/teams/projects/new.html.haml_spec.rb create mode 100644 spec/views/teams/projects/update.html.haml_spec.rb create mode 100644 spec/views/teams/show.html.haml_spec.rb create mode 100644 spec/views/teams/update.html.haml_spec.rb diff --git a/app/views/teams/members/edit.html.haml b/app/views/teams/members/edit.html.haml new file mode 100644 index 00000000000..a2742977717 --- /dev/null +++ b/app/views/teams/members/edit.html.haml @@ -0,0 +1,2 @@ +%h1 Teams::Members#edit +%p Find me in app/views/teams/members/edit.html.haml \ No newline at end of file diff --git a/app/views/teams/members/import.html.haml b/app/views/teams/members/import.html.haml new file mode 100644 index 00000000000..de82f416248 --- /dev/null +++ b/app/views/teams/members/import.html.haml @@ -0,0 +1,17 @@ += render "projects/project_head" + +%h3.page_title + = "Import team from another project" +%hr +%p.slead + Read more about team import #{link_to "here", '#', class: 'vlink'}. += form_tag apply_import_project_team_members_path(@project), method: 'post' do + %p.slead Choose project you want to use as team source: + .padded + = label_tag :source_project_id, "Project" + .input= select_tag(:source_project_id, options_from_collection_for_select(current_user.authorized_projects, :id, :name_with_namespace), prompt: "Select project", class: "chosen xxlarge", required: true) + + .actions + = submit_tag 'Import', class: "btn save-btn" + = link_to "Cancel", project_team_index_path(@project), class: "btn cancel-btn" + diff --git a/spec/controllers/admin/teams_controller_spec.rb b/spec/controllers/admin/teams_controller_spec.rb new file mode 100644 index 00000000000..02d8f86a79d --- /dev/null +++ b/spec/controllers/admin/teams_controller_spec.rb @@ -0,0 +1,47 @@ +require 'spec_helper' + +describe Admin::TeamsController do + + describe "GET 'index'" do + it "returns http success" do + get 'index' + response.should be_success + end + end + + describe "GET 'show'" do + it "returns http success" do + get 'show' + response.should be_success + end + end + + describe "GET 'create'" do + it "returns http success" do + get 'create' + response.should be_success + end + end + + describe "GET 'edit'" do + it "returns http success" do + get 'edit' + response.should be_success + end + end + + describe "GET 'update'" do + it "returns http success" do + get 'update' + response.should be_success + end + end + + describe "GET 'destroy'" do + it "returns http success" do + get 'destroy' + response.should be_success + end + end + +end diff --git a/spec/controllers/teams/members_controller_spec.rb b/spec/controllers/teams/members_controller_spec.rb new file mode 100644 index 00000000000..e1ac558a6cd --- /dev/null +++ b/spec/controllers/teams/members_controller_spec.rb @@ -0,0 +1,47 @@ +require 'spec_helper' + +describe Teams::MembersController do + + describe "GET 'index'" do + it "returns http success" do + get 'index' + response.should be_success + end + end + + describe "GET 'new'" do + it "returns http success" do + get 'new' + response.should be_success + end + end + + describe "GET 'create'" do + it "returns http success" do + get 'create' + response.should be_success + end + end + + describe "GET 'edit'" do + it "returns http success" do + get 'edit' + response.should be_success + end + end + + describe "GET 'update'" do + it "returns http success" do + get 'update' + response.should be_success + end + end + + describe "GET 'destroy'" do + it "returns http success" do + get 'destroy' + response.should be_success + end + end + +end diff --git a/spec/controllers/teams/projects_controller_spec.rb b/spec/controllers/teams/projects_controller_spec.rb new file mode 100644 index 00000000000..b379c3721bb --- /dev/null +++ b/spec/controllers/teams/projects_controller_spec.rb @@ -0,0 +1,47 @@ +require 'spec_helper' + +describe Teams::ProjectsController do + + describe "GET 'index'" do + it "returns http success" do + get 'index' + response.should be_success + end + end + + describe "GET 'new'" do + it "returns http success" do + get 'new' + response.should be_success + end + end + + describe "GET 'create'" do + it "returns http success" do + get 'create' + response.should be_success + end + end + + describe "GET 'edit'" do + it "returns http success" do + get 'edit' + response.should be_success + end + end + + describe "GET 'update'" do + it "returns http success" do + get 'update' + response.should be_success + end + end + + describe "GET 'destroy'" do + it "returns http success" do + get 'destroy' + response.should be_success + end + end + +end diff --git a/spec/controllers/teams_controller_spec.rb b/spec/controllers/teams_controller_spec.rb new file mode 100644 index 00000000000..923261fce9c --- /dev/null +++ b/spec/controllers/teams_controller_spec.rb @@ -0,0 +1,54 @@ +require 'spec_helper' + +describe TeamsController do + + describe "GET 'index'" do + it "returns http success" do + get 'index' + response.should be_success + end + end + + describe "GET 'show'" do + it "returns http success" do + get 'show' + response.should be_success + end + end + + describe "GET 'new'" do + it "returns http success" do + get 'new' + response.should be_success + end + end + + describe "GET 'edit'" do + it "returns http success" do + get 'edit' + response.should be_success + end + end + + describe "GET 'update'" do + it "returns http success" do + get 'update' + response.should be_success + end + end + + describe "GET 'create'" do + it "returns http success" do + get 'create' + response.should be_success + end + end + + describe "GET 'destroy'" do + it "returns http success" do + get 'destroy' + response.should be_success + end + end + +end diff --git a/spec/helpers/admin/teams_helper_spec.rb b/spec/helpers/admin/teams_helper_spec.rb new file mode 100644 index 00000000000..5ed6073297b --- /dev/null +++ b/spec/helpers/admin/teams_helper_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +# Specs in this file have access to a helper object that includes +# the Admin::TeamsHelper. For example: +# +# describe Admin::TeamsHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# helper.concat_strings("this","that").should == "this that" +# end +# end +# end +describe Admin::TeamsHelper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/helpers/teams/members_helper_spec.rb b/spec/helpers/teams/members_helper_spec.rb new file mode 100644 index 00000000000..a8e227aa063 --- /dev/null +++ b/spec/helpers/teams/members_helper_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +# Specs in this file have access to a helper object that includes +# the Teams::MembersHelper. For example: +# +# describe Teams::MembersHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# helper.concat_strings("this","that").should == "this that" +# end +# end +# end +describe Teams::MembersHelper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/helpers/teams/projects_helper_spec.rb b/spec/helpers/teams/projects_helper_spec.rb new file mode 100644 index 00000000000..836d1dca018 --- /dev/null +++ b/spec/helpers/teams/projects_helper_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +# Specs in this file have access to a helper object that includes +# the Teams::ProjectsHelper. For example: +# +# describe Teams::ProjectsHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# helper.concat_strings("this","that").should == "this that" +# end +# end +# end +describe Teams::ProjectsHelper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/helpers/teams_helper_spec.rb b/spec/helpers/teams_helper_spec.rb new file mode 100644 index 00000000000..95726163e35 --- /dev/null +++ b/spec/helpers/teams_helper_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +# Specs in this file have access to a helper object that includes +# the TeamsHelper. For example: +# +# describe TeamsHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# helper.concat_strings("this","that").should == "this that" +# end +# end +# end +describe TeamsHelper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/views/admin/teams/create.html.haml_spec.rb b/spec/views/admin/teams/create.html.haml_spec.rb new file mode 100644 index 00000000000..27f57d89693 --- /dev/null +++ b/spec/views/admin/teams/create.html.haml_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe "teams/create.html.haml" do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/views/admin/teams/destroy.html.haml_spec.rb b/spec/views/admin/teams/destroy.html.haml_spec.rb new file mode 100644 index 00000000000..87670e4dc66 --- /dev/null +++ b/spec/views/admin/teams/destroy.html.haml_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe "teams/destroy.html.haml" do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/views/admin/teams/edit.html.haml_spec.rb b/spec/views/admin/teams/edit.html.haml_spec.rb new file mode 100644 index 00000000000..5180d713f7f --- /dev/null +++ b/spec/views/admin/teams/edit.html.haml_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe "teams/edit.html.haml" do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/views/admin/teams/index.html.haml_spec.rb b/spec/views/admin/teams/index.html.haml_spec.rb new file mode 100644 index 00000000000..7a0d69bd316 --- /dev/null +++ b/spec/views/admin/teams/index.html.haml_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe "teams/index.html.haml" do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/views/admin/teams/show.html.haml_spec.rb b/spec/views/admin/teams/show.html.haml_spec.rb new file mode 100644 index 00000000000..b7f7b669c2e --- /dev/null +++ b/spec/views/admin/teams/show.html.haml_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe "teams/show.html.haml" do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/views/admin/teams/update.html.haml_spec.rb b/spec/views/admin/teams/update.html.haml_spec.rb new file mode 100644 index 00000000000..b28cfa4f699 --- /dev/null +++ b/spec/views/admin/teams/update.html.haml_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe "teams/update.html.haml" do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/views/teams/create.html.haml_spec.rb b/spec/views/teams/create.html.haml_spec.rb new file mode 100644 index 00000000000..27f57d89693 --- /dev/null +++ b/spec/views/teams/create.html.haml_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe "teams/create.html.haml" do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/views/teams/destroy.html.haml_spec.rb b/spec/views/teams/destroy.html.haml_spec.rb new file mode 100644 index 00000000000..87670e4dc66 --- /dev/null +++ b/spec/views/teams/destroy.html.haml_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe "teams/destroy.html.haml" do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/views/teams/edit.html.haml_spec.rb b/spec/views/teams/edit.html.haml_spec.rb new file mode 100644 index 00000000000..5180d713f7f --- /dev/null +++ b/spec/views/teams/edit.html.haml_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe "teams/edit.html.haml" do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/views/teams/index.html.haml_spec.rb b/spec/views/teams/index.html.haml_spec.rb new file mode 100644 index 00000000000..7a0d69bd316 --- /dev/null +++ b/spec/views/teams/index.html.haml_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe "teams/index.html.haml" do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/views/teams/members/create.html.haml_spec.rb b/spec/views/teams/members/create.html.haml_spec.rb new file mode 100644 index 00000000000..b6f817617e4 --- /dev/null +++ b/spec/views/teams/members/create.html.haml_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe "members/create.html.haml" do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/views/teams/members/destroy.html.haml_spec.rb b/spec/views/teams/members/destroy.html.haml_spec.rb new file mode 100644 index 00000000000..3ff1634461c --- /dev/null +++ b/spec/views/teams/members/destroy.html.haml_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe "members/destroy.html.haml" do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/views/teams/members/edit.html.haml_spec.rb b/spec/views/teams/members/edit.html.haml_spec.rb new file mode 100644 index 00000000000..3e952e898a9 --- /dev/null +++ b/spec/views/teams/members/edit.html.haml_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe "members/edit.html.haml" do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/views/teams/members/index.html.haml_spec.rb b/spec/views/teams/members/index.html.haml_spec.rb new file mode 100644 index 00000000000..363430d769f --- /dev/null +++ b/spec/views/teams/members/index.html.haml_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe "members/index.html.haml" do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/views/teams/members/new.html.haml_spec.rb b/spec/views/teams/members/new.html.haml_spec.rb new file mode 100644 index 00000000000..f03eed1f29f --- /dev/null +++ b/spec/views/teams/members/new.html.haml_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe "members/new.html.haml" do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/views/teams/members/update.html.haml_spec.rb b/spec/views/teams/members/update.html.haml_spec.rb new file mode 100644 index 00000000000..43b84bad99b --- /dev/null +++ b/spec/views/teams/members/update.html.haml_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe "members/update.html.haml" do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/views/teams/new.html.haml_spec.rb b/spec/views/teams/new.html.haml_spec.rb new file mode 100644 index 00000000000..8ef621b708f --- /dev/null +++ b/spec/views/teams/new.html.haml_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe "teams/new.html.haml" do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/views/teams/projects/create.html.haml_spec.rb b/spec/views/teams/projects/create.html.haml_spec.rb new file mode 100644 index 00000000000..74c4ee2d837 --- /dev/null +++ b/spec/views/teams/projects/create.html.haml_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe "projects/create.html.haml" do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/views/teams/projects/destroy.html.haml_spec.rb b/spec/views/teams/projects/destroy.html.haml_spec.rb new file mode 100644 index 00000000000..b3eee48f38b --- /dev/null +++ b/spec/views/teams/projects/destroy.html.haml_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe "projects/destroy.html.haml" do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/views/teams/projects/edit.html.haml_spec.rb b/spec/views/teams/projects/edit.html.haml_spec.rb new file mode 100644 index 00000000000..ef41b7b0814 --- /dev/null +++ b/spec/views/teams/projects/edit.html.haml_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe "projects/edit.html.haml" do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/views/teams/projects/index.html.haml_spec.rb b/spec/views/teams/projects/index.html.haml_spec.rb new file mode 100644 index 00000000000..8cf0dbcd954 --- /dev/null +++ b/spec/views/teams/projects/index.html.haml_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe "projects/index.html.haml" do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/views/teams/projects/new.html.haml_spec.rb b/spec/views/teams/projects/new.html.haml_spec.rb new file mode 100644 index 00000000000..9ee68e5ae05 --- /dev/null +++ b/spec/views/teams/projects/new.html.haml_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe "projects/new.html.haml" do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/views/teams/projects/update.html.haml_spec.rb b/spec/views/teams/projects/update.html.haml_spec.rb new file mode 100644 index 00000000000..fdaafd3924b --- /dev/null +++ b/spec/views/teams/projects/update.html.haml_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe "projects/update.html.haml" do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/views/teams/show.html.haml_spec.rb b/spec/views/teams/show.html.haml_spec.rb new file mode 100644 index 00000000000..b7f7b669c2e --- /dev/null +++ b/spec/views/teams/show.html.haml_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe "teams/show.html.haml" do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/views/teams/update.html.haml_spec.rb b/spec/views/teams/update.html.haml_spec.rb new file mode 100644 index 00000000000..b28cfa4f699 --- /dev/null +++ b/spec/views/teams/update.html.haml_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe "teams/update.html.haml" do + pending "add some examples to (or delete) #{__FILE__}" +end From 6d1c566ec9f8506500f997c5ab33915e98826f3f Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Sat, 19 Jan 2013 22:52:55 +0400 Subject: [PATCH 17/56] Rename Team class to ProjectTeam --- app/models/project.rb | 2 +- app/models/{team.rb => project_team.rb} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename app/models/{team.rb => project_team.rb} (99%) diff --git a/app/models/project.rb b/app/models/project.rb index fa314d9c5f0..a21cc3f6f40 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -127,7 +127,7 @@ class Project < ActiveRecord::Base end def team - @team ||= Team.new(self) + @team ||= ProjectTeam.new(self) end def repository diff --git a/app/models/team.rb b/app/models/project_team.rb similarity index 99% rename from app/models/team.rb rename to app/models/project_team.rb index 51f4ff68d7b..2cc76974987 100644 --- a/app/models/team.rb +++ b/app/models/project_team.rb @@ -1,4 +1,4 @@ -class Team +class ProjectTeam attr_accessor :project def initialize(project) From 845f146518783e7122d5ff9c593ffe3c6a59cecf Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Sun, 20 Jan 2013 11:46:15 +0400 Subject: [PATCH 18/56] fix simples errors in tests --- features/steps/admin/admin_teams.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/features/steps/admin/admin_teams.rb b/features/steps/admin/admin_teams.rb index 7bb1dacabcb..bba60ec496b 100644 --- a/features/steps/admin/admin_teams.rb +++ b/features/steps/admin/admin_teams.rb @@ -50,7 +50,7 @@ class AdminTeams < Spinach::FeatureSteps When 'I select user "John" from user list as "Developer"' do @user ||= User.find_by_name("John") within "#team_members" do - select user.name, :from => "user_ids" + select @user.name, :from => "user_ids" select "Developer", :from => "default_project_access" end end @@ -61,7 +61,7 @@ class AdminTeams < Spinach::FeatureSteps Then 'I should see "John" in teams members list as "Developer"' do @user ||= User.find_by_name("John") - find_in_list("#members_list .member", user).must_equal true + find_in_list("#members_list .member", @user).must_equal true end When 'I visit "John" user admin page' do @@ -185,7 +185,7 @@ class AdminTeams < Spinach::FeatureSteps end Then 'I should be redirected to "HardCoders" team admin page' do - current_path.should admin_team_peth(UserTeam.find_by_name("HardCoders")) + current_path.should == admin_team_path(UserTeam.find_by_name("HardCoders")) end And 'I should not to see "Jimm" user in members list' do From 2984716870a26b704a04e4ac4e72bfbc05750f73 Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Sun, 20 Jan 2013 12:08:46 +0400 Subject: [PATCH 19/56] Admin rename team page is fixed --- app/views/admin/teams/edit.html.haml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/app/views/admin/teams/edit.html.haml b/app/views/admin/teams/edit.html.haml index 15ec267f45f..b2499ef6b8b 100644 --- a/app/views/admin/teams/edit.html.haml +++ b/app/views/admin/teams/edit.html.haml @@ -1,6 +1,6 @@ %h3.page_title Rename Team %hr -= form_for [:admin, @team] do |f| += form_for @team, url: admin_team_path(@team), method: :put do |f| - if @team.errors.any? .alert-message.block-message.error %span= @team.errors.full_messages.first @@ -10,18 +10,13 @@ .input = f.text_field :name, placeholder: "Example Team", class: "xxlarge" - - .clearfix.team_name_holder = f.label :path do %span.cred Team path is .input = f.text_field :path, placeholder: "example-team", class: "xxlarge danger" %ul.cred - %li Changing team path can have unintended side effects. - %li Renaming team path will rename directory for all related projects %li It will change web url for access team and team projects. - %li It will change the git path to repositories under this team. .form-actions = f.submit 'Rename team', class: "btn danger" From 9d318db48f4d76b8493aefa80e7b29c2ea3cc1cf Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Sun, 20 Jan 2013 15:20:50 +0400 Subject: [PATCH 20/56] Added the correct hierarchy of controllers for the administrative part --- .../{admin_controller.rb => admin/application_controller.rb} | 2 +- app/controllers/admin/dashboard_controller.rb | 2 +- app/controllers/admin/groups_controller.rb | 2 +- app/controllers/admin/hooks_controller.rb | 2 +- app/controllers/admin/logs_controller.rb | 2 +- app/controllers/admin/projects_controller.rb | 2 +- app/controllers/admin/resque_controller.rb | 2 +- app/controllers/admin/team_members_controller.rb | 2 +- app/controllers/admin/teams_controller.rb | 2 +- app/controllers/admin/users_controller.rb | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) rename app/controllers/{admin_controller.rb => admin/application_controller.rb} (82%) diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin/application_controller.rb similarity index 82% rename from app/controllers/admin_controller.rb rename to app/controllers/admin/application_controller.rb index bce9f692385..6a8f20f6047 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin/application_controller.rb @@ -1,7 +1,7 @@ # Provides a base class for Admin controllers to subclass # # Automatically sets the layout and ensures an administrator is logged in -class AdminController < ApplicationController +class Admin::ApplicationController < ApplicationController layout 'admin' before_filter :authenticate_admin! diff --git a/app/controllers/admin/dashboard_controller.rb b/app/controllers/admin/dashboard_controller.rb index f97c56b0b31..3c27b86180b 100644 --- a/app/controllers/admin/dashboard_controller.rb +++ b/app/controllers/admin/dashboard_controller.rb @@ -1,4 +1,4 @@ -class Admin::DashboardController < AdminController +class Admin::DashboardController < Admin::ApplicationController def index @projects = Project.order("created_at DESC").limit(10) @users = User.order("created_at DESC").limit(10) diff --git a/app/controllers/admin/groups_controller.rb b/app/controllers/admin/groups_controller.rb index 90dbda3eeea..f552fb595b8 100644 --- a/app/controllers/admin/groups_controller.rb +++ b/app/controllers/admin/groups_controller.rb @@ -1,4 +1,4 @@ -class Admin::GroupsController < AdminController +class Admin::GroupsController < Admin::ApplicationController before_filter :group, only: [:edit, :show, :update, :destroy, :project_update, :project_teams_update] def index diff --git a/app/controllers/admin/hooks_controller.rb b/app/controllers/admin/hooks_controller.rb index 91a1d633590..c5bf76f8c39 100644 --- a/app/controllers/admin/hooks_controller.rb +++ b/app/controllers/admin/hooks_controller.rb @@ -1,4 +1,4 @@ -class Admin::HooksController < AdminController +class Admin::HooksController < Admin::ApplicationController def index @hooks = SystemHook.all @hook = SystemHook.new diff --git a/app/controllers/admin/logs_controller.rb b/app/controllers/admin/logs_controller.rb index 28c321a9e52..b999018dde4 100644 --- a/app/controllers/admin/logs_controller.rb +++ b/app/controllers/admin/logs_controller.rb @@ -1,2 +1,2 @@ -class Admin::LogsController < AdminController +class Admin::LogsController < Admin::ApplicationController end diff --git a/app/controllers/admin/projects_controller.rb b/app/controllers/admin/projects_controller.rb index fc2793a72e7..28d9bf01cce 100644 --- a/app/controllers/admin/projects_controller.rb +++ b/app/controllers/admin/projects_controller.rb @@ -1,4 +1,4 @@ -class Admin::ProjectsController < AdminController +class Admin::ProjectsController < Admin::ApplicationController before_filter :project, only: [:edit, :show, :update, :destroy, :team_update] def index diff --git a/app/controllers/admin/resque_controller.rb b/app/controllers/admin/resque_controller.rb index 9d8e7e3051f..7d489ab4876 100644 --- a/app/controllers/admin/resque_controller.rb +++ b/app/controllers/admin/resque_controller.rb @@ -1,4 +1,4 @@ -class Admin::ResqueController < AdminController +class Admin::ResqueController < Admin::ApplicationController def show end end diff --git a/app/controllers/admin/team_members_controller.rb b/app/controllers/admin/team_members_controller.rb index 073208057ca..3c85681cf66 100644 --- a/app/controllers/admin/team_members_controller.rb +++ b/app/controllers/admin/team_members_controller.rb @@ -1,4 +1,4 @@ -class Admin::TeamMembersController < AdminController +class Admin::TeamMembersController < Admin::ApplicationController def edit @admin_team_member = UsersProject.find(params[:id]) end diff --git a/app/controllers/admin/teams_controller.rb b/app/controllers/admin/teams_controller.rb index fd25d3fe219..5d9356e9095 100644 --- a/app/controllers/admin/teams_controller.rb +++ b/app/controllers/admin/teams_controller.rb @@ -1,4 +1,4 @@ -class Admin::TeamsController < AdminController +class Admin::TeamsController < Admin::ApplicationController before_filter :user_team, only: [ :edit, :show, :update, :destroy, :delegate_projects, :relegate_project, diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index 8669f5d1d38..659dd2f2ab0 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -1,4 +1,4 @@ -class Admin::UsersController < AdminController +class Admin::UsersController < Admin::ApplicationController def index @admin_users = User.scoped @admin_users = @admin_users.filter(params[:filter]) From 9804b7df68a0ba4a1b144bc652351ad77a38fc3f Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Sun, 20 Jan 2013 15:25:16 +0400 Subject: [PATCH 21/56] Move admin team members management to own controller --- .../admin/teams/application_controller.rb | 12 +++++ .../admin/teams/members_controller.rb | 35 +++++++++++++++ app/models/user_team.rb | 4 ++ app/views/admin/teams/members/_form.html.haml | 20 +++++++++ app/views/admin/teams/members/edit.html.haml | 16 +++++++ app/views/admin/teams/members/new.html.haml | 29 ++++++++++++ app/views/admin/teams/show.html.haml | 45 +++++++++---------- config/routes.rb | 3 ++ lib/gitlab/user_team_manager.rb | 32 +++++++++++++ 9 files changed, 173 insertions(+), 23 deletions(-) create mode 100644 app/controllers/admin/teams/application_controller.rb create mode 100644 app/controllers/admin/teams/members_controller.rb create mode 100644 app/views/admin/teams/members/_form.html.haml create mode 100644 app/views/admin/teams/members/edit.html.haml create mode 100644 app/views/admin/teams/members/new.html.haml diff --git a/app/controllers/admin/teams/application_controller.rb b/app/controllers/admin/teams/application_controller.rb new file mode 100644 index 00000000000..a2920b626b5 --- /dev/null +++ b/app/controllers/admin/teams/application_controller.rb @@ -0,0 +1,12 @@ +# Provides a base class for Admin controllers to subclass +# +# Automatically sets the layout and ensures an administrator is logged in +class Admin::Teams::ApplicationController < Admin::ApplicationController + before_filter :user_team + + private + + def user_team + @team = UserTeam.find_by_path(params[:team_id]) + end +end diff --git a/app/controllers/admin/teams/members_controller.rb b/app/controllers/admin/teams/members_controller.rb new file mode 100644 index 00000000000..4037bff510e --- /dev/null +++ b/app/controllers/admin/teams/members_controller.rb @@ -0,0 +1,35 @@ +class Admin::Teams::MembersController < Admin::Teams::ApplicationController + def new + @users = User.active + @users = @users.not_in_team(@team) if @team.members.any? + @users = UserDecorator.decorate @users + end + + def create + unless params[:user_ids].blank? + user_ids = params[:user_ids] + access = params[:default_project_access] + is_admin = params[:group_admin] + @team.add_members(user_ids, access, is_admin) + end + + redirect_to admin_team_path(@team), notice: 'Members was successfully added.' + end + + def edit + @member = @team.members.find(params[:id]) + end + + def update + @member = @team.members.find(params[:id]) + options = {default_projects_access: params[:default_project_access], group_admin: params[:group_admin]} + if @team.update_membership(@member, options) + redirect_to admin_team_path(@team), notice: 'Membership was successfully updated.' + else + render :edit + end + end + + def destroy + end +end diff --git a/app/models/user_team.rb b/app/models/user_team.rb index d402fd22ea3..c9dfd671efc 100644 --- a/app/models/user_team.rb +++ b/app/models/user_team.rb @@ -64,6 +64,10 @@ class UserTeam < ActiveRecord::Base Gitlab::UserTeamManager.remove_member_from_team(self, user) end + def update_membership(user, options) + Gitlab::UserTeamManager.update_team_user_membership(self, user, options) + end + def max_project_access(project) user_team_project_relationships.find_by_project_id(project).greatest_access end diff --git a/app/views/admin/teams/members/_form.html.haml b/app/views/admin/teams/members/_form.html.haml new file mode 100644 index 00000000000..b75d788a94a --- /dev/null +++ b/app/views/admin/teams/members/_form.html.haml @@ -0,0 +1,20 @@ += form_tag admin_team_member_path(@team, @member), method: :put do + -if @member.errors.any? + .alert-message.block-message.error + %ul + - @member.errors.full_messages.each do |msg| + %li= msg + + .clearfix + %label Default access for Team projects: + .input + = select_tag :default_project_access, options_for_select(UserTeam.access_roles, @team.default_projects_access(@member)), class: "project-access-select chosen span3" + .clearfix + %label Team admin? + .input + = check_box_tag :group_admin, true, @team.admin?(@member) + + %br + .actions + = submit_tag 'Save', class: "btn primary" + = link_to 'Cancel', :back, class: "btn" diff --git a/app/views/admin/teams/members/edit.html.haml b/app/views/admin/teams/members/edit.html.haml new file mode 100644 index 00000000000..a82847ee5f8 --- /dev/null +++ b/app/views/admin/teams/members/edit.html.haml @@ -0,0 +1,16 @@ +%h3 + Edit access #{@member.name} in #{@team.name} team + +%hr +%table.zebra-striped + %tr + %td User: + %td= @member.name + %tr + %td Team: + %td= @team.name + %tr + %td Since: + %td= member_since(@team, @member).stamp("Nov 11, 2010") + += render 'form' diff --git a/app/views/admin/teams/members/new.html.haml b/app/views/admin/teams/members/new.html.haml new file mode 100644 index 00000000000..5cdf07359c8 --- /dev/null +++ b/app/views/admin/teams/members/new.html.haml @@ -0,0 +1,29 @@ +%h3.page_title + Team: #{@team.name} + +%fieldset + %legend Members (#{@team.members.count}) + = form_tag add_members_admin_team_path(@team), id: "team_members", class: "bulk_import", method: :post do + %table#members_list + %thead + %tr + %th User name + %th Default project access + %th Team access + %th + - @team.members.each do |member| + %tr.member + %td + = link_to [:admin, member] do + = member.name + %small= "(#{member.email})" + %td= @team.human_default_projects_access(member) + %td= @team.admin?(member) ? "Admin" : "Member" + %td + %tr + %td= select_tag :user_ids, options_from_collection_for_select(@users , :id, :name_with_email), multiple: true, data: {placeholder: 'Select users'}, class: 'chosen span5' + %td= select_tag :default_project_access, options_for_select(Project.access_options), {class: "project-access-select chosen span3" } + %td + %span= check_box_tag :group_admin + %span Admin? + %td= submit_tag 'Add', class: "btn primary", id: :add_members_to_team diff --git a/app/views/admin/teams/show.html.haml b/app/views/admin/teams/show.html.haml index 0f47717ae0e..05a3a1d3e16 100644 --- a/app/views/admin/teams/show.html.haml +++ b/app/views/admin/teams/show.html.haml @@ -41,31 +41,30 @@ %fieldset %legend Members (#{@team.members.count}) - = form_tag add_members_admin_team_path(@team), id: "team_members", class: "bulk_import", method: :post do - %table#members_list - %thead - %tr - %th User name - %th Default project access - %th Team access - %th.cred Danger Zone! - - @team.members.each do |member| - %tr.member - %td - = link_to [:admin, member] do - = member.name - %small= "(#{member.email})" - %td= @team.human_default_projects_access(member) - %td= @team.admin?(member) ? "Admin" : "Member" - %td.bgred - = link_to 'Remove', remove_member_admin_team_path(@team, member_id: member.id), confirm: 'Remove project from team and move to global namespace. Are you sure?', method: :delete, class: "btn danger small" + %table#members_list + %thead %tr - %td= select_tag :user_ids, options_from_collection_for_select(@users , :id, :name_with_email), multiple: true, data: {placeholder: 'Select users'}, class: 'chosen span5' - %td= select_tag :default_project_access, options_for_select(Project.access_options), {class: "project-access-select chosen span3" } + %th User name + %th Default project access + %th Team access + %th.cred Danger Zone! + - @team.members.each do |member| + %tr.member %td - %span= check_box_tag :group_admin - %span Admin? - %td= submit_tag 'Add', class: "btn primary", id: :add_members_to_team + = link_to [:admin, member] do + = member.name + %small= "(#{member.email})" + %td= @team.human_default_projects_access(member) + %td= @team.admin?(member) ? "Admin" : "Member" + %td.bgred + = link_to 'Edit', edit_admin_team_member_path(@team, member), class: "btn small" +   + = link_to 'Remove', admin_team_member_path(@team, member), confirm: 'Remove member from team. Are you sure?', method: :delete, class: "btn danger small" + %tr + %td + %td + %td + %td= link_to 'Add members', new_admin_team_member_path(@team), class: "btn primary", id: :add_members_to_team %fieldset %legend Projects (#{@team.projects.count}) diff --git a/config/routes.rb b/config/routes.rb index 69ad2e68642..b15431e3455 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -77,6 +77,9 @@ Gitlab::Application.routes.draw do post :add_members delete :remove_member end + scope module: :teams do + resources :members, only: [:edit, :update, :destroy, :new, :create] + end end resources :team_members, only: [:edit, :update, :destroy] resources :hooks, only: [:index, :create, :destroy] do diff --git a/lib/gitlab/user_team_manager.rb b/lib/gitlab/user_team_manager.rb index d010c79223e..753081ea718 100644 --- a/lib/gitlab/user_team_manager.rb +++ b/lib/gitlab/user_team_manager.rb @@ -22,6 +22,38 @@ module Gitlab update_team_users_access_in_project(team, project) end + def update_team_user_membership(team, member, options) + updates = {} + + if options[:default_projects_access] && options[:default_projects_access] != team.default_projects_access(member) + updates[:permission] = options[:default_projects_access] + end + + if options[:group_admin].to_s != team.admin?(member).to_s + updates[:group_admin] = options[:group_admin].present? + end + + unless updates.blank? + user_team_relationship = team.user_team_user_relationships.find_by_user_id(member) + if user_team_relationship.update_attributes(updates) + if updates[:permission] + rebuild_project_permissions_to_member(team, member) + end + true + else + false + end + else + true + end + end + + def rebuild_project_permissions_to_member(team, member) + team.projects.each do |project| + update_team_user_access_in_project(team, member, project) + end + end + def update_team_users_access_in_project(team, project) members = team.members members.each do |member| From cca993597013e1359d84230b0f69a2e02edb8e97 Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Sun, 20 Jan 2013 15:25:45 +0400 Subject: [PATCH 22/56] save generated files --- .../javascripts/admin/teams/members.js.coffee | 3 ++ .../stylesheets/admin/teams/members.css.scss | 3 ++ app/helpers/admin/teams/members_helper.rb | 5 +++ config/routes.rb | 1 - .../admin/teams/members_controller_spec.rb | 40 +++++++++++++++++++ .../admin/teams/members_helper_spec.rb | 15 +++++++ .../teams/members/create.html.haml_spec.rb | 5 +++ .../teams/members/destroy.html.haml_spec.rb | 5 +++ .../teams/members/edit.html.haml_spec.rb | 5 +++ .../admin/teams/members/new.html.haml_spec.rb | 5 +++ .../teams/members/update.html.haml_spec.rb | 5 +++ 11 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 app/assets/javascripts/admin/teams/members.js.coffee create mode 100644 app/assets/stylesheets/admin/teams/members.css.scss create mode 100644 app/helpers/admin/teams/members_helper.rb create mode 100644 spec/controllers/admin/teams/members_controller_spec.rb create mode 100644 spec/helpers/admin/teams/members_helper_spec.rb create mode 100644 spec/views/admin/teams/members/create.html.haml_spec.rb create mode 100644 spec/views/admin/teams/members/destroy.html.haml_spec.rb create mode 100644 spec/views/admin/teams/members/edit.html.haml_spec.rb create mode 100644 spec/views/admin/teams/members/new.html.haml_spec.rb create mode 100644 spec/views/admin/teams/members/update.html.haml_spec.rb diff --git a/app/assets/javascripts/admin/teams/members.js.coffee b/app/assets/javascripts/admin/teams/members.js.coffee new file mode 100644 index 00000000000..761567942fc --- /dev/null +++ b/app/assets/javascripts/admin/teams/members.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/stylesheets/admin/teams/members.css.scss b/app/assets/stylesheets/admin/teams/members.css.scss new file mode 100644 index 00000000000..47c2273c1c2 --- /dev/null +++ b/app/assets/stylesheets/admin/teams/members.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Admin::Teams::Members controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/helpers/admin/teams/members_helper.rb b/app/helpers/admin/teams/members_helper.rb new file mode 100644 index 00000000000..58b9f1896c4 --- /dev/null +++ b/app/helpers/admin/teams/members_helper.rb @@ -0,0 +1,5 @@ +module Admin::Teams::MembersHelper + def member_since(team, member) + team.user_team_user_relationships.find_by_user_id(member).created_at + end +end diff --git a/config/routes.rb b/config/routes.rb index b15431e3455..a31d0e7797d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,6 @@ require 'sidekiq/web' Gitlab::Application.routes.draw do - # # Search # diff --git a/spec/controllers/admin/teams/members_controller_spec.rb b/spec/controllers/admin/teams/members_controller_spec.rb new file mode 100644 index 00000000000..a9e41be59f7 --- /dev/null +++ b/spec/controllers/admin/teams/members_controller_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe Admin::Teams::MembersController do + + describe "GET 'new'" do + it "returns http success" do + get 'new' + response.should be_success + end + end + + describe "GET 'create'" do + it "returns http success" do + get 'create' + response.should be_success + end + end + + describe "GET 'edit'" do + it "returns http success" do + get 'edit' + response.should be_success + end + end + + describe "GET 'update'" do + it "returns http success" do + get 'update' + response.should be_success + end + end + + describe "GET 'destroy'" do + it "returns http success" do + get 'destroy' + response.should be_success + end + end + +end diff --git a/spec/helpers/admin/teams/members_helper_spec.rb b/spec/helpers/admin/teams/members_helper_spec.rb new file mode 100644 index 00000000000..ceef71c0be6 --- /dev/null +++ b/spec/helpers/admin/teams/members_helper_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +# Specs in this file have access to a helper object that includes +# the Admin::Teams::MembersHelper. For example: +# +# describe Admin::Teams::MembersHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# helper.concat_strings("this","that").should == "this that" +# end +# end +# end +describe Admin::Teams::MembersHelper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/views/admin/teams/members/create.html.haml_spec.rb b/spec/views/admin/teams/members/create.html.haml_spec.rb new file mode 100644 index 00000000000..b6f817617e4 --- /dev/null +++ b/spec/views/admin/teams/members/create.html.haml_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe "members/create.html.haml" do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/views/admin/teams/members/destroy.html.haml_spec.rb b/spec/views/admin/teams/members/destroy.html.haml_spec.rb new file mode 100644 index 00000000000..3ff1634461c --- /dev/null +++ b/spec/views/admin/teams/members/destroy.html.haml_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe "members/destroy.html.haml" do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/views/admin/teams/members/edit.html.haml_spec.rb b/spec/views/admin/teams/members/edit.html.haml_spec.rb new file mode 100644 index 00000000000..3e952e898a9 --- /dev/null +++ b/spec/views/admin/teams/members/edit.html.haml_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe "members/edit.html.haml" do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/views/admin/teams/members/new.html.haml_spec.rb b/spec/views/admin/teams/members/new.html.haml_spec.rb new file mode 100644 index 00000000000..f03eed1f29f --- /dev/null +++ b/spec/views/admin/teams/members/new.html.haml_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe "members/new.html.haml" do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/views/admin/teams/members/update.html.haml_spec.rb b/spec/views/admin/teams/members/update.html.haml_spec.rb new file mode 100644 index 00000000000..43b84bad99b --- /dev/null +++ b/spec/views/admin/teams/members/update.html.haml_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe "members/update.html.haml" do + pending "add some examples to (or delete) #{__FILE__}" +end From b7470440ffbc9cb9f58f9de4b3064760670a20a4 Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Mon, 21 Jan 2013 01:03:29 +0400 Subject: [PATCH 23/56] Move team project management to own controller --- .../admin/teams/projects_controller.rb | 42 +++++++++++++++++++ app/helpers/admin/teams/projects_helper.rb | 5 +++ app/models/user_team.rb | 4 ++ .../admin/teams/projects/_form.html.haml | 16 +++++++ app/views/admin/teams/projects/edit.html.haml | 16 +++++++ app/views/admin/teams/projects/new.html.haml | 23 ++++++++++ config/routes.rb | 1 + lib/gitlab/user_team_manager.rb | 14 +++++++ 8 files changed, 121 insertions(+) create mode 100644 app/controllers/admin/teams/projects_controller.rb create mode 100644 app/helpers/admin/teams/projects_helper.rb create mode 100644 app/views/admin/teams/projects/_form.html.haml create mode 100644 app/views/admin/teams/projects/edit.html.haml create mode 100644 app/views/admin/teams/projects/new.html.haml diff --git a/app/controllers/admin/teams/projects_controller.rb b/app/controllers/admin/teams/projects_controller.rb new file mode 100644 index 00000000000..74e566191b1 --- /dev/null +++ b/app/controllers/admin/teams/projects_controller.rb @@ -0,0 +1,42 @@ +class Admin::Teams::ProjectsController < Admin::Teams::ApplicationController + before_filter :team_project, only: [:edit, :destroy, :update] + + def new + @projects = Project.scoped + @projects = @projects.without_team(@team) if @team.projects.any? + #@projects.reject!(&:empty_repo?) + end + + def create + unless params[:project_ids].blank? + project_ids = params[:project_ids] + access = params[:greatest_project_access] + @team.assign_to_projects(project_ids, access) + end + + redirect_to admin_team_path(@team), notice: 'Projects was successfully added.' + end + + def edit + end + + def update + if @team.update_project_access(@project, params[:greatest_project_access]) + redirect_to admin_team_path(@team), notice: 'Membership was successfully updated.' + else + render :edit + end + end + + def destroy + @team.resign_from_project(@project) + redirect_to admin_team_path(@team), notice: 'Project was successfully removed.' + end + + private + + def team_project + @project = @team.projects.find_by_path(params[:id]) + end + +end diff --git a/app/helpers/admin/teams/projects_helper.rb b/app/helpers/admin/teams/projects_helper.rb new file mode 100644 index 00000000000..b97cc403337 --- /dev/null +++ b/app/helpers/admin/teams/projects_helper.rb @@ -0,0 +1,5 @@ +module Admin::Teams::ProjectsHelper + def assigned_since(team, project) + team.user_team_project_relationships.find_by_project_id(project).created_at + end +end diff --git a/app/models/user_team.rb b/app/models/user_team.rb index c9dfd671efc..2e2f75060c3 100644 --- a/app/models/user_team.rb +++ b/app/models/user_team.rb @@ -68,6 +68,10 @@ class UserTeam < ActiveRecord::Base Gitlab::UserTeamManager.update_team_user_membership(self, user, options) end + def update_project_access(project, permission) + Gitlab::UserTeamManager.update_project_greates_access(self, project, permission) + end + def max_project_access(project) user_team_project_relationships.find_by_project_id(project).greatest_access end diff --git a/app/views/admin/teams/projects/_form.html.haml b/app/views/admin/teams/projects/_form.html.haml new file mode 100644 index 00000000000..db4fe85b000 --- /dev/null +++ b/app/views/admin/teams/projects/_form.html.haml @@ -0,0 +1,16 @@ += form_tag admin_team_project_path(@team, @project), method: :put do + -if @project.errors.any? + .alert-message.block-message.error + %ul + - @project.errors.full_messages.each do |msg| + %li= msg + + .clearfix + %label Max access for Team members: + .input + = select_tag :greatest_project_access, options_for_select(UserTeam.access_roles, @team.max_project_access(@project)), class: "project-access-select chosen span3" + + %br + .actions + = submit_tag 'Save', class: "btn primary" + = link_to 'Cancel', :back, class: "btn" diff --git a/app/views/admin/teams/projects/edit.html.haml b/app/views/admin/teams/projects/edit.html.haml new file mode 100644 index 00000000000..b91a4982b81 --- /dev/null +++ b/app/views/admin/teams/projects/edit.html.haml @@ -0,0 +1,16 @@ +%h3 + Edit max access in #{@project.name} for #{@team.name} team + +%hr +%table.zebra-striped + %tr + %td Project: + %td= @project.name + %tr + %td Team: + %td= @team.name + %tr + %td Since: + %td= assigned_since(@team, @project).stamp("Nov 11, 2010") + += render 'form' diff --git a/app/views/admin/teams/projects/new.html.haml b/app/views/admin/teams/projects/new.html.haml new file mode 100644 index 00000000000..8a0a18a48c0 --- /dev/null +++ b/app/views/admin/teams/projects/new.html.haml @@ -0,0 +1,23 @@ +%h3.page_title + Team: #{@team.name} + +%fieldset + %legend Projects (#{@team.projects.count}) + = form_tag admin_team_projects_path(@team), id: "assign_projects", class: "bulk_import", method: :post do + %table#projects_list + %thead + %tr + %th Project name + %th Max access + %th + - @team.projects.each do |project| + %tr.project + %td + = link_to project.name_with_namespace, [:admin, project] + %td + %span= @team.human_max_project_access(project) + %td + %tr + %td= select_tag :project_ids, options_from_collection_for_select(@projects , :id, :name_with_namespace), multiple: true, data: {placeholder: 'Select projects'}, class: 'chosen span5' + %td= select_tag :greatest_project_access, options_for_select(Project.access_options), {class: "project-access-select chosen span3" } + %td= submit_tag 'Add', class: "btn primary", id: :assign_projects_to_team diff --git a/config/routes.rb b/config/routes.rb index a31d0e7797d..3132c310c99 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -78,6 +78,7 @@ Gitlab::Application.routes.draw do end scope module: :teams do resources :members, only: [:edit, :update, :destroy, :new, :create] + resources :projects, only: [:edit, :update, :destroy, :new, :create] end end resources :team_members, only: [:edit, :update, :destroy] diff --git a/lib/gitlab/user_team_manager.rb b/lib/gitlab/user_team_manager.rb index 753081ea718..7d9a9bdf3f5 100644 --- a/lib/gitlab/user_team_manager.rb +++ b/lib/gitlab/user_team_manager.rb @@ -48,6 +48,20 @@ module Gitlab end end + def update_project_greates_access(team, project, permission) + project_relation = team.user_team_project_relationships.find_by_project_id(project) + if permission != team.max_project_access(project) + if project_relation.update_attributes(greatest_access: permission) + update_team_users_access_in_project(team, project) + true + else + false + end + else + true + end + end + def rebuild_project_permissions_to_member(team, member) team.projects.each do |project| update_team_user_access_in_project(team, member, project) From a7667ffc14017732228058e34e1f724be08bf9a0 Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Mon, 21 Jan 2013 01:04:53 +0400 Subject: [PATCH 24/56] Repair members management of teams --- .../admin/teams/members_controller.rb | 15 +++++++- app/views/admin/teams/members/new.html.haml | 2 +- app/views/admin/teams/show.html.haml | 37 ++++++++++--------- 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/app/controllers/admin/teams/members_controller.rb b/app/controllers/admin/teams/members_controller.rb index 4037bff510e..6795a520bb3 100644 --- a/app/controllers/admin/teams/members_controller.rb +++ b/app/controllers/admin/teams/members_controller.rb @@ -1,4 +1,6 @@ class Admin::Teams::MembersController < Admin::Teams::ApplicationController + before_filter :team_member, only: [:edit, :destroy, :update] + def new @users = User.active @users = @users.not_in_team(@team) if @team.members.any? @@ -17,11 +19,9 @@ class Admin::Teams::MembersController < Admin::Teams::ApplicationController end def edit - @member = @team.members.find(params[:id]) end def update - @member = @team.members.find(params[:id]) options = {default_projects_access: params[:default_project_access], group_admin: params[:group_admin]} if @team.update_membership(@member, options) redirect_to admin_team_path(@team), notice: 'Membership was successfully updated.' @@ -31,5 +31,16 @@ class Admin::Teams::MembersController < Admin::Teams::ApplicationController end def destroy + if @team.remove_member(@member) + redirect_to admin_team_path(@team), notice: "Member was successfully removed from team." + else + redirect_to admin_team_members(@team), notice: "Something wrong." + end + end + + private + + def team_member + @member = @team.members.find(params[:id]) end end diff --git a/app/views/admin/teams/members/new.html.haml b/app/views/admin/teams/members/new.html.haml index 5cdf07359c8..066ab19fd08 100644 --- a/app/views/admin/teams/members/new.html.haml +++ b/app/views/admin/teams/members/new.html.haml @@ -3,7 +3,7 @@ %fieldset %legend Members (#{@team.members.count}) - = form_tag add_members_admin_team_path(@team), id: "team_members", class: "bulk_import", method: :post do + = form_tag admin_team_members_path(@team), id: "team_members", class: "bulk_import", method: :post do %table#members_list %thead %tr diff --git a/app/views/admin/teams/show.html.haml b/app/views/admin/teams/show.html.haml index 05a3a1d3e16..2bb9c02af7e 100644 --- a/app/views/admin/teams/show.html.haml +++ b/app/views/admin/teams/show.html.haml @@ -68,25 +68,26 @@ %fieldset %legend Projects (#{@team.projects.count}) - = form_tag delegate_projects_admin_team_path(@team), id: "assign_projects", class: "bulk_import", method: :post do - %table#projects_list - %thead - %tr - %th Project name - %th Max access - %th.cred Danger Zone! - - @team.projects.each do |project| - %tr.project - %td - = link_to project.name_with_namespace, [:admin, project] - %td - %span= @team.human_max_project_access(project) - %td.bgred - = link_to 'Relegate', relegate_project_admin_team_path(@team, project_id: project.id), confirm: 'Remove project from team and move to global namespace. Are you sure?', method: :delete, class: "btn danger small" + %table#projects_list + %thead %tr - %td= select_tag :project_ids, options_from_collection_for_select(@projects , :id, :name_with_namespace), multiple: true, data: {placeholder: 'Select projects'}, class: 'chosen span5' - %td= select_tag :greatest_project_access, options_for_select(Project.access_options), {class: "project-access-select chosen span3" } - %td= submit_tag 'Add', class: "btn primary", id: :assign_projects_to_team + %th Project name + %th Max access + %th.cred Danger Zone! + - @team.projects.each do |project| + %tr.project + %td + = link_to project.name_with_namespace, [:admin, project] + %td + %span= @team.human_max_project_access(project) + %td.bgred + = link_to 'Edit', edit_admin_team_project_path(@team, project), class: "btn small" +   + = link_to 'Relegate', admin_team_project_path(@team, project), confirm: 'Remove project from team. Are you sure?', method: :delete, class: "btn danger small" + %tr + %td + %td + %td= link_to 'Add projects', new_admin_team_project_path(@team), class: "btn primary", id: :assign_projects_to_team :javascript $(function(){ From 17a8ee57fe7a2c2b7c18c59f88828be9d5a455a0 Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Mon, 21 Jan 2013 01:05:51 +0400 Subject: [PATCH 25/56] Remove old data --- app/controllers/admin/teams_controller.rb | 35 ----------------------- app/models/users_project.rb | 2 +- config/routes.rb | 6 ---- 3 files changed, 1 insertion(+), 42 deletions(-) diff --git a/app/controllers/admin/teams_controller.rb b/app/controllers/admin/teams_controller.rb index 5d9356e9095..ee9141e371c 100644 --- a/app/controllers/admin/teams_controller.rb +++ b/app/controllers/admin/teams_controller.rb @@ -60,41 +60,6 @@ class Admin::TeamsController < Admin::ApplicationController redirect_to admin_user_teams_path, notice: 'UserTeam was successfully deleted.' end - def delegate_projects - unless params[:project_ids].blank? - project_ids = params[:project_ids] - access = params[:greatest_project_access] - @team.assign_to_projects(project_ids, access) - end - - redirect_to admin_team_path(@team), notice: 'Projects was successfully added.' - end - - def relegate_project - project = params[:project_id] - @team.resign_from_project(project) - - redirect_to admin_team_path(@team), notice: 'Project was successfully removed.' - end - - def add_members - unless params[:user_ids].blank? - user_ids = params[:user_ids] - access = params[:default_project_access] - is_admin = params[:group_admin] - @team.add_members(user_ids, access, is_admin) - end - - redirect_to admin_team_path(@team), notice: 'Members was successfully added.' - end - - def remove_member - member = params[:member_id] - @team.remove_member(member) - - redirect_to admin_team_path(@team), notice: 'Member was successfully removed.' - end - private def user_team diff --git a/app/models/users_project.rb b/app/models/users_project.rb index d282b2acbfc..ca5048ca7d4 100644 --- a/app/models/users_project.rb +++ b/app/models/users_project.rb @@ -41,7 +41,7 @@ class UsersProject < ActiveRecord::Base scope :masters, where(project_access: MASTER) scope :in_project, ->(project) { where(project_id: project.id) } - scope :in_projects, ->(projects) { where(project_id: projects.map(&:id)) } + scope :in_projects, ->(projects) { where(project_id: project_ids) } scope :with_user, ->(user) { where(user_id: user.id) } class << self diff --git a/config/routes.rb b/config/routes.rb index 3132c310c99..21bfc89c24c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -70,12 +70,6 @@ Gitlab::Application.routes.draw do end end resources :teams do #, constraints: { id: /[^\/]+/ } do end - member do - post :delegate_projects - delete :relegate_project - post :add_members - delete :remove_member - end scope module: :teams do resources :members, only: [:edit, :update, :destroy, :new, :create] resources :projects, only: [:edit, :update, :destroy, :new, :create] From 13fb3fdcf20f505b2591cfe3fc1a1e74242a932c Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Mon, 21 Jan 2013 01:06:11 +0400 Subject: [PATCH 26/56] Repair admin section tests --- features/admin/teams.feature | 4 +++- features/steps/admin/admin_teams.rb | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/features/admin/teams.feature b/features/admin/teams.feature index e070a90ae02..6ca7c4cbe02 100644 --- a/features/admin/teams.feature +++ b/features/admin/teams.feature @@ -17,7 +17,7 @@ Feature: Admin Teams When I visit admin teams page When I have clean "HardCoders" team And I visit "HardCoders" team page - #Then I should see only me in members table + When I click to "Add members" link When I select user "John" from user list as "Developer" And submit form with new team member info Then I should see "John" in teams members list as "Developer" @@ -30,6 +30,7 @@ Feature: Admin Teams When I have "Shop" project And I visit "HardCoders" team page Then I should see empty projects table + When I click to "Add projects" link When I select project "Shop" with max access "Reporter" And submit form with new team project info Then I should see "Shop" project in projects list @@ -43,6 +44,7 @@ Feature: Admin Teams When I have gitlab user "Jimm" And I visit "HardCoders" team page Then I should see members table without "Jimm" member + When I click to "Add members" link When I select user "Jimm" ub team members list as "Master" And submit form with new team member info Then I should see "Jimm" in teams members list as "Master" diff --git a/features/steps/admin/admin_teams.rb b/features/steps/admin/admin_teams.rb index bba60ec496b..a1221cd1a8c 100644 --- a/features/steps/admin/admin_teams.rb +++ b/features/steps/admin/admin_teams.rb @@ -205,6 +205,14 @@ class AdminTeams < Spinach::FeatureSteps find_in_list(".team_members", user).must_equal true end + When 'I click to "Add members" link' do + click_link "Add members" + end + + When 'I click to "Add projects" link' do + click_link "Add projects" + end + protected def current_team From b8dadd6427e50aa6d4f8f5dee113518340495550 Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Mon, 21 Jan 2013 01:07:17 +0400 Subject: [PATCH 27/56] repair rspec (remove and rename files) --- spec/helpers/admin/teams_helper_spec.rb | 15 --------------- spec/helpers/teams/members_helper_spec.rb | 15 --------------- spec/helpers/teams/projects_helper_spec.rb | 15 --------------- spec/helpers/teams_helper_spec.rb | 15 --------------- .../models/{team_spec.rb => project_team_spec.rb} | 2 +- 5 files changed, 1 insertion(+), 61 deletions(-) delete mode 100644 spec/helpers/admin/teams_helper_spec.rb delete mode 100644 spec/helpers/teams/members_helper_spec.rb delete mode 100644 spec/helpers/teams/projects_helper_spec.rb delete mode 100644 spec/helpers/teams_helper_spec.rb rename spec/models/{team_spec.rb => project_team_spec.rb} (94%) diff --git a/spec/helpers/admin/teams_helper_spec.rb b/spec/helpers/admin/teams_helper_spec.rb deleted file mode 100644 index 5ed6073297b..00000000000 --- a/spec/helpers/admin/teams_helper_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'spec_helper' - -# Specs in this file have access to a helper object that includes -# the Admin::TeamsHelper. For example: -# -# describe Admin::TeamsHelper do -# describe "string concat" do -# it "concats two strings with spaces" do -# helper.concat_strings("this","that").should == "this that" -# end -# end -# end -describe Admin::TeamsHelper do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/helpers/teams/members_helper_spec.rb b/spec/helpers/teams/members_helper_spec.rb deleted file mode 100644 index a8e227aa063..00000000000 --- a/spec/helpers/teams/members_helper_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'spec_helper' - -# Specs in this file have access to a helper object that includes -# the Teams::MembersHelper. For example: -# -# describe Teams::MembersHelper do -# describe "string concat" do -# it "concats two strings with spaces" do -# helper.concat_strings("this","that").should == "this that" -# end -# end -# end -describe Teams::MembersHelper do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/helpers/teams/projects_helper_spec.rb b/spec/helpers/teams/projects_helper_spec.rb deleted file mode 100644 index 836d1dca018..00000000000 --- a/spec/helpers/teams/projects_helper_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'spec_helper' - -# Specs in this file have access to a helper object that includes -# the Teams::ProjectsHelper. For example: -# -# describe Teams::ProjectsHelper do -# describe "string concat" do -# it "concats two strings with spaces" do -# helper.concat_strings("this","that").should == "this that" -# end -# end -# end -describe Teams::ProjectsHelper do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/helpers/teams_helper_spec.rb b/spec/helpers/teams_helper_spec.rb deleted file mode 100644 index 95726163e35..00000000000 --- a/spec/helpers/teams_helper_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'spec_helper' - -# Specs in this file have access to a helper object that includes -# the TeamsHelper. For example: -# -# describe TeamsHelper do -# describe "string concat" do -# it "concats two strings with spaces" do -# helper.concat_strings("this","that").should == "this that" -# end -# end -# end -describe TeamsHelper do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/team_spec.rb b/spec/models/project_team_spec.rb similarity index 94% rename from spec/models/team_spec.rb rename to spec/models/project_team_spec.rb index 65ffe13b490..7803811f395 100644 --- a/spec/models/team_spec.rb +++ b/spec/models/project_team_spec.rb @@ -1,6 +1,6 @@ require "spec_helper" -describe Team do +describe ProjectTeam do let(:team) { create(:project).team } describe "Respond to" do From 497f7ab5ba11bcb9d663c86e74326d8116125e18 Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Mon, 21 Jan 2013 01:07:28 +0400 Subject: [PATCH 28/56] save autogenerated files --- .../admin/teams/projects.js.coffee | 3 ++ .../stylesheets/admin/teams/projects.css.scss | 3 ++ .../admin/teams/projects_controller_spec.rb | 40 +++++++++++++++++++ .../admin/teams/projects_helper_spec.rb | 15 +++++++ .../teams/projects/create.html.haml_spec.rb | 5 +++ .../teams/projects/destroy.html.haml_spec.rb | 5 +++ .../teams/projects/edit.html.haml_spec.rb | 5 +++ .../teams/projects/new.html.haml_spec.rb | 5 +++ .../teams/projects/update.html.haml_spec.rb | 5 +++ 9 files changed, 86 insertions(+) create mode 100644 app/assets/javascripts/admin/teams/projects.js.coffee create mode 100644 app/assets/stylesheets/admin/teams/projects.css.scss create mode 100644 spec/controllers/admin/teams/projects_controller_spec.rb create mode 100644 spec/helpers/admin/teams/projects_helper_spec.rb create mode 100644 spec/views/admin/teams/projects/create.html.haml_spec.rb create mode 100644 spec/views/admin/teams/projects/destroy.html.haml_spec.rb create mode 100644 spec/views/admin/teams/projects/edit.html.haml_spec.rb create mode 100644 spec/views/admin/teams/projects/new.html.haml_spec.rb create mode 100644 spec/views/admin/teams/projects/update.html.haml_spec.rb diff --git a/app/assets/javascripts/admin/teams/projects.js.coffee b/app/assets/javascripts/admin/teams/projects.js.coffee new file mode 100644 index 00000000000..761567942fc --- /dev/null +++ b/app/assets/javascripts/admin/teams/projects.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/stylesheets/admin/teams/projects.css.scss b/app/assets/stylesheets/admin/teams/projects.css.scss new file mode 100644 index 00000000000..e6a6ec39043 --- /dev/null +++ b/app/assets/stylesheets/admin/teams/projects.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Admin::Teams::Projects controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/spec/controllers/admin/teams/projects_controller_spec.rb b/spec/controllers/admin/teams/projects_controller_spec.rb new file mode 100644 index 00000000000..7fe6ee0ca26 --- /dev/null +++ b/spec/controllers/admin/teams/projects_controller_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe Admin::Teams::ProjectsController do + + describe "GET 'new'" do + it "returns http success" do + get 'new' + response.should be_success + end + end + + describe "GET 'create'" do + it "returns http success" do + get 'create' + response.should be_success + end + end + + describe "GET 'edit'" do + it "returns http success" do + get 'edit' + response.should be_success + end + end + + describe "GET 'update'" do + it "returns http success" do + get 'update' + response.should be_success + end + end + + describe "GET 'destroy'" do + it "returns http success" do + get 'destroy' + response.should be_success + end + end + +end diff --git a/spec/helpers/admin/teams/projects_helper_spec.rb b/spec/helpers/admin/teams/projects_helper_spec.rb new file mode 100644 index 00000000000..1c98d23cdb7 --- /dev/null +++ b/spec/helpers/admin/teams/projects_helper_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +# Specs in this file have access to a helper object that includes +# the Admin::Teams::ProjectsHelper. For example: +# +# describe Admin::Teams::ProjectsHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# helper.concat_strings("this","that").should == "this that" +# end +# end +# end +describe Admin::Teams::ProjectsHelper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/views/admin/teams/projects/create.html.haml_spec.rb b/spec/views/admin/teams/projects/create.html.haml_spec.rb new file mode 100644 index 00000000000..74c4ee2d837 --- /dev/null +++ b/spec/views/admin/teams/projects/create.html.haml_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe "projects/create.html.haml" do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/views/admin/teams/projects/destroy.html.haml_spec.rb b/spec/views/admin/teams/projects/destroy.html.haml_spec.rb new file mode 100644 index 00000000000..b3eee48f38b --- /dev/null +++ b/spec/views/admin/teams/projects/destroy.html.haml_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe "projects/destroy.html.haml" do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/views/admin/teams/projects/edit.html.haml_spec.rb b/spec/views/admin/teams/projects/edit.html.haml_spec.rb new file mode 100644 index 00000000000..ef41b7b0814 --- /dev/null +++ b/spec/views/admin/teams/projects/edit.html.haml_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe "projects/edit.html.haml" do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/views/admin/teams/projects/new.html.haml_spec.rb b/spec/views/admin/teams/projects/new.html.haml_spec.rb new file mode 100644 index 00000000000..9ee68e5ae05 --- /dev/null +++ b/spec/views/admin/teams/projects/new.html.haml_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe "projects/new.html.haml" do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/views/admin/teams/projects/update.html.haml_spec.rb b/spec/views/admin/teams/projects/update.html.haml_spec.rb new file mode 100644 index 00000000000..fdaafd3924b --- /dev/null +++ b/spec/views/admin/teams/projects/update.html.haml_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe "projects/update.html.haml" do + pending "add some examples to (or delete) #{__FILE__}" +end From 1dd0feacc7ba885c53da74028ee081a5a08e05ca Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Mon, 21 Jan 2013 23:55:55 +0400 Subject: [PATCH 29/56] move Team_members controller into project (conflicts with team/members controller) --- .../admin/projects/application_controller.rb | 11 +++++++ .../admin/projects/members_controller.rb | 32 +++++++++++++++++++ .../admin/team_members_controller.rb | 22 ------------- app/models/project.rb | 5 +++ .../admin/projects/members/_form.html.haml | 16 ++++++++++ .../admin/projects/members/edit.html.haml | 8 +++++ app/views/admin/projects/show.html.haml | 12 +++---- app/views/admin/team_members/_form.html.haml | 16 ---------- app/views/admin/team_members/edit.html.haml | 8 ----- config/routes.rb | 4 ++- .../admin/projects/members_controller_spec.rb | 26 +++++++++++++++ 11 files changed, 107 insertions(+), 53 deletions(-) create mode 100644 app/controllers/admin/projects/application_controller.rb create mode 100644 app/controllers/admin/projects/members_controller.rb delete mode 100644 app/controllers/admin/team_members_controller.rb create mode 100644 app/views/admin/projects/members/_form.html.haml create mode 100644 app/views/admin/projects/members/edit.html.haml delete mode 100644 app/views/admin/team_members/_form.html.haml delete mode 100644 app/views/admin/team_members/edit.html.haml create mode 100644 spec/controllers/admin/projects/members_controller_spec.rb diff --git a/app/controllers/admin/projects/application_controller.rb b/app/controllers/admin/projects/application_controller.rb new file mode 100644 index 00000000000..0f3da998666 --- /dev/null +++ b/app/controllers/admin/projects/application_controller.rb @@ -0,0 +1,11 @@ +# Provides a base class for Admin controllers to subclass +# +# Automatically sets the layout and ensures an administrator is logged in +class Admin::Projects::ApplicationController < Admin::ApplicationController + + protected + + def project + @project ||= Project.find_by_path(params[:project_id]) + end +end diff --git a/app/controllers/admin/projects/members_controller.rb b/app/controllers/admin/projects/members_controller.rb new file mode 100644 index 00000000000..5c20c0717ed --- /dev/null +++ b/app/controllers/admin/projects/members_controller.rb @@ -0,0 +1,32 @@ +class Admin::Projects::MembersController < Admin::Projects::ApplicationController + def edit + @member = team_member + @project = project + @team_member_relation = team_member_relation + end + + def update + if team_member_relation.update_attributes(params[:team_member]) + redirect_to [:admin, project], notice: 'Project Access was successfully updated.' + else + render action: "edit" + end + end + + def destroy + team_member_relation.destroy + + redirect_to :back + end + + private + + def team_member + @member ||= project.users.find(params[:id]) + end + + def team_member_relation + team_member.users_projects.find_by_project_id(project) + end + +end diff --git a/app/controllers/admin/team_members_controller.rb b/app/controllers/admin/team_members_controller.rb deleted file mode 100644 index 3c85681cf66..00000000000 --- a/app/controllers/admin/team_members_controller.rb +++ /dev/null @@ -1,22 +0,0 @@ -class Admin::TeamMembersController < Admin::ApplicationController - def edit - @admin_team_member = UsersProject.find(params[:id]) - end - - def update - @admin_team_member = UsersProject.find(params[:id]) - - if @admin_team_member.update_attributes(params[:team_member]) - redirect_to [:admin, @admin_team_member.project], notice: 'Project Access was successfully updated.' - else - render action: "edit" - end - end - - def destroy - @admin_team_member = UsersProject.find(params[:id]) - @admin_team_member.destroy - - redirect_to :back - end -end diff --git a/app/models/project.rb b/app/models/project.rb index a21cc3f6f40..ba46fea2864 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -494,6 +494,11 @@ class Project < ActiveRecord::Base http_url = [Gitlab.config.gitlab.url, "/", path_with_namespace, ".git"].join('') end + def project_access_human(member) + project_user_relation = self.users_projects.find_by_user_id(member.id) + self.class.access_options.key(project_user_relation.project_access) + end + # Check if current branch name is marked as protected in the system def protected_branch? branch_name protected_branches.map(&:name).include?(branch_name) diff --git a/app/views/admin/projects/members/_form.html.haml b/app/views/admin/projects/members/_form.html.haml new file mode 100644 index 00000000000..f1bb6cfa226 --- /dev/null +++ b/app/views/admin/projects/members/_form.html.haml @@ -0,0 +1,16 @@ += form_for @team_member_relation, as: :team_member, url: admin_project_member_path(@project, @member) do |f| + -if @team_member_relation.errors.any? + .alert-message.block-message.error + %ul + - @team_member_relation.errors.full_messages.each do |msg| + %li= msg + + .clearfix + %label Project Access: + .input + = f.select :project_access, options_for_select(Project.access_options, @team_member_relation.project_access), {}, class: "project-access-select chosen span3" + + %br + .actions + = f.submit 'Save', class: "btn primary" + = link_to 'Cancel', :back, class: "btn" diff --git a/app/views/admin/projects/members/edit.html.haml b/app/views/admin/projects/members/edit.html.haml new file mode 100644 index 00000000000..2d76deb2aca --- /dev/null +++ b/app/views/admin/projects/members/edit.html.haml @@ -0,0 +1,8 @@ +%p.slead + Edit access for + = link_to @member.name, admin_user_path(@member) + in + = link_to @project.name_with_namespace, admin_project_path(@project) + +%hr += render 'form' diff --git a/app/views/admin/projects/show.html.haml b/app/views/admin/projects/show.html.haml index 12cad07c9c4..a213c09d456 100644 --- a/app/views/admin/projects/show.html.haml +++ b/app/views/admin/projects/show.html.haml @@ -114,7 +114,7 @@ %h5 Team %small - (#{@project.users_projects.count}) + (#{@project.users.count}) %br %table.zebra-striped.team_members %thead @@ -124,13 +124,13 @@ %th Repository Access %th - - @project.users_projects.each do |tm| + - @project.users.each do |tm| %tr %td - = link_to tm.user_name, admin_user_path(tm.user) - %td= tm.project_access_human - %td= link_to 'Edit Access', edit_admin_team_member_path(tm), class: "btn small" - %td= link_to 'Remove from team', admin_team_member_path(tm), confirm: 'Are you sure?', method: :delete, class: "btn danger small" + = link_to tm.name, admin_user_path(tm) + %td= @project.project_access_human(tm) + %td= link_to 'Edit Access', edit_admin_project_member_path(@project, tm), class: "btn small" + %td= link_to 'Remove from team', admin_project_member_path(@project, tm), confirm: 'Are you sure?', method: :delete, class: "btn danger small" %br %h5 Add new team member diff --git a/app/views/admin/team_members/_form.html.haml b/app/views/admin/team_members/_form.html.haml deleted file mode 100644 index 9cd94fdd30f..00000000000 --- a/app/views/admin/team_members/_form.html.haml +++ /dev/null @@ -1,16 +0,0 @@ -= form_for @admin_team_member, as: :team_member, url: admin_team_member_path(@admin_team_member) do |f| - -if @admin_team_member.errors.any? - .alert-message.block-message.error - %ul - - @admin_team_member.errors.full_messages.each do |msg| - %li= msg - - .clearfix - %label Project Access: - .input - = f.select :project_access, options_for_select(Project.access_options, @admin_team_member.project_access), {}, class: "project-access-select chosen span3" - - %br - .actions - = f.submit 'Save', class: "btn primary" - = link_to 'Cancel', :back, class: "btn" diff --git a/app/views/admin/team_members/edit.html.haml b/app/views/admin/team_members/edit.html.haml deleted file mode 100644 index aea9bd70a79..00000000000 --- a/app/views/admin/team_members/edit.html.haml +++ /dev/null @@ -1,8 +0,0 @@ -%p.slead - Edit access for - = link_to @admin_team_member.user_name, admin_user_path(@admin_team_member) - in - = link_to @admin_team_member.project.name_with_namespace, admin_project_path(@admin_team_member) - -%hr -= render 'form' diff --git a/config/routes.rb b/config/routes.rb index 21bfc89c24c..69ac18127d4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -68,6 +68,9 @@ Gitlab::Application.routes.draw do get :team put :team_update end + scope module: :projects do + resources :members, only: [:edit, :update, :destroy] + end end resources :teams do #, constraints: { id: /[^\/]+/ } do end scope module: :teams do @@ -75,7 +78,6 @@ Gitlab::Application.routes.draw do resources :projects, only: [:edit, :update, :destroy, :new, :create] end end - resources :team_members, only: [:edit, :update, :destroy] resources :hooks, only: [:index, :create, :destroy] do get :test end diff --git a/spec/controllers/admin/projects/members_controller_spec.rb b/spec/controllers/admin/projects/members_controller_spec.rb new file mode 100644 index 00000000000..73625e33d70 --- /dev/null +++ b/spec/controllers/admin/projects/members_controller_spec.rb @@ -0,0 +1,26 @@ +require 'spec_helper' + +describe Admin::Projects::MembersController do + + describe "GET 'edit'" do + it "returns http success" do + get 'edit' + response.should be_success + end + end + + describe "GET 'update'" do + it "returns http success" do + get 'update' + response.should be_success + end + end + + describe "GET 'destroy'" do + it "returns http success" do + get 'destroy' + response.should be_success + end + end + +end From 4ce715a360b089f95bf8e2b37cf87ec237492fcc Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Tue, 22 Jan 2013 21:14:00 +0400 Subject: [PATCH 30/56] Fix using context of Projects::UpdateContext (in admin section error, in public section - to next step if moving controlers) --- app/controllers/admin/projects_controller.rb | 2 +- app/controllers/projects_controller.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/admin/projects_controller.rb b/app/controllers/admin/projects_controller.rb index 28d9bf01cce..7f88652cdab 100644 --- a/app/controllers/admin/projects_controller.rb +++ b/app/controllers/admin/projects_controller.rb @@ -29,7 +29,7 @@ class Admin::ProjectsController < Admin::ApplicationController end def update - status = Projects::UpdateContext.new(project, current_user, params).execute(:admin) + status = ::Projects::UpdateContext.new(project, current_user, params).execute(:admin) if status redirect_to [:admin, @project], notice: 'Project was successfully updated.' diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 368737d1e0b..6e5e1f91381 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -19,7 +19,7 @@ class ProjectsController < ProjectResourceController end def create - @project = Projects::CreateContext.new(current_user, params[:project]).execute + @project = ::Projects::CreateContext.new(current_user, params[:project]).execute respond_to do |format| flash[:notice] = 'Project was successfully created.' if @project.saved? @@ -35,7 +35,7 @@ class ProjectsController < ProjectResourceController end def update - status = Projects::UpdateContext.new(project, current_user, params).execute + status = ::Projects::UpdateContext.new(project, current_user, params).execute respond_to do |format| if status From ccf8fa4fa23c9d48350bd2ed53f4a86afcfd6655 Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Tue, 22 Jan 2013 21:15:05 +0400 Subject: [PATCH 31/56] if project creator was remowed from Gitlab - creator is next admin, who edit this project --- app/controllers/admin/projects_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/admin/projects_controller.rb b/app/controllers/admin/projects_controller.rb index 7f88652cdab..711817395f1 100644 --- a/app/controllers/admin/projects_controller.rb +++ b/app/controllers/admin/projects_controller.rb @@ -29,6 +29,8 @@ class Admin::ProjectsController < Admin::ApplicationController end def update + project.creator = current_user unless project.creator + status = ::Projects::UpdateContext.new(project, current_user, params).execute(:admin) if status From f6f414ce3b8c252779e78cfd1a6470dc03e2e374 Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Tue, 22 Jan 2013 21:20:39 +0400 Subject: [PATCH 32/56] refactoring project team members controller (corresponding mental model) --- app/controllers/team_members_controller.rb | 22 +++++++++------ app/helpers/projects_helper.rb | 4 +-- app/views/team_members/_form.html.haml | 8 +++--- app/views/team_members/_show.html.haml | 10 +++---- app/views/team_members/create.js.haml | 2 +- app/views/team_members/index.html.haml | 2 +- app/views/team_members/show.html.haml | 31 +++++++++++----------- app/views/team_members/update.js.haml | 6 ++--- 8 files changed, 45 insertions(+), 40 deletions(-) diff --git a/app/controllers/team_members_controller.rb b/app/controllers/team_members_controller.rb index 8378a8458ff..2b48e29ed7d 100644 --- a/app/controllers/team_members_controller.rb +++ b/app/controllers/team_members_controller.rb @@ -7,12 +7,12 @@ class TeamMembersController < ProjectResourceController end def show - @team_member = project.users_projects.find(params[:id]) - @events = @team_member.user.recent_events.where(:project_id => @project.id).limit(7) + @user_project_relation = project.users_projects.find_by_user_id(member) + @events = member.recent_events.in_projects(project).limit(7) end def new - @team_member = project.users_projects.new + @user_project_relation = project.users_projects.new end def create @@ -28,18 +28,18 @@ class TeamMembersController < ProjectResourceController end def update - @team_member = project.users_projects.find(params[:id]) - @team_member.update_attributes(params[:team_member]) + @user_project_relation = project.users_projects.find_by_user_id(member) + @user_project_relation.update_attributes(params[:team_member]) - unless @team_member.valid? + unless @user_project_relation.valid? flash[:alert] = "User should have at least one role" end redirect_to project_team_index_path(@project) end def destroy - @team_member = project.users_projects.find(params[:id]) - @team_member.destroy + @user_project_relation = project.users_projects.find_by_user_id(params[:id]) + @user_project_relation.destroy respond_to do |format| format.html { redirect_to project_team_index_path(@project) } @@ -54,4 +54,10 @@ class TeamMembersController < ProjectResourceController redirect_to project_team_members_path(project), notice: notice end + + protected + + def member + @member ||= User.find(params[:id]) + end end diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 158925ba6c0..dbd47998eb1 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -3,8 +3,8 @@ module ProjectsHelper @project.users_projects.sort_by(&:project_access).reverse.group_by(&:project_access) end - def remove_from_team_message(project, member) - "You are going to remove #{member.user_name} from #{project.name}. Are you sure?" + def remove_from_project_team_message(project, user) + "You are going to remove #{user.name} from #{project.name} project team. Are you sure?" end def link_to_project project diff --git a/app/views/team_members/_form.html.haml b/app/views/team_members/_form.html.haml index a963e462a78..f9ee49dbdeb 100644 --- a/app/views/team_members/_form.html.haml +++ b/app/views/team_members/_form.html.haml @@ -1,11 +1,11 @@ %h3.page_title = "New Team member(s)" %hr -= form_for @team_member, as: :team_member, url: project_team_members_path(@project, @team_member) do |f| - -if @team_member.errors.any? += form_for @user_project_relation, as: :team_member, url: project_team_members_path(@project) do |f| + -if @user_project_relation.errors.any? .alert-message.block-message.error %ul - - @team_member.errors.full_messages.each do |msg| + - @user_project_relation.errors.full_messages.each do |msg| %li= msg %h6 1. Choose people you want in the team @@ -16,7 +16,7 @@ %h6 2. Set access level for them .clearfix = f.label :project_access, "Project Access" - .input= select_tag :project_access, options_for_select(Project.access_options, @team_member.project_access), class: "project-access-select chosen" + .input= select_tag :project_access, options_for_select(Project.access_options, @user_project_relation.project_access), class: "project-access-select chosen" .actions = f.submit 'Save', class: "btn save-btn" diff --git a/app/views/team_members/_show.html.haml b/app/views/team_members/_show.html.haml index 8082f47fca8..52992033805 100644 --- a/app/views/team_members/_show.html.haml +++ b/app/views/team_members/_show.html.haml @@ -1,11 +1,11 @@ - user = member.user - allow_admin = can? current_user, :admin_project, @project -%li{id: dom_id(member), class: "team_member_row user_#{user.id}"} +%li{id: dom_id(user), class: "team_member_row user_#{user.id}"} .row .span6 - = link_to project_team_member_path(@project, member), title: user.name, class: "dark" do + = link_to project_team_member_path(@project, user), title: user.name, class: "dark" do = image_tag gravatar_icon(user.email, 40), class: "avatar s32" - = link_to project_team_member_path(@project, member), title: user.name, class: "dark" do + = link_to project_team_member_path(@project, user), title: user.name, class: "dark" do %strong= truncate(user.name, lenght: 40) %br %small.cgray= user.email @@ -13,7 +13,7 @@ .span5.right - if allow_admin .left - = form_for(member, as: :team_member, url: project_team_member_path(@project, member)) do |f| + = form_for(member, as: :team_member, url: project_team_member_path(@project, member.user)) do |f| = f.select :project_access, options_for_select(UsersProject.access_roles, member.project_access), {}, class: "medium project-access-select span2" .right - if current_user == user @@ -23,6 +23,6 @@ - elsif user.blocked %span.btn.disabled.blocked Blocked - elsif allow_admin - = link_to project_team_member_path(project_id: @project, id: member.id), confirm: remove_from_team_message(@project, member), method: :delete, class: "very_small btn danger" do + = link_to project_team_member_path(@project, user), confirm: remove_from_project_team_message(@project, user), method: :delete, class: "very_small btn danger" do %i.icon-minus.icon-white diff --git a/app/views/team_members/create.js.haml b/app/views/team_members/create.js.haml index d5ae5d0cc43..b7dff35a269 100644 --- a/app/views/team_members/create.js.haml +++ b/app/views/team_members/create.js.haml @@ -1,4 +1,4 @@ -- if @team_member.valid? +- if @user_project_relation.valid? :plain $("#new_team_member").hide("slide", { direction: "right" }, 150, function(){ $("#team-table").show("slide", { direction: "left" }, 150, function() { diff --git a/app/views/team_members/index.html.haml b/app/views/team_members/index.html.haml index e413c81bb6c..8ba13939a30 100644 --- a/app/views/team_members/index.html.haml +++ b/app/views/team_members/index.html.haml @@ -1,7 +1,7 @@ = render "projects/project_head" %h3.page_title Team Members - (#{@project.users_projects.count}) + (#{@project.users.count}) %small Read more about project permissions %strong= link_to "here", help_permissions_path, class: "vlink" diff --git a/app/views/team_members/show.html.haml b/app/views/team_members/show.html.haml index 4008e8bd23e..a6a7152e92a 100644 --- a/app/views/team_members/show.html.haml +++ b/app/views/team_members/show.html.haml @@ -1,14 +1,13 @@ - allow_admin = can? current_user, :admin_project, @project -- user = @team_member.user .team_member_show - if can? current_user, :admin_project, @project - = link_to 'Remove from team', project_team_member_path(project_id: @project, id: @team_member.id), confirm: 'Are you sure?', method: :delete, class: "right btn danger" + = link_to 'Remove from team', project_team_member_path(@project, @member), confirm: 'Are you sure?', method: :delete, class: "right btn danger" .profile_avatar_holder - = image_tag gravatar_icon(user.email, 60), class: "borders" + = image_tag gravatar_icon(@member.email, 60), class: "borders" %h3.page_title - = user.name - %small (@#{user.username}) + = @member.name + %small (@#{@member.username}) %hr .back_link @@ -21,34 +20,34 @@ %table.lite %tr %td Email - %td= mail_to user.email + %td= mail_to @member.email %tr %td Skype - %td= user.skype - - unless user.linkedin.blank? + %td= @member.skype + - unless @member.linkedin.blank? %tr %td LinkedIn - %td= user.linkedin - - unless user.twitter.blank? + %td= @member.linkedin + - unless @member.twitter.blank? %tr %td Twitter - %td= user.twitter - - unless user.bio.blank? + %td= @member.twitter + - unless @member.bio.blank? %tr %td Bio - %td= user.bio + %td= @member.bio .span6 %table.lite %tr %td Member since - %td= @team_member.created_at.stamp("Aug 21, 2011") + %td= @user_project_relation.created_at.stamp("Aug 21, 2011") %tr %td Project Access: %small (#{link_to "read more", help_permissions_path, class: "vlink"}) %td - = form_for(@team_member, as: :team_member, url: project_team_member_path(@project, @team_member)) do |f| - = f.select :project_access, options_for_select(Project.access_options, @team_member.project_access), {}, class: "project-access-select", disabled: !allow_admin + = form_for(@user_project_relation, as: :team_member, url: project_team_member_path(@project, @member)) do |f| + = f.select :project_access, options_for_select(Project.access_options, @user_project_relation.project_access), {}, class: "project-access-select", disabled: !allow_admin %hr = render @events :javascript diff --git a/app/views/team_members/update.js.haml b/app/views/team_members/update.js.haml index 6d7f88160de..c68fe9574a2 100644 --- a/app/views/team_members/update.js.haml +++ b/app/views/team_members/update.js.haml @@ -1,6 +1,6 @@ -- if @team_member.valid? +- if @user_project_relation.valid? :plain - $("##{dom_id(@team_member)}").effect("highlight", {color: "#529214"}, 1000);; + $("##{dom_id(@user_project_relation)}").effect("highlight", {color: "#529214"}, 1000);; - else :plain - $("##{dom_id(@team_member)}").effect("highlight", {color: "#D12F19"}, 1000);; + $("##{dom_id(@user_project_relation)}").effect("highlight", {color: "#D12F19"}, 1000);; From f87b76a805e8ac2d6a77747be171714e2289281a Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Tue, 22 Jan 2013 21:21:07 +0400 Subject: [PATCH 33/56] refactoring user team in public section --- .../teams/application_controller.rb | 2 -- app/controllers/teams/projects_controller.rb | 22 +++++++++++++++++-- app/helpers/user_teams_helper.rb | 2 +- app/views/teams/members/_show.html.haml | 2 +- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/app/controllers/teams/application_controller.rb b/app/controllers/teams/application_controller.rb index 1cfb0e0991a..f1ecb5b2ce8 100644 --- a/app/controllers/teams/application_controller.rb +++ b/app/controllers/teams/application_controller.rb @@ -1,6 +1,4 @@ class Teams::ApplicationController < ApplicationController - before_filter :user_team, only: [:index, :show, :edit, :update, :destroy, :issues, :merge_requests, :search, :members] - protected def user_team diff --git a/app/controllers/teams/projects_controller.rb b/app/controllers/teams/projects_controller.rb index 796f37f6d5d..84de96861fb 100644 --- a/app/controllers/teams/projects_controller.rb +++ b/app/controllers/teams/projects_controller.rb @@ -1,21 +1,39 @@ class Teams::ProjectsController < Teams::ApplicationController def index - @projects = @user_team.projects - @avaliable_projects = current_user.admin? ? Project.without_team(@user_team) : (Project.personal(current_user) + current_user.projects).uniq + @projects = user_team.projects + @avaliable_projects = current_user.admin? ? Project.without_team(user_team) : (Project.personal(current_user) + current_user.projects).uniq end def new + @projects = Project.scoped + @projects = @projects.without_team(user_team) if user_team.projects.any? + #@projects.reject!(&:empty_repo?) end def create + unless params[:project_ids].blank? + project_ids = params[:project_ids] + access = params[:greatest_project_access] + user_team.assign_to_projects(project_ids, access) + end + + redirect_to admin_team_path(user_team), notice: 'Projects was successfully added.' end def edit + @user_team = user_team end def update + if user_team.update_project_access(project, params[:greatest_project_access]) + redirect_to admin_team_path(user_team), notice: 'Membership was successfully updated.' + else + render :edit + end end def destroy + user_team.resign_from_project(project) + redirect_to admin_team_path(user_team), notice: 'Project was successfully removed.' end end diff --git a/app/helpers/user_teams_helper.rb b/app/helpers/user_teams_helper.rb index 01e10de52fb..60deb9e09e5 100644 --- a/app/helpers/user_teams_helper.rb +++ b/app/helpers/user_teams_helper.rb @@ -19,7 +19,7 @@ module UserTeamsHelper team.user_team_user_relationships.sort_by(&:permission).reverse.group_by(&:permission) end - def remove_from_team_message(team, member) + def remove_from_user_team_message(team, member) "You are going to remove #{member.name} from #{team.name}. Are you sure?" end diff --git a/app/views/teams/members/_show.html.haml b/app/views/teams/members/_show.html.haml index dfe73c77652..a06d269ac00 100644 --- a/app/views/teams/members/_show.html.haml +++ b/app/views/teams/members/_show.html.haml @@ -27,5 +27,5 @@ - elsif user.blocked %span.btn.disabled.blocked Blocked - elsif allow_admin - = link_to team_member_path(@user_team, user), confirm: remove_from_team_message(@user_team, user), method: :delete, class: "very_small btn danger" do + = link_to team_member_path(@user_team, user), confirm: remove_from_user_team_message(@user_team, user), method: :delete, class: "very_small btn danger" do %i.icon-minus.icon-white From dcea52203ddc93c1d073e7615d98725cc3584d2f Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Tue, 22 Jan 2013 21:29:19 +0400 Subject: [PATCH 34/56] remove before_filter from controllers --- .../admin/teams/members_controller.rb | 11 +++---- .../admin/teams/projects_controller.rb | 11 +++---- app/controllers/admin/teams_controller.rb | 32 ++++++++----------- app/controllers/teams/projects_controller.rb | 13 ++++++-- 4 files changed, 34 insertions(+), 33 deletions(-) diff --git a/app/controllers/admin/teams/members_controller.rb b/app/controllers/admin/teams/members_controller.rb index 6795a520bb3..a6dbf6b5049 100644 --- a/app/controllers/admin/teams/members_controller.rb +++ b/app/controllers/admin/teams/members_controller.rb @@ -1,6 +1,4 @@ class Admin::Teams::MembersController < Admin::Teams::ApplicationController - before_filter :team_member, only: [:edit, :destroy, :update] - def new @users = User.active @users = @users.not_in_team(@team) if @team.members.any? @@ -19,11 +17,12 @@ class Admin::Teams::MembersController < Admin::Teams::ApplicationController end def edit + team_member end def update options = {default_projects_access: params[:default_project_access], group_admin: params[:group_admin]} - if @team.update_membership(@member, options) + if @team.update_membership(team_member, options) redirect_to admin_team_path(@team), notice: 'Membership was successfully updated.' else render :edit @@ -31,16 +30,16 @@ class Admin::Teams::MembersController < Admin::Teams::ApplicationController end def destroy - if @team.remove_member(@member) + if @team.remove_member(team_member) redirect_to admin_team_path(@team), notice: "Member was successfully removed from team." else redirect_to admin_team_members(@team), notice: "Something wrong." end end - private + protected def team_member - @member = @team.members.find(params[:id]) + @member ||= @team.members.find(params[:id]) end end diff --git a/app/controllers/admin/teams/projects_controller.rb b/app/controllers/admin/teams/projects_controller.rb index 74e566191b1..f255b8448ab 100644 --- a/app/controllers/admin/teams/projects_controller.rb +++ b/app/controllers/admin/teams/projects_controller.rb @@ -1,6 +1,4 @@ class Admin::Teams::ProjectsController < Admin::Teams::ApplicationController - before_filter :team_project, only: [:edit, :destroy, :update] - def new @projects = Project.scoped @projects = @projects.without_team(@team) if @team.projects.any? @@ -18,10 +16,11 @@ class Admin::Teams::ProjectsController < Admin::Teams::ApplicationController end def edit + team_project end def update - if @team.update_project_access(@project, params[:greatest_project_access]) + if @team.update_project_access(team_project, params[:greatest_project_access]) redirect_to admin_team_path(@team), notice: 'Membership was successfully updated.' else render :edit @@ -29,14 +28,14 @@ class Admin::Teams::ProjectsController < Admin::Teams::ApplicationController end def destroy - @team.resign_from_project(@project) + @team.resign_from_project(team_project) redirect_to admin_team_path(@team), notice: 'Project was successfully removed.' end - private + protected def team_project - @project = @team.projects.find_by_path(params[:id]) + @project ||= @team.projects.find_by_path(params[:id]) end end diff --git a/app/controllers/admin/teams_controller.rb b/app/controllers/admin/teams_controller.rb index ee9141e371c..f42ec10585b 100644 --- a/app/controllers/admin/teams_controller.rb +++ b/app/controllers/admin/teams_controller.rb @@ -1,9 +1,4 @@ class Admin::TeamsController < Admin::ApplicationController - before_filter :user_team, - only: [ :edit, :show, :update, :destroy, - :delegate_projects, :relegate_project, - :add_members, :remove_member ] - def index @teams = UserTeam.order('name ASC') @teams = @teams.search(params[:name]) if params[:name].present? @@ -12,11 +7,11 @@ class Admin::TeamsController < Admin::ApplicationController def show @projects = Project.scoped - @projects = @projects.without_team(@team) if @team.projects.any? + @projects = @projects.without_team(user_team) if user_team.projects.any? #@projects.reject!(&:empty_repo?) @users = User.active - @users = @users.not_in_team(@team) if @team.members.any? + @users = @users.not_in_team(user_team) if user_team.members.any? @users = UserDecorator.decorate @users end @@ -25,15 +20,16 @@ class Admin::TeamsController < Admin::ApplicationController end def edit + user_team end def create - @team = UserTeam.new(params[:user_team]) - @team.path = @team.name.dup.parameterize if @team.name - @team.owner = current_user + user_team = UserTeam.new(params[:user_team]) + user_team.path = user_team.name.dup.parameterize if user_team.name + user_team.owner = current_user - if @team.save - redirect_to admin_team_path(@team), notice: 'UserTeam was successfully created.' + if user_team.save + redirect_to admin_team_path(user_team), notice: 'UserTeam was successfully created.' else render action: "new" end @@ -44,26 +40,26 @@ class Admin::TeamsController < Admin::ApplicationController owner_id = user_team_params.delete(:owner_id) if owner_id - @team.owner = User.find(owner_id) + user_team.owner = User.find(owner_id) end - if @team.update_attributes(user_team_params) - redirect_to admin_team_path(@team), notice: 'UserTeam was successfully updated.' + if user_team.update_attributes(user_team_params) + redirect_to admin_team_path(user_team), notice: 'UserTeam was successfully updated.' else render action: "edit" end end def destroy - @team.destroy + user_team.destroy redirect_to admin_user_teams_path, notice: 'UserTeam was successfully deleted.' end - private + protected def user_team - @team = UserTeam.find_by_path(params[:id]) + @team ||= UserTeam.find_by_path(params[:id]) end end diff --git a/app/controllers/teams/projects_controller.rb b/app/controllers/teams/projects_controller.rb index 84de96861fb..1e65c0ce35e 100644 --- a/app/controllers/teams/projects_controller.rb +++ b/app/controllers/teams/projects_controller.rb @@ -21,11 +21,11 @@ class Teams::ProjectsController < Teams::ApplicationController end def edit - @user_team = user_team + team_project end def update - if user_team.update_project_access(project, params[:greatest_project_access]) + if user_team.update_project_access(team_project, params[:greatest_project_access]) redirect_to admin_team_path(user_team), notice: 'Membership was successfully updated.' else render :edit @@ -33,7 +33,14 @@ class Teams::ProjectsController < Teams::ApplicationController end def destroy - user_team.resign_from_project(project) + user_team.resign_from_project(team_project) redirect_to admin_team_path(user_team), notice: 'Project was successfully removed.' end + + private + + def team_project + @project ||= @team.projects.find_by_path(params[:id]) + end + end From 7534154b44f920005e6732bbcc9e9af391b81546 Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Wed, 23 Jan 2013 00:58:44 +0400 Subject: [PATCH 35/56] Add access control in public section to users teams --- app/controllers/teams/application_controller.rb | 7 +++++++ app/controllers/teams/members_controller.rb | 2 +- app/controllers/teams/projects_controller.rb | 3 +++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/controllers/teams/application_controller.rb b/app/controllers/teams/application_controller.rb index f1ecb5b2ce8..ff73f6b4eb0 100644 --- a/app/controllers/teams/application_controller.rb +++ b/app/controllers/teams/application_controller.rb @@ -1,8 +1,15 @@ class Teams::ApplicationController < ApplicationController + + before_filter :authorize_manage_user_team! + protected def user_team @user_team ||= UserTeam.find_by_path(params[:team_id]) end + def authorize_manage_user_team! + return access_denied! unless can?(current_user, :manage_user_team, user_team) + end + end diff --git a/app/controllers/teams/members_controller.rb b/app/controllers/teams/members_controller.rb index ab1c2878331..111ad5c2f3d 100644 --- a/app/controllers/teams/members_controller.rb +++ b/app/controllers/teams/members_controller.rb @@ -1,6 +1,6 @@ class Teams::MembersController < Teams::ApplicationController # Authorize - before_filter :authorize_manage_user_team!, only: [:new, :edit] + skip_before_filter :authorize_manage_user_team!, only: [:index] def index @members = @user_team.members diff --git a/app/controllers/teams/projects_controller.rb b/app/controllers/teams/projects_controller.rb index 1e65c0ce35e..6255853f8c9 100644 --- a/app/controllers/teams/projects_controller.rb +++ b/app/controllers/teams/projects_controller.rb @@ -1,4 +1,7 @@ class Teams::ProjectsController < Teams::ApplicationController + + skip_before_filter :authorize_manage_user_team!, only: [:index] + def index @projects = user_team.projects @avaliable_projects = current_user.admin? ? Project.without_team(user_team) : (Project.personal(current_user) + current_user.projects).uniq From 7658f8c151b22680cf594d028e180a8a859fc9b8 Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Wed, 23 Jan 2013 01:03:52 +0400 Subject: [PATCH 36/56] update routes --- config/routes.rb | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 69ac18127d4..e8af16387bc 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -56,6 +56,7 @@ Gitlab::Application.routes.draw do put :unblock end end + resources :groups, constraints: { id: /[^\/]+/ } do member do put :project_update @@ -63,26 +64,31 @@ Gitlab::Application.routes.draw do delete :remove_project end end + + resources :teams, constraints: { id: /[^\/]+/ } do + scope module: :teams do + resources :members, only: [:edit, :update, :destroy, :new, :create] + resources :projects, only: [:edit, :update, :destroy, :new, :create], constraints: { id: /[a-zA-Z.\/0-9_\-]+/ } + end + end + + resources :hooks, only: [:index, :create, :destroy] do + get :test + end + + resource :logs, only: [:show] + resource :resque, controller: 'resque', only: [:show] + resources :projects, constraints: { id: /[a-zA-Z.\/0-9_\-]+/ }, except: [:new, :create] do member do get :team put :team_update end - scope module: :projects do + scope module: :projects, constraints: { id: /[^\/]+/ } do resources :members, only: [:edit, :update, :destroy] end end - resources :teams do #, constraints: { id: /[^\/]+/ } do end - scope module: :teams do - resources :members, only: [:edit, :update, :destroy, :new, :create] - resources :projects, only: [:edit, :update, :destroy, :new, :create] - end - end - resources :hooks, only: [:index, :create, :destroy] do - get :test - end - resource :logs, only: [:show] - resource :resque, controller: 'resque', only: [:show] + root to: "dashboard#index" end @@ -116,7 +122,6 @@ Gitlab::Application.routes.draw do get "dashboard/issues" => "dashboard#issues" get "dashboard/merge_requests" => "dashboard#merge_requests" - # # Groups Area # @@ -130,19 +135,18 @@ Gitlab::Application.routes.draw do end end - resources :teams do + # + # Teams Area + # + resources :teams, constraints: { id: /[^\/]+/ } do member do get :issues get :merge_requests get :search - post :delegate_projects - delete :relegate_project - put :update_access end scope module: :teams do - resources :members - resources :projects, only: [:index, :show] do - end + resources :members, only: [:index, :new, :create, :edit, :update, :destroy] + resources :projects, only: [:index, :new, :create, :edit, :update, :destroy], constraints: { id: /[a-zA-Z.0-9_\-\/]+/ } end collection do get :search From 18bd1c9d30e16783d750c7786cbcc7d350f4d0aa Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Wed, 23 Jan 2013 02:20:27 +0400 Subject: [PATCH 37/56] update all teams code. refactoring and some corrections --- .../admin/teams/application_controller.rb | 1 - .../admin/teams/members_controller.rb | 18 ++-- .../admin/teams/projects_controller.rb | 16 ++-- app/controllers/admin/teams_controller.rb | 14 +-- app/controllers/application_controller.rb | 9 ++ app/controllers/team_members_controller.rb | 1 + .../teams/application_controller.rb | 6 +- app/controllers/teams/members_controller.rb | 61 ++++++------- app/controllers/teams/projects_controller.rb | 15 ++-- app/controllers/teams_controller.rb | 61 ++++--------- app/views/admin/teams/index.html.haml | 1 + app/views/admin/teams/new.html.haml | 6 +- app/views/admin/teams/show.html.haml | 89 +++++++++---------- app/views/dashboard/_teams.html.haml | 9 +- app/views/layouts/_head_panel.html.haml | 3 + app/views/layouts/user_team.html.haml | 16 ++-- app/views/teams/_team_head.html.haml | 12 +-- app/views/teams/edit.html.haml | 18 ++-- app/views/teams/index.html.haml | 5 +- app/views/teams/members/_form.html.haml | 27 +++--- app/views/teams/members/_show.html.haml | 14 +-- app/views/teams/members/_team.html.haml | 2 +- app/views/teams/members/edit.html.haml | 20 ++++- app/views/teams/members/import.html.haml | 17 ---- app/views/teams/members/index.html.haml | 7 +- app/views/teams/members/new.html.haml | 32 ++++++- app/views/teams/members/show.html.haml | 2 + app/views/teams/merge_requests.html.haml | 2 + app/views/teams/new.html.haml | 6 +- app/views/teams/projects/_form.html.haml | 16 ++++ app/views/teams/projects/edit.html.haml | 18 +++- app/views/teams/projects/index.html.haml | 60 ++++++------- app/views/teams/projects/new.html.haml | 25 +++++- app/views/teams/projects/show.html.haml | 4 - app/views/teams/search.html.haml | 2 +- 35 files changed, 332 insertions(+), 283 deletions(-) delete mode 100644 app/views/teams/members/import.html.haml create mode 100644 app/views/teams/projects/_form.html.haml delete mode 100644 app/views/teams/projects/show.html.haml diff --git a/app/controllers/admin/teams/application_controller.rb b/app/controllers/admin/teams/application_controller.rb index a2920b626b5..8710821454e 100644 --- a/app/controllers/admin/teams/application_controller.rb +++ b/app/controllers/admin/teams/application_controller.rb @@ -2,7 +2,6 @@ # # Automatically sets the layout and ensures an administrator is logged in class Admin::Teams::ApplicationController < Admin::ApplicationController - before_filter :user_team private diff --git a/app/controllers/admin/teams/members_controller.rb b/app/controllers/admin/teams/members_controller.rb index a6dbf6b5049..cdcc96c0aef 100644 --- a/app/controllers/admin/teams/members_controller.rb +++ b/app/controllers/admin/teams/members_controller.rb @@ -1,7 +1,7 @@ class Admin::Teams::MembersController < Admin::Teams::ApplicationController def new @users = User.active - @users = @users.not_in_team(@team) if @team.members.any? + @users = @users.not_in_team(user_team) if user_team.members.any? @users = UserDecorator.decorate @users end @@ -10,10 +10,10 @@ class Admin::Teams::MembersController < Admin::Teams::ApplicationController user_ids = params[:user_ids] access = params[:default_project_access] is_admin = params[:group_admin] - @team.add_members(user_ids, access, is_admin) + user_team.add_members(user_ids, access, is_admin) end - redirect_to admin_team_path(@team), notice: 'Members was successfully added.' + redirect_to admin_team_path(user_team), notice: 'Members was successfully added into Team of users.' end def edit @@ -22,24 +22,24 @@ class Admin::Teams::MembersController < Admin::Teams::ApplicationController def update options = {default_projects_access: params[:default_project_access], group_admin: params[:group_admin]} - if @team.update_membership(team_member, options) - redirect_to admin_team_path(@team), notice: 'Membership was successfully updated.' + if user_team.update_membership(team_member, options) + redirect_to admin_team_path(user_team), notice: "Membership for #{team_member.name} was successfully updated in Team of users." else render :edit end end def destroy - if @team.remove_member(team_member) - redirect_to admin_team_path(@team), notice: "Member was successfully removed from team." + if user_team.remove_member(team_member) + redirect_to admin_team_path(user_team), notice: "Member #{team_member.name} was successfully removed from Team of users." else - redirect_to admin_team_members(@team), notice: "Something wrong." + redirect_to admin_team_members(user_team), notice: "Something is wrong." end end protected def team_member - @member ||= @team.members.find(params[:id]) + @member ||= user_team.members.find(params[:id]) end end diff --git a/app/controllers/admin/teams/projects_controller.rb b/app/controllers/admin/teams/projects_controller.rb index f255b8448ab..8584a188b20 100644 --- a/app/controllers/admin/teams/projects_controller.rb +++ b/app/controllers/admin/teams/projects_controller.rb @@ -1,7 +1,7 @@ class Admin::Teams::ProjectsController < Admin::Teams::ApplicationController def new @projects = Project.scoped - @projects = @projects.without_team(@team) if @team.projects.any? + @projects = @projects.without_team(user_team) if user_team.projects.any? #@projects.reject!(&:empty_repo?) end @@ -9,10 +9,10 @@ class Admin::Teams::ProjectsController < Admin::Teams::ApplicationController unless params[:project_ids].blank? project_ids = params[:project_ids] access = params[:greatest_project_access] - @team.assign_to_projects(project_ids, access) + user_team.assign_to_projects(project_ids, access) end - redirect_to admin_team_path(@team), notice: 'Projects was successfully added.' + redirect_to admin_team_path(user_team), notice: 'Team of users was successfully assgned to projects.' end def edit @@ -20,22 +20,22 @@ class Admin::Teams::ProjectsController < Admin::Teams::ApplicationController end def update - if @team.update_project_access(team_project, params[:greatest_project_access]) - redirect_to admin_team_path(@team), notice: 'Membership was successfully updated.' + if user_team.update_project_access(team_project, params[:greatest_project_access]) + redirect_to admin_team_path(user_team), notice: 'Access was successfully updated.' else render :edit end end def destroy - @team.resign_from_project(team_project) - redirect_to admin_team_path(@team), notice: 'Project was successfully removed.' + user_team.resign_from_project(team_project) + redirect_to admin_team_path(user_team), notice: 'Team of users was successfully reassigned from project.' end protected def team_project - @project ||= @team.projects.find_by_path(params[:id]) + @project ||= user_team.projects.find_with_namespace(params[:id]) end end diff --git a/app/controllers/admin/teams_controller.rb b/app/controllers/admin/teams_controller.rb index f42ec10585b..7371f4a446c 100644 --- a/app/controllers/admin/teams_controller.rb +++ b/app/controllers/admin/teams_controller.rb @@ -24,12 +24,12 @@ class Admin::TeamsController < Admin::ApplicationController end def create - user_team = UserTeam.new(params[:user_team]) - user_team.path = user_team.name.dup.parameterize if user_team.name - user_team.owner = current_user + @team = UserTeam.new(params[:user_team]) + @team.path = @team.name.dup.parameterize if @team.name + @team.owner = current_user - if user_team.save - redirect_to admin_team_path(user_team), notice: 'UserTeam was successfully created.' + if @team.save + redirect_to admin_team_path(@team), notice: 'Team of users was successfully created.' else render action: "new" end @@ -44,7 +44,7 @@ class Admin::TeamsController < Admin::ApplicationController end if user_team.update_attributes(user_team_params) - redirect_to admin_team_path(user_team), notice: 'UserTeam was successfully updated.' + redirect_to admin_team_path(user_team), notice: 'Team of users was successfully updated.' else render action: "edit" end @@ -53,7 +53,7 @@ class Admin::TeamsController < Admin::ApplicationController def destroy user_team.destroy - redirect_to admin_user_teams_path, notice: 'UserTeam was successfully deleted.' + redirect_to admin_user_teams_path, notice: 'Team of users was successfully deleted.' end protected diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 3457a1ab1b4..f903c7fdd62 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -94,6 +94,14 @@ class ApplicationController < ActionController::Base return access_denied! unless can?(current_user, :download_code, project) end + def authorize_manage_user_team! + return access_denied! unless user_team.present? && can?(current_user, :manage_user_team, user_team) + end + + def authorize_admin_user_team! + return access_denied! unless user_team.present? && can?(current_user, :admin_user_team, user_team) + end + def access_denied! render "errors/access_denied", layout: "errors", status: 404 end @@ -135,4 +143,5 @@ class ApplicationController < ActionController::Base def dev_tools Rack::MiniProfiler.authorize_request end + end diff --git a/app/controllers/team_members_controller.rb b/app/controllers/team_members_controller.rb index 2b48e29ed7d..7e4c8792b50 100644 --- a/app/controllers/team_members_controller.rb +++ b/app/controllers/team_members_controller.rb @@ -4,6 +4,7 @@ class TeamMembersController < ProjectResourceController before_filter :authorize_admin_project!, except: [:index, :show] def index + @teams = UserTeam.scoped end def show diff --git a/app/controllers/teams/application_controller.rb b/app/controllers/teams/application_controller.rb index ff73f6b4eb0..2c1583d943e 100644 --- a/app/controllers/teams/application_controller.rb +++ b/app/controllers/teams/application_controller.rb @@ -5,11 +5,7 @@ class Teams::ApplicationController < ApplicationController protected def user_team - @user_team ||= UserTeam.find_by_path(params[:team_id]) - end - - def authorize_manage_user_team! - return access_denied! unless can?(current_user, :manage_user_team, user_team) + @team ||= UserTeam.find_by_path(params[:team_id]) end end diff --git a/app/controllers/teams/members_controller.rb b/app/controllers/teams/members_controller.rb index 111ad5c2f3d..95b8de1861b 100644 --- a/app/controllers/teams/members_controller.rb +++ b/app/controllers/teams/members_controller.rb @@ -1,58 +1,53 @@ class Teams::MembersController < Teams::ApplicationController - # Authorize + skip_before_filter :authorize_manage_user_team!, only: [:index] def index - @members = @user_team.members - end - - def show - @team_member = @user_team.members.find(params[:id]) - @events = @team_member.recent_events.limit(7) + @members = user_team.members end def new - @team_member = @user_team.members.new + @users = User.active + @users = @users.not_in_team(user_team) if user_team.members.any? + @users = UserDecorator.decorate @users end def create - users = User.where(id: params[:user_ids]) - - @project.team << [users, params[:default_project_access]] - - if params[:redirect_to] - redirect_to params[:redirect_to] - else - redirect_to project_team_index_path(@project) + unless params[:user_ids].blank? + user_ids = params[:user_ids] + access = params[:default_project_access] + is_admin = params[:group_admin] + user_team.add_members(user_ids, access, is_admin) end + + redirect_to team_path(user_team), notice: 'Members was successfully added into Team of users.' + end + + def edit + team_member end def update - @team_member = @user_team.members.find(params[:id]) - @team_member.update_attributes(params[:team_member]) - - unless @team_member.valid? - flash[:alert] = "User should have at least one role" + options = {default_projects_access: params[:default_project_access], group_admin: params[:group_admin]} + if user_team.update_membership(team_member, options) + redirect_to team_path(user_team), notice: "Membership for #{team_member.name} was successfully updated in Team of users." + else + render :edit end - redirect_to team_member_path(@project) end def destroy - @team_member = project.users_projects.find(params[:id]) - @team_member.destroy - - respond_to do |format| - format.html { redirect_to project_team_index_path(@project) } - format.js { render nothing: true } + if user_team.remove_member(team_member) + redirect_to team_path(user_team), notice: "Member #{team_member.name} was successfully removed from Team of users." + else + redirect_to team_members(user_team), notice: "Something is wrong." end end - def apply_import - giver = Project.find(params[:source_project_id]) - status = @project.team.import(giver) - notice = status ? "Succesfully imported" : "Import failed" + protected - redirect_to project_team_members_path(project), notice: notice + def team_member + @member ||= user_team.members.find(params[:id]) end end diff --git a/app/controllers/teams/projects_controller.rb b/app/controllers/teams/projects_controller.rb index 6255853f8c9..21ddba865f3 100644 --- a/app/controllers/teams/projects_controller.rb +++ b/app/controllers/teams/projects_controller.rb @@ -8,9 +8,12 @@ class Teams::ProjectsController < Teams::ApplicationController end def new - @projects = Project.scoped - @projects = @projects.without_team(user_team) if user_team.projects.any? + user_team + @avaliable_projects = Project.scoped + @avaliable_projects = @avaliable_projects.without_team(user_team) if user_team.projects.any? #@projects.reject!(&:empty_repo?) + + redirect_to team_projects_path(user_team), notice: "No avalible projects." unless @avaliable_projects.any? end def create @@ -20,7 +23,7 @@ class Teams::ProjectsController < Teams::ApplicationController user_team.assign_to_projects(project_ids, access) end - redirect_to admin_team_path(user_team), notice: 'Projects was successfully added.' + redirect_to team_projects_path(user_team), notice: 'Team of users was successfully assgned to projects.' end def edit @@ -29,7 +32,7 @@ class Teams::ProjectsController < Teams::ApplicationController def update if user_team.update_project_access(team_project, params[:greatest_project_access]) - redirect_to admin_team_path(user_team), notice: 'Membership was successfully updated.' + redirect_to team_projects_path(user_team), notice: 'Access was successfully updated.' else render :edit end @@ -37,13 +40,13 @@ class Teams::ProjectsController < Teams::ApplicationController def destroy user_team.resign_from_project(team_project) - redirect_to admin_team_path(user_team), notice: 'Project was successfully removed.' + redirect_to team_projects_path(user_team), notice: 'Team of users was successfully reassigned from project.' end private def team_project - @project ||= @team.projects.find_by_path(params[:id]) + @project ||= user_team.projects.find_with_namespace(params[:id]) end end diff --git a/app/controllers/teams_controller.rb b/app/controllers/teams_controller.rb index 4e3703d72d4..169ee34f4ec 100644 --- a/app/controllers/teams_controller.rb +++ b/app/controllers/teams_controller.rb @@ -1,30 +1,26 @@ class TeamsController < ApplicationController - respond_to :html + # Authorize + before_filter :authorize_manage_user_team! + before_filter :authorize_admin_user_team! + + # Skip access control on public section + skip_before_filter :authorize_manage_user_team!, only: [:index, :show, :new, :destroy, :create, :search, :issues, :merge_requests] + skip_before_filter :authorize_admin_user_team!, only: [:index, :show, :new, :create, :search, :issues, :merge_requests] + layout 'user_team', only: [:show, :edit, :update, :destroy, :issues, :merge_requests, :search] - before_filter :user_team, only: [:show, :edit, :update, :destroy, :issues, :merge_requests, :search] - before_filter :projects, only: [:show, :edit, :update, :destroy, :issues, :merge_requests, :search] - - # Authorize - before_filter :authorize_manage_user_team!, only: [:edit, :update] - before_filter :authorize_admin_user_team!, only: [:destroy] - def index - @teams = UserTeam.all + @teams = UserTeam.order('name ASC') end def show - @events = Event.in_projects(project_ids).limit(20).offset(params[:offset] || 0) - - respond_to do |format| - format.html - format.js - format.atom { render layout: false } - end + user_team + projects + @events = Event.in_projects(user_team.project_ids).limit(20).offset(params[:offset] || 0) end def edit - + user_team end def update @@ -58,56 +54,37 @@ class TeamsController < ApplicationController # Get authored or assigned open merge requests def merge_requests - @merge_requests = MergeRequest.of_user_team(@user_team) + @merge_requests = MergeRequest.of_user_team(user_team) @merge_requests = FilterContext.new(@merge_requests, params).execute @merge_requests = @merge_requests.recent.page(params[:page]).per(20) end # Get only assigned issues def issues - @issues = Issue.of_user_team(@user_team) + @issues = Issue.of_user_team(user_team) @issues = FilterContext.new(@issues, params).execute @issues = @issues.recent.page(params[:page]).per(20) @issues = @issues.includes(:author, :project) - - respond_to do |format| - format.html - format.atom { render layout: false } - end end def search - result = SearchContext.new(project_ids, params).execute + result = SearchContext.new(user_team.project_ids, params).execute @projects = result[:projects] @merge_requests = result[:merge_requests] @issues = result[:issues] @wiki_pages = result[:wiki_pages] + @teams = result[:teams] end protected - def user_team - @user_team ||= UserTeam.find_by_path(params[:id]) - end - def projects @projects ||= user_team.projects.sorted_by_activity end - def project_ids - projects.map(&:id) + def user_team + @team ||= UserTeam.find_by_path(params[:id]) end - def authorize_manage_user_team! - unless user_team.present? or can?(current_user, :manage_user_team, user_team) - return render_404 - end - end - - def authorize_admin_user_team! - unless user_team.owner == current_user || current_user.admin? - return render_404 - end - end end diff --git a/app/views/admin/teams/index.html.haml b/app/views/admin/teams/index.html.haml index 8b6928e906e..3ab57448ab2 100644 --- a/app/views/admin/teams/index.html.haml +++ b/app/views/admin/teams/index.html.haml @@ -34,4 +34,5 @@ %td.bgred = link_to 'Rename', edit_admin_team_path(team), id: "edit_#{dom_id(team)}", class: "btn small" = link_to 'Destroy', admin_team_path(team), confirm: "REMOVE #{team.name}? Are you sure?", method: :delete, class: "btn small danger" + = paginate @teams, theme: "admin" diff --git a/app/views/admin/teams/new.html.haml b/app/views/admin/teams/new.html.haml index c936b66b32e..a40a2c4ebf9 100644 --- a/app/views/admin/teams/new.html.haml +++ b/app/views/admin/teams/new.html.haml @@ -14,8 +14,6 @@ %hr .padded %ul - %li Team is kind of directory for several projects - %li All created teams are private + %li All created teams are public (users can view who enter into team and which project are assigned for this team) %li People within a team see only projects they have access to - %li All projects of team will be stored in team directory - %li You will be able to move existing projects into team + %li You will be able to assign existing projects for team diff --git a/app/views/admin/teams/show.html.haml b/app/views/admin/teams/show.html.haml index 2bb9c02af7e..a7470c2d6e0 100644 --- a/app/views/admin/teams/show.html.haml +++ b/app/views/admin/teams/show.html.haml @@ -40,54 +40,51 @@ = link_to "Cancel", "#", class: "btn change-owner-cancel-link" %fieldset - %legend Members (#{@team.members.count}) - %table#members_list - %thead - %tr - %th User name - %th Default project access - %th Team access - %th.cred Danger Zone! - - @team.members.each do |member| - %tr.member - %td - = link_to [:admin, member] do - = member.name - %small= "(#{member.email})" - %td= @team.human_default_projects_access(member) - %td= @team.admin?(member) ? "Admin" : "Member" - %td.bgred - = link_to 'Edit', edit_admin_team_member_path(@team, member), class: "btn small" -   - = link_to 'Remove', admin_team_member_path(@team, member), confirm: 'Remove member from team. Are you sure?', method: :delete, class: "btn danger small" - %tr - %td - %td - %td - %td= link_to 'Add members', new_admin_team_member_path(@team), class: "btn primary", id: :add_members_to_team + %legend + Members (#{@team.members.count}) + %span= link_to 'Add members', new_admin_team_member_path(@team), class: "btn success small right", id: :add_members_to_team + - if @team.members.any? + %table#members_list + %thead + %tr + %th User name + %th Default project access + %th Team access + %th.cred.span3 Danger Zone! + - @team.members.each do |member| + %tr.member + %td + = link_to [:admin, member] do + = member.name + %small= "(#{member.email})" + %td= @team.human_default_projects_access(member) + %td= @team.admin?(member) ? "Admin" : "Member" + %td.bgred + = link_to 'Edit', edit_admin_team_member_path(@team, member), class: "btn small" +   + = link_to 'Remove', admin_team_member_path(@team, member), confirm: 'Remove member from team. Are you sure?', method: :delete, class: "btn danger small" %fieldset - %legend Projects (#{@team.projects.count}) - %table#projects_list - %thead - %tr - %th Project name - %th Max access - %th.cred Danger Zone! - - @team.projects.each do |project| - %tr.project - %td - = link_to project.name_with_namespace, [:admin, project] - %td - %span= @team.human_max_project_access(project) - %td.bgred - = link_to 'Edit', edit_admin_team_project_path(@team, project), class: "btn small" -   - = link_to 'Relegate', admin_team_project_path(@team, project), confirm: 'Remove project from team. Are you sure?', method: :delete, class: "btn danger small" - %tr - %td - %td - %td= link_to 'Add projects', new_admin_team_project_path(@team), class: "btn primary", id: :assign_projects_to_team + %legend + Projects (#{@team.projects.count}) + %span= link_to 'Add projects', new_admin_team_project_path(@team), class: "btn success small right", id: :assign_projects_to_team + - if @team.projects.any? + %table#projects_list + %thead + %tr + %th Project name + %th Max access + %th.cred.span3 Danger Zone! + - @team.projects.each do |project| + %tr.project + %td + = link_to project.name_with_namespace, [:admin, project] + %td + %span= @team.human_max_project_access(project) + %td.bgred + = link_to 'Edit', edit_admin_team_project_path(@team, project), class: "btn small" +   + = link_to 'Relegate', admin_team_project_path(@team, project), confirm: 'Remove project from team. Are you sure?', method: :delete, class: "btn danger small" :javascript $(function(){ diff --git a/app/views/dashboard/_teams.html.haml b/app/views/dashboard/_teams.html.haml index cbf97b93097..414bb12a945 100644 --- a/app/views/dashboard/_teams.html.haml +++ b/app/views/dashboard/_teams.html.haml @@ -2,7 +2,7 @@ %h5.title My Teams %small - (#{teams.count}) + (#{@teams.count}) %span.right = link_to new_team_path, class: "btn very_small info" do %i.icon-plus @@ -12,7 +12,7 @@ %i.icon-user All Teams %ul.well-list - - teams.each do |team| + - @teams.each do |team| %li = link_to team_path(id: team.path), class: dom_class(team) do %strong.well-title= truncate(team.name, length: 35) @@ -20,4 +20,7 @@ → %span.last_activity %strong Projects: - %span= current_user.authorized_projects.in_team(team).count + %span= team.projects.count + %span.last_activity + %strong Members: + %span= team.members.count diff --git a/app/views/layouts/_head_panel.html.haml b/app/views/layouts/_head_panel.html.haml index 8f4f3d7815f..945500d4b6c 100644 --- a/app/views/layouts/_head_panel.html.haml +++ b/app/views/layouts/_head_panel.html.haml @@ -8,6 +8,9 @@ %span.separator %h1.project_name= title %ul.nav + %li + = link_to teams_path, title: "Teams of users", class: 'has_bottom_tooltip', 'data-original-title' => 'Teams list' do + %i.icon-globe - if current_user.is_admin? %li = link_to admin_root_path, title: "Admin area", class: 'has_bottom_tooltip', 'data-original-title' => 'Admin area' do diff --git a/app/views/layouts/user_team.html.haml b/app/views/layouts/user_team.html.haml index bd3dfe0d418..aa613d71f90 100644 --- a/app/views/layouts/user_team.html.haml +++ b/app/views/layouts/user_team.html.haml @@ -1,22 +1,22 @@ !!! 5 %html{ lang: "en"} - = render "layouts/head", title: "#{@user_team.name}" + = render "layouts/head", title: "#{@team.name}" %body{class: "#{app_theme} application"} = render "layouts/flash" - = render "layouts/head_panel", title: "#{@user_team.name}" + = render "layouts/head_panel", title: "#{@team.name}" .container %ul.main_menu = nav_link(path: 'teams#show', html_options: {class: 'home'}) do - = link_to "Home", team_path(@user_team), title: "Home" + = link_to "Home", team_path(@team), title: "Home" = nav_link(path: 'teams#issues') do - = link_to issues_team_path(@user_team) do + = link_to issues_team_path(@team) do Issues - %span.count= Issue.opened.of_user_team(@user_team).count + %span.count= Issue.opened.of_user_team(@team).count = nav_link(path: 'teams#merge_requests') do - = link_to merge_requests_team_path(@user_team) do + = link_to merge_requests_team_path(@team) do Merge Requests - %span.count= MergeRequest.opened.of_user_team(@user_team).count + %span.count= MergeRequest.opened.of_user_team(@team).count = nav_link(path: 'teams#search') do - = link_to "Search", search_team_path(@user_team) + = link_to "Search", search_team_path(@team) .content= yield diff --git a/app/views/teams/_team_head.html.haml b/app/views/teams/_team_head.html.haml index 53796623de1..cb5c9567ba6 100644 --- a/app/views/teams/_team_head.html.haml +++ b/app/views/teams/_team_head.html.haml @@ -1,19 +1,19 @@ %ul.nav.nav-tabs = nav_link(path: 'teams#show') do - = link_to team_path(@user_team), class: "activities-tab tab" do + = link_to team_path(@team), class: "activities-tab tab" do %i.icon-home Show = nav_link(controller: [:members]) do - = link_to team_members_path(@user_team), class: "team-tab tab" do + = link_to team_members_path(@team), class: "team-tab tab" do %i.icon-user Members = nav_link(controller: [:projects]) do - = link_to team_projects_path(@user_team), class: "team-tab tab" do + = link_to team_projects_path(@team), class: "team-tab tab" do %i.icon-briefcase Projects - - if can? current_user, :manage_user_team, @user_team + - if can? current_user, :admin_user_team, @team = nav_link(path: 'teams#edit', html_options: {class: 'right'}) do - = link_to edit_team_path(@user_team), class: "stat-tab tab " do + = link_to edit_team_path(@team), class: "stat-tab tab " do %i.icon-edit - Edit + Edit Team diff --git a/app/views/teams/edit.html.haml b/app/views/teams/edit.html.haml index 4c239e8fa41..b2ceb2bdb21 100644 --- a/app/views/teams/edit.html.haml +++ b/app/views/teams/edit.html.haml @@ -1,11 +1,11 @@ = render "team_head" -%h3.page_title= "Edit Team #{@user_team.name}" +%h3.page_title= "Edit Team #{@team.name}" %hr -= form_for @user_team, url: teams_path do |f| - - if @user_team.errors.any? += form_for @team, url: teams_path do |f| + - if @team.errors.any? .alert-message.block-message.error - %span= @user_team.errors.full_messages.first + %span= @team.errors.full_messages.first .clearfix = f.label :name do Team name is @@ -21,12 +21,4 @@ .input.span3.center = f.submit 'Save team changes', class: "btn primary" .input.span3.center - = link_to 'Delete team', team_path(@user_team), method: :delete, confirm: "You are shure?", class: "btn danger" - %hr - .padded - %ul - %li Team is kind of directory for several projects - %li All created teams are private - %li People within a team see only projects they have access to - %li All projects of team will be stored in team directory - %li You will be able to move existing projects into team + = link_to 'Delete team', team_path(@team), method: :delete, confirm: "You are shure?", class: "btn danger" diff --git a/app/views/teams/index.html.haml b/app/views/teams/index.html.haml index 9ac54594521..8f8874328fc 100644 --- a/app/views/teams/index.html.haml +++ b/app/views/teams/index.html.haml @@ -3,7 +3,7 @@ %small list of all teams - = link_to 'New Team', new_team_path, class: "btn small right" + = link_to 'New Team', new_team_path, class: "btn success small right" %br = form_tag search_teams_path, method: :get, class: 'form-inline' do @@ -32,6 +32,7 @@ %td= link_to team.owner.name, team_member_path(team, team.owner) %td - if current_user.can?(:manage_user_team, team) - - if team.owner == current_user + - if current_user.can?(:admin_user_team, team) = link_to "Destroy", team_path(team), method: :delete, confirm: "You are shure?", class: "danger btn small right" +   = link_to "Edit", edit_team_path(team), class: "btn small right" diff --git a/app/views/teams/members/_form.html.haml b/app/views/teams/members/_form.html.haml index a963e462a78..b75d788a94a 100644 --- a/app/views/teams/members/_form.html.haml +++ b/app/views/teams/members/_form.html.haml @@ -1,23 +1,20 @@ -%h3.page_title - = "New Team member(s)" -%hr -= form_for @team_member, as: :team_member, url: project_team_members_path(@project, @team_member) do |f| - -if @team_member.errors.any? += form_tag admin_team_member_path(@team, @member), method: :put do + -if @member.errors.any? .alert-message.block-message.error %ul - - @team_member.errors.full_messages.each do |msg| + - @member.errors.full_messages.each do |msg| %li= msg - %h6 1. Choose people you want in the team .clearfix - = f.label :user_ids, "People" - .input= select_tag(:user_ids, options_from_collection_for_select(User.active.not_in_project(@project).alphabetically, :id, :name), {data: {placeholder: "Select users"}, class: "chosen xxlarge", multiple: true}) - - %h6 2. Set access level for them + %label Default access for Team projects: + .input + = select_tag :default_project_access, options_for_select(UserTeam.access_roles, @team.default_projects_access(@member)), class: "project-access-select chosen span3" .clearfix - = f.label :project_access, "Project Access" - .input= select_tag :project_access, options_for_select(Project.access_options, @team_member.project_access), class: "project-access-select chosen" + %label Team admin? + .input + = check_box_tag :group_admin, true, @team.admin?(@member) + %br .actions - = f.submit 'Save', class: "btn save-btn" - = link_to "Cancel", project_team_index_path(@project), class: "btn cancel-btn" + = submit_tag 'Save', class: "btn primary" + = link_to 'Cancel', :back, class: "btn" diff --git a/app/views/teams/members/_show.html.haml b/app/views/teams/members/_show.html.haml index a06d269ac00..ec4728787cf 100644 --- a/app/views/teams/members/_show.html.haml +++ b/app/views/teams/members/_show.html.haml @@ -1,11 +1,11 @@ - user = member.user -- allow_admin = can? current_user, :manage_user_team, @user_team +- allow_admin = can? current_user, :manage_user_team, @team %li{id: dom_id(member), class: "team_member_row user_#{user.id}"} .row .span5 - = link_to team_member_path(@user_team, user), title: user.name, class: "dark" do + = link_to team_member_path(@team, user), title: user.name, class: "dark" do = image_tag gravatar_icon(user.email, 40), class: "avatar s32" - = link_to team_member_path(@user_team, user), title: user.name, class: "dark" do + = link_to team_member_path(@team, user), title: user.name, class: "dark" do %strong= truncate(user.name, lenght: 40) %br %small.cgray= user.email @@ -13,8 +13,8 @@ .span6.right - if allow_admin .left.span2 - = form_for(member, as: :team_member, url: team_member_path(@user_team, user)) do |f| - = f.select :permission, options_for_select(UsersProject.access_roles, @user_team.default_projects_access(user)), {}, class: "medium project-access-select span2" + = form_for(member, as: :team_member, url: team_member_path(@team, user)) do |f| + = f.select :permission, options_for_select(UsersProject.access_roles, @team.default_projects_access(user)), {}, class: "medium project-access-select span2" .left.span2 %span Admin access @@ -22,10 +22,10 @@ .right - if current_user == user %span.btn.disabled This is you! - - if @user_team.owner == user + - if @team.owner == user %span.btn.disabled.success Owner - elsif user.blocked %span.btn.disabled.blocked Blocked - elsif allow_admin - = link_to team_member_path(@user_team, user), confirm: remove_from_user_team_message(@user_team, user), method: :delete, class: "very_small btn danger" do + = link_to team_member_path(@team, user), confirm: remove_from_user_team_message(@team, user), method: :delete, class: "very_small btn danger" do %i.icon-minus.icon-white diff --git a/app/views/teams/members/_team.html.haml b/app/views/teams/members/_team.html.haml index e1fbf6d1e75..d8afc1fa371 100644 --- a/app/views/teams/members/_team.html.haml +++ b/app/views/teams/members/_team.html.haml @@ -1,4 +1,4 @@ -- grouped_user_team_members(@user_team).each do |access, members| +- grouped_user_team_members(@team).each do |access, members| .ui-box %h5.title = Project.access_options.key(access).pluralize diff --git a/app/views/teams/members/edit.html.haml b/app/views/teams/members/edit.html.haml index a2742977717..9caff799552 100644 --- a/app/views/teams/members/edit.html.haml +++ b/app/views/teams/members/edit.html.haml @@ -1,2 +1,18 @@ -%h1 Teams::Members#edit -%p Find me in app/views/teams/members/edit.html.haml \ No newline at end of file += render "teams/team_head" + +%h3 + Edit access #{@member.name} in #{@team.name} team + +%hr +%table.zebra-striped + %tr + %td User: + %td= @member.name + %tr + %td Team: + %td= @team.name + %tr + %td Since: + %td= member_since(@team, @member).stamp("Nov 11, 2010") + += render 'form' diff --git a/app/views/teams/members/import.html.haml b/app/views/teams/members/import.html.haml deleted file mode 100644 index de82f416248..00000000000 --- a/app/views/teams/members/import.html.haml +++ /dev/null @@ -1,17 +0,0 @@ -= render "projects/project_head" - -%h3.page_title - = "Import team from another project" -%hr -%p.slead - Read more about team import #{link_to "here", '#', class: 'vlink'}. -= form_tag apply_import_project_team_members_path(@project), method: 'post' do - %p.slead Choose project you want to use as team source: - .padded - = label_tag :source_project_id, "Project" - .input= select_tag(:source_project_id, options_from_collection_for_select(current_user.authorized_projects, :id, :name_with_namespace), prompt: "Select project", class: "chosen xxlarge", required: true) - - .actions - = submit_tag 'Import', class: "btn save-btn" - = link_to "Cancel", project_team_index_path(@project), class: "btn cancel-btn" - diff --git a/app/views/teams/members/index.html.haml b/app/views/teams/members/index.html.haml index 5b125b32769..1628237ede0 100644 --- a/app/views/teams/members/index.html.haml +++ b/app/views/teams/members/index.html.haml @@ -1,4 +1,5 @@ = render "teams/team_head" + %h3.page_title Team Members (#{@members.count}) @@ -6,13 +7,13 @@ Read more about project permissions %strong= link_to "here", help_permissions_path, class: "vlink" - - if can? current_user, :manage_user_team, @user_team + - if can? current_user, :manage_user_team, @team %span.right - = link_to new_team_member_path(@user_team), class: "btn success small grouped", title: "New Team Member" do + = link_to new_team_member_path(@team), class: "btn success small grouped", title: "New Team Member" do New Team Member %hr .clearfix %div.team-table - = render partial: "teams/members/team", locals: {project: @user_team} + = render partial: "teams/members/team", locals: {project: @team} diff --git a/app/views/teams/members/new.html.haml b/app/views/teams/members/new.html.haml index 40eb4cebf08..43f7c5d7b6f 100644 --- a/app/views/teams/members/new.html.haml +++ b/app/views/teams/members/new.html.haml @@ -1,2 +1,30 @@ -= render "projects/project_head" -= render "team_members/form" += render "teams/team_head" + +%h3.page_title + Team: #{@team.name} + +%fieldset + %legend Members (#{@team.members.count}) + = form_tag team_members_path(@team), id: "team_members", class: "bulk_import", method: :post do + %table#members_list + %thead + %tr + %th User name + %th Default project access + %th Team access + %th + - @team.members.each do |member| + %tr.member + %td + = member.name + %small= "(#{member.email})" + %td= @team.human_default_projects_access(member) + %td= @team.admin?(member) ? "Admin" : "Member" + %td + %tr + %td= select_tag :user_ids, options_from_collection_for_select(@users , :id, :name_with_email), multiple: true, data: {placeholder: 'Select users'}, class: 'chosen span5' + %td= select_tag :default_project_access, options_for_select(Project.access_options), {class: "project-access-select chosen span3" } + %td + %span= check_box_tag :group_admin + %span Admin? + %td= submit_tag 'Add', class: "btn primary", id: :add_members_to_team diff --git a/app/views/teams/members/show.html.haml b/app/views/teams/members/show.html.haml index 4008e8bd23e..03ef21be7a6 100644 --- a/app/views/teams/members/show.html.haml +++ b/app/views/teams/members/show.html.haml @@ -1,3 +1,5 @@ += render "teams/team_head" + - allow_admin = can? current_user, :admin_project, @project - user = @team_member.user diff --git a/app/views/teams/merge_requests.html.haml b/app/views/teams/merge_requests.html.haml index c9af529e113..f16331e1cdd 100644 --- a/app/views/teams/merge_requests.html.haml +++ b/app/views/teams/merge_requests.html.haml @@ -1,3 +1,5 @@ += render "team_head" + %h3.page_title Merge Requests %small (authored by or assigned to Team members) diff --git a/app/views/teams/new.html.haml b/app/views/teams/new.html.haml index d8312e0e913..a068c51e6ab 100644 --- a/app/views/teams/new.html.haml +++ b/app/views/teams/new.html.haml @@ -14,8 +14,6 @@ %hr .padded %ul - %li Team is kind of directory for several projects - %li All created teams are private + %li All created teams are public (users can view who enter into team and which project are assigned for this team) %li People within a team see only projects they have access to - %li All projects of team will be stored in team directory - %li You will be able to move existing projects into team + %li You will be able to assign existing projects for team diff --git a/app/views/teams/projects/_form.html.haml b/app/views/teams/projects/_form.html.haml new file mode 100644 index 00000000000..3749dbc4f99 --- /dev/null +++ b/app/views/teams/projects/_form.html.haml @@ -0,0 +1,16 @@ += form_tag team_project_path(@team, @project), method: :put do + -if @project.errors.any? + .alert-message.block-message.error + %ul + - @project.errors.full_messages.each do |msg| + %li= msg + + .clearfix + %label Max access for Team members: + .input + = select_tag :greatest_project_access, options_for_select(UserTeam.access_roles, @team.max_project_access(@project)), class: "project-access-select chosen span3" + + %br + .actions + = submit_tag 'Save', class: "btn primary" + = link_to 'Cancel', :back, class: "btn" diff --git a/app/views/teams/projects/edit.html.haml b/app/views/teams/projects/edit.html.haml index 66c9f0671ff..056ee6852c1 100644 --- a/app/views/teams/projects/edit.html.haml +++ b/app/views/teams/projects/edit.html.haml @@ -1,4 +1,18 @@ = render "teams/team_head" -%h1 Teams::Projects#edit -%p Find me in app/views/teams/projects/edit.html.haml +%h3 + Edit max access in #{@project.name} for #{@team.name} team + +%hr +%table.zebra-striped + %tr + %td Project: + %td= @project.name + %tr + %td Team: + %td= @team.name + %tr + %td Since: + %td= assigned_since(@team, @project).stamp("Nov 11, 2010") + += render 'form' diff --git a/app/views/teams/projects/index.html.haml b/app/views/teams/projects/index.html.haml index 66cb12a8421..b0a50e594cf 100644 --- a/app/views/teams/projects/index.html.haml +++ b/app/views/teams/projects/index.html.haml @@ -1,34 +1,34 @@ = render "teams/team_head" -%fieldset - %legend Projects (#{@user_team.projects.count}) - = form_tag delegate_projects_team_path(@user_team), id: "team_projects", class: "bulk_import", method: :post do - %table - %thead - %tr - %th Project name - %th Max access - %th - - @user_team.projects.each do |project| - %tr.project - %td - = link_to project.name_with_namespace, project - %td - %span= @user_team.human_max_project_access(project) - -# if current_user.can?(:manage_user_team, @user_team) - - relation = project.user_team_project_relationships.find_by_user_team_id(@user_team) - = form_for(relation, as: :project, url: team_project_path(@user_team, project)) do |f| - = f.select :greatest_access, options_for_select(UsersProject.access_roles, @user_team.max_project_access(project)), {}, class: "medium project-access-select span2" +%h3.page_title + Assigned projects (#{@team.projects.count}) + %small + Read more about project permissions + %strong= link_to "here", help_permissions_path, class: "vlink" - - if current_user.can?(:admin_user_team, @user_team) - %td.bgred - -#= link_to 'Edit max access', edit_project_team_path(@user_team, project), class: "btn small" - = link_to 'Relegate', relegate_project_team_path(@user_team, project_id: project.id), confirm: 'Remove project from team and move to global namespace. Are you sure?', method: :delete, class: "btn danger small" - - else - %td + - if current_user.can?(:manage_user_team, @team) && @avaliable_projects.any? + %span.right + = link_to new_team_project_path(@team), class: "btn success small grouped", title: "New Team Member" do + Assign project to Team - - if @avaliable_projects.any? - %tr - %td= select_tag :project_ids, options_from_collection_for_select(@avaliable_projects , :id, :name_with_namespace), multiple: true, data: {placeholder: 'Select projects'}, class: 'chosen span5' - %td= select_tag :greatest_project_access, options_for_select(Project.access_options), {class: "project-access-select chosen span3" } - %td= submit_tag 'Add', class: "btn primary" +%hr + +%table + %thead + %tr + %th Project name + %th Max access + - if current_user.can?(:admin_user_team, @team) + %th.span3 + + - @team.projects.each do |project| + %tr.project + %td + = link_to project.name_with_namespace, project_path(project) + %td + %span= @team.human_max_project_access(project) + + - if current_user.can?(:admin_user_team, @team) + %td.bgred + = link_to 'Edit max access', edit_team_project_path(@team, project), class: "btn small" + = 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 danger small" diff --git a/app/views/teams/projects/new.html.haml b/app/views/teams/projects/new.html.haml index 24d2d4c34ca..000f62bb643 100644 --- a/app/views/teams/projects/new.html.haml +++ b/app/views/teams/projects/new.html.haml @@ -1,4 +1,25 @@ = render "teams/team_head" -%h1 Teams::Projects#new -%p Find me in app/views/teams/projects/new.html.haml +%h3.page_title + Team: #{@team.name} + +%fieldset + %legend Projects (#{@team.projects.count}) + = form_tag team_projects_path(@team), id: "assign_projects", class: "bulk_import", method: :post do + %table#projects_list + %thead + %tr + %th Project name + %th Max access + %th + - @team.projects.each do |project| + %tr.project + %td + = link_to project.name_with_namespace, team_project_path(@team, project) + %td + %span= @team.human_max_project_access(project) + %td + %tr + %td= select_tag :project_ids, options_from_collection_for_select(@avaliable_projects , :id, :name_with_namespace), multiple: true, data: {placeholder: 'Select projects'}, class: 'chosen span5' + %td= select_tag :greatest_project_access, options_for_select(UserTeam.access_roles), {class: "project-access-select chosen span3" } + %td= submit_tag 'Add', class: "btn primary", id: :assign_projects_to_team diff --git a/app/views/teams/projects/show.html.haml b/app/views/teams/projects/show.html.haml deleted file mode 100644 index 66c9f0671ff..00000000000 --- a/app/views/teams/projects/show.html.haml +++ /dev/null @@ -1,4 +0,0 @@ -= render "teams/team_head" - -%h1 Teams::Projects#edit -%p Find me in app/views/teams/projects/edit.html.haml diff --git a/app/views/teams/search.html.haml b/app/views/teams/search.html.haml index 601f2d57c8b..5c357c5cfcb 100644 --- a/app/views/teams/search.html.haml +++ b/app/views/teams/search.html.haml @@ -1,6 +1,6 @@ = render "team_head" -= form_tag search_team_path(@user_team), method: :get, class: 'form-inline' do |f| += form_tag search_team_path(@team), method: :get, class: 'form-inline' do |f| .padded = label_tag :search do %strong Looking for From 31d84d71d3659dc815875f39f466cdcf81d97aaf Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Wed, 23 Jan 2013 18:14:20 +0400 Subject: [PATCH 38/56] assign team to project from project page in public section --- .../projects/application_controller.rb | 11 ++++++++ app/controllers/projects/teams_controller.rb | 27 +++++++++++++++++++ app/helpers/projects_helper.rb | 4 +++ app/models/user_team.rb | 2 ++ app/models/user_team_project_relationship.rb | 4 +++ app/views/projects/_project_head.html.haml | 2 +- app/views/projects/teams/avaliable.html.haml | 22 +++++++++++++++ app/views/team_members/_show_team.html.haml | 15 +++++++++++ app/views/team_members/_teams.html.haml | 16 +++++++++++ app/views/team_members/import.html.haml | 2 +- app/views/team_members/index.html.haml | 15 ++++++++++- config/routes.rb | 12 +++++++++ 12 files changed, 129 insertions(+), 3 deletions(-) create mode 100644 app/controllers/projects/application_controller.rb create mode 100644 app/controllers/projects/teams_controller.rb create mode 100644 app/views/projects/teams/avaliable.html.haml create mode 100644 app/views/team_members/_show_team.html.haml create mode 100644 app/views/team_members/_teams.html.haml diff --git a/app/controllers/projects/application_controller.rb b/app/controllers/projects/application_controller.rb new file mode 100644 index 00000000000..7e4776d2d75 --- /dev/null +++ b/app/controllers/projects/application_controller.rb @@ -0,0 +1,11 @@ +class Projects::ApplicationController < ApplicationController + + before_filter :authorize_admin_team_member! + + protected + + def user_team + @team ||= UserTeam.find_by_path(params[:id]) + end + +end diff --git a/app/controllers/projects/teams_controller.rb b/app/controllers/projects/teams_controller.rb new file mode 100644 index 00000000000..c04835ed153 --- /dev/null +++ b/app/controllers/projects/teams_controller.rb @@ -0,0 +1,27 @@ +class Projects::TeamsController < Projects::ApplicationController + + def avaliable + @teams = current_user.is_admin? ? UserTeam.scoped : current_user.user_teams + @teams = @teams.without_project(project) + unless @teams.any? + redirect_to project_team_index_path(project), notice: "No avaliable teams for assigment." + end + end + + def assign + unless params[:team_id].blank? + team = UserTeam.find(params[:team_id]) + access = params[:greatest_project_access] + team.assign_to_project(project, access) + end + redirect_to project_team_index_path(project) + end + + def resign + team = project.user_teams.find_by_path(params[:id]) + team.resign_from_project(project) + + redirect_to project_team_index_path(project) + end + +end diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index dbd47998eb1..c6cb9129499 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -3,6 +3,10 @@ module ProjectsHelper @project.users_projects.sort_by(&:project_access).reverse.group_by(&:project_access) end + def grouper_project_teams(project) + @project.user_team_project_relationships.sort_by(&:greatest_access).reverse.group_by(&:greatest_access) + end + def remove_from_project_team_message(project, user) "You are going to remove #{user.name} from #{project.name} project team. Are you sure?" end diff --git a/app/models/user_team.rb b/app/models/user_team.rb index 2e2f75060c3..0442123fc24 100644 --- a/app/models/user_team.rb +++ b/app/models/user_team.rb @@ -16,6 +16,8 @@ class UserTeam < ActiveRecord::Base message: "only letters, digits & '_' '-' '.' allowed. Letter should be first" } scope :with_member, ->(user){ joins(:user_team_user_relationships).where(user_team_user_relationships: {user_id: user.id}) } + scope :with_project, ->(project){ joins(:user_team_project_relationships).where(user_team_project_relationships: {project_id: project})} + scope :without_project, ->(project){ where("id NOT IN (:ids)", ids: with_project(project))} scope :created_by, ->(user){ where(owner_id: user) } class << self diff --git a/app/models/user_team_project_relationship.rb b/app/models/user_team_project_relationship.rb index 4413c492a6d..1b0368c7ecc 100644 --- a/app/models/user_team_project_relationship.rb +++ b/app/models/user_team_project_relationship.rb @@ -10,6 +10,10 @@ class UserTeamProjectRelationship < ActiveRecord::Base scope :with_project, ->(project){ where(project_id: project.id) } + def team_name + user_team.name + end + private def check_greatest_access diff --git a/app/views/projects/_project_head.html.haml b/app/views/projects/_project_head.html.haml index 94052650694..cc215502859 100644 --- a/app/views/projects/_project_head.html.haml +++ b/app/views/projects/_project_head.html.haml @@ -3,7 +3,7 @@ = link_to project_path(@project), class: "activities-tab tab" do %i.icon-home Show - = nav_link(controller: :team_members) do + = nav_link(controller: [:team_members, :teams]) do = link_to project_team_index_path(@project), class: "team-tab tab" do %i.icon-user Team diff --git a/app/views/projects/teams/avaliable.html.haml b/app/views/projects/teams/avaliable.html.haml new file mode 100644 index 00000000000..814e216d6ad --- /dev/null +++ b/app/views/projects/teams/avaliable.html.haml @@ -0,0 +1,22 @@ += render "projects/project_head" + +%h3.page_title + = "Assign project to team of users" +%hr +%p.slead + Read more about assign to team of users #{link_to "here", '#', class: 'vlink'}. += form_tag assign_project_teams_path(@project), method: 'post' do + %p.slead Choose Team of users you want to assign: + .padded + = label_tag :team_id, "Team" + .input= select_tag(:team_id, options_from_collection_for_select(@teams, :id, :name), prompt: "Select team", class: "chosen xxlarge", required: true) + %p.slead Choose greatest user acces in team you want to assign: + .padded + = label_tag :team_ids, "Permission" + .input= select_tag :greatest_project_access, options_for_select(UserTeam.access_roles), {class: "project-access-select chosen span3" } + + + .actions + = submit_tag 'Assign', class: "btn save-btn" + = link_to "Cancel", project_team_index_path(@project), class: "btn cancel-btn" + diff --git a/app/views/team_members/_show_team.html.haml b/app/views/team_members/_show_team.html.haml new file mode 100644 index 00000000000..da0262efda5 --- /dev/null +++ b/app/views/team_members/_show_team.html.haml @@ -0,0 +1,15 @@ +- team = team_rel.user_team +- allow_admin = can? current_user, :admin_team_member, @project +%li{id: dom_id(team), class: "user_team_row team_#{team.id}"} + .row + .span6 + %strong= link_to team.name, team_path(team), title: team.name, class: "dark" + %br + %small.cgray Members: #{team.members.count} + + .span5.right + .right + - if allow_admin + .left + = link_to resign_project_team_path(@project, team), method: :delete, confirm: "Are you shure?", class: "btn danger small" do + %i.icon-minus.icon-white diff --git a/app/views/team_members/_teams.html.haml b/app/views/team_members/_teams.html.haml new file mode 100644 index 00000000000..156fdd1befa --- /dev/null +++ b/app/views/team_members/_teams.html.haml @@ -0,0 +1,16 @@ +- grouper_project_teams(@project).each do |access, teams| + .ui-box + %h5.title + = UserTeam.access_roles.key(access).pluralize + %small= teams.size + %ul.well-list + - teams.sort_by(&:team_name).each do |tofr| + = render(partial: 'team_members/show_team', locals: {team_rel: tofr}) + + +:javascript + $(function(){ + $('.repo-access-select, .project-access-select').live("change", function() { + $(this.form).submit(); + }); + }) diff --git a/app/views/team_members/import.html.haml b/app/views/team_members/import.html.haml index de82f416248..135db946041 100644 --- a/app/views/team_members/import.html.haml +++ b/app/views/team_members/import.html.haml @@ -4,7 +4,7 @@ = "Import team from another project" %hr %p.slead - Read more about team import #{link_to "here", '#', class: 'vlink'}. + Read more about project team import #{link_to "here", '#', class: 'vlink'}. = form_tag apply_import_project_team_members_path(@project), method: 'post' do %p.slead Choose project you want to use as team source: .padded diff --git a/app/views/team_members/index.html.haml b/app/views/team_members/index.html.haml index 8ba13939a30..f694ccbca93 100644 --- a/app/views/team_members/index.html.haml +++ b/app/views/team_members/index.html.haml @@ -10,11 +10,24 @@ %span.right = link_to import_project_team_members_path(@project), class: "btn small grouped", title: "Import team from another project" do Import team from another project + = link_to avaliable_project_teams_path(@project), class: "btn small grouped", title: "Assign project to team of users" do + Assign project to Team of users = link_to new_project_team_member_path(@project), class: "btn success small grouped", title: "New Team Member" do New Team Member -%hr +%hr .clearfix %div.team-table = render partial: "team_members/team", locals: {project: @project} + + +%h3.page_title + Assigned teams + (#{@project.user_teams.count}) + +%hr + +.clearfix +%div.team-table + = render partial: "team_members/teams", locals: {project: @project} diff --git a/config/routes.rb b/config/routes.rb index e8af16387bc..a19ab14f605 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -269,6 +269,18 @@ Gitlab::Application.routes.draw do end end + scope module: :projects do + resources :teams, only: [] do + collection do + get :avaliable + post :assign + end + member do + delete :resign + end + end + end + resources :notes, only: [:index, :create, :destroy] do collection do post :preview From d721863382b3e2cedae03e8f235809eb409224c0 Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Wed, 23 Jan 2013 18:14:53 +0400 Subject: [PATCH 39/56] Fix little bugs --- app/controllers/teams_controller.rb | 2 ++ app/helpers/user_teams_helper.rb | 4 ++-- config/routes.rb | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/controllers/teams_controller.rb b/app/controllers/teams_controller.rb index 169ee34f4ec..ea060b3a44d 100644 --- a/app/controllers/teams_controller.rb +++ b/app/controllers/teams_controller.rb @@ -54,6 +54,7 @@ class TeamsController < ApplicationController # Get authored or assigned open merge requests def merge_requests + projects @merge_requests = MergeRequest.of_user_team(user_team) @merge_requests = FilterContext.new(@merge_requests, params).execute @merge_requests = @merge_requests.recent.page(params[:page]).per(20) @@ -61,6 +62,7 @@ class TeamsController < ApplicationController # Get only assigned issues def issues + projects @issues = Issue.of_user_team(user_team) @issues = FilterContext.new(@issues, params).execute @issues = @issues.recent.page(params[:page]).per(20) diff --git a/app/helpers/user_teams_helper.rb b/app/helpers/user_teams_helper.rb index 60deb9e09e5..2055bb3c8bc 100644 --- a/app/helpers/user_teams_helper.rb +++ b/app/helpers/user_teams_helper.rb @@ -9,9 +9,9 @@ module UserTeamsHelper case entity when 'issue' then - issues_team_path(@user_team, options) + issues_team_path(@team, options) when 'merge_request' - merge_requests_team_path(@user_team, options) + merge_requests_team_path(@team, options) end end diff --git a/config/routes.rb b/config/routes.rb index a19ab14f605..387f94ba025 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -21,7 +21,7 @@ Gitlab::Application.routes.draw do project_root: Gitlab.config.gitolite.repos_path, upload_pack: Gitlab.config.gitolite.upload_pack, receive_pack: Gitlab.config.gitolite.receive_pack - }), at: '/', constraints: lambda { |request| /[-\/\w\.-]+\.git\//.match(request.path_info) } + }), at: '/', constraints: lambda { |request| /[-\/\w\.]+\.git\//.match(request.path_info) } # # Help From a5ce8696a6aa5a3a588fc618d8c959ce6c687310 Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Wed, 23 Jan 2013 20:42:38 +0400 Subject: [PATCH 40/56] remove unused autogenerated files --- .../javascripts/admin/teams/members.js.coffee | 3 -- .../admin/teams/projects.js.coffee | 3 -- .../stylesheets/admin/teams/members.css.scss | 3 -- .../stylesheets/admin/teams/projects.css.scss | 3 -- .../admin/projects/members_controller_spec.rb | 26 --------- .../admin/teams/members_controller_spec.rb | 40 -------------- .../admin/teams/projects_controller_spec.rb | 40 -------------- .../admin/teams_controller_spec.rb | 47 ---------------- .../teams/members_controller_spec.rb | 47 ---------------- .../teams/projects_controller_spec.rb | 47 ---------------- spec/controllers/teams_controller_spec.rb | 54 ------------------- .../admin/teams/members_helper_spec.rb | 15 ------ .../admin/teams/projects_helper_spec.rb | 15 ------ .../admin/teams/create.html.haml_spec.rb | 5 -- .../admin/teams/destroy.html.haml_spec.rb | 5 -- spec/views/admin/teams/edit.html.haml_spec.rb | 5 -- .../views/admin/teams/index.html.haml_spec.rb | 5 -- .../teams/members/create.html.haml_spec.rb | 5 -- .../teams/members/destroy.html.haml_spec.rb | 5 -- .../teams/members/edit.html.haml_spec.rb | 5 -- .../admin/teams/members/new.html.haml_spec.rb | 5 -- .../teams/members/update.html.haml_spec.rb | 5 -- .../teams/projects/create.html.haml_spec.rb | 5 -- .../teams/projects/destroy.html.haml_spec.rb | 5 -- .../teams/projects/edit.html.haml_spec.rb | 5 -- .../teams/projects/new.html.haml_spec.rb | 5 -- .../teams/projects/update.html.haml_spec.rb | 5 -- spec/views/admin/teams/show.html.haml_spec.rb | 5 -- .../admin/teams/update.html.haml_spec.rb | 5 -- spec/views/teams/create.html.haml_spec.rb | 5 -- spec/views/teams/destroy.html.haml_spec.rb | 5 -- spec/views/teams/edit.html.haml_spec.rb | 5 -- spec/views/teams/index.html.haml_spec.rb | 5 -- .../teams/members/create.html.haml_spec.rb | 5 -- .../teams/members/destroy.html.haml_spec.rb | 5 -- .../teams/members/edit.html.haml_spec.rb | 5 -- .../teams/members/index.html.haml_spec.rb | 5 -- .../views/teams/members/new.html.haml_spec.rb | 5 -- .../teams/members/update.html.haml_spec.rb | 5 -- spec/views/teams/new.html.haml_spec.rb | 5 -- .../teams/projects/create.html.haml_spec.rb | 5 -- .../teams/projects/destroy.html.haml_spec.rb | 5 -- .../teams/projects/edit.html.haml_spec.rb | 5 -- .../teams/projects/index.html.haml_spec.rb | 5 -- .../teams/projects/new.html.haml_spec.rb | 5 -- .../teams/projects/update.html.haml_spec.rb | 5 -- spec/views/teams/show.html.haml_spec.rb | 5 -- spec/views/teams/update.html.haml_spec.rb | 5 -- 48 files changed, 518 deletions(-) delete mode 100644 app/assets/javascripts/admin/teams/members.js.coffee delete mode 100644 app/assets/javascripts/admin/teams/projects.js.coffee delete mode 100644 app/assets/stylesheets/admin/teams/members.css.scss delete mode 100644 app/assets/stylesheets/admin/teams/projects.css.scss delete mode 100644 spec/controllers/admin/projects/members_controller_spec.rb delete mode 100644 spec/controllers/admin/teams/members_controller_spec.rb delete mode 100644 spec/controllers/admin/teams/projects_controller_spec.rb delete mode 100644 spec/controllers/admin/teams_controller_spec.rb delete mode 100644 spec/controllers/teams/members_controller_spec.rb delete mode 100644 spec/controllers/teams/projects_controller_spec.rb delete mode 100644 spec/controllers/teams_controller_spec.rb delete mode 100644 spec/helpers/admin/teams/members_helper_spec.rb delete mode 100644 spec/helpers/admin/teams/projects_helper_spec.rb delete mode 100644 spec/views/admin/teams/create.html.haml_spec.rb delete mode 100644 spec/views/admin/teams/destroy.html.haml_spec.rb delete mode 100644 spec/views/admin/teams/edit.html.haml_spec.rb delete mode 100644 spec/views/admin/teams/index.html.haml_spec.rb delete mode 100644 spec/views/admin/teams/members/create.html.haml_spec.rb delete mode 100644 spec/views/admin/teams/members/destroy.html.haml_spec.rb delete mode 100644 spec/views/admin/teams/members/edit.html.haml_spec.rb delete mode 100644 spec/views/admin/teams/members/new.html.haml_spec.rb delete mode 100644 spec/views/admin/teams/members/update.html.haml_spec.rb delete mode 100644 spec/views/admin/teams/projects/create.html.haml_spec.rb delete mode 100644 spec/views/admin/teams/projects/destroy.html.haml_spec.rb delete mode 100644 spec/views/admin/teams/projects/edit.html.haml_spec.rb delete mode 100644 spec/views/admin/teams/projects/new.html.haml_spec.rb delete mode 100644 spec/views/admin/teams/projects/update.html.haml_spec.rb delete mode 100644 spec/views/admin/teams/show.html.haml_spec.rb delete mode 100644 spec/views/admin/teams/update.html.haml_spec.rb delete mode 100644 spec/views/teams/create.html.haml_spec.rb delete mode 100644 spec/views/teams/destroy.html.haml_spec.rb delete mode 100644 spec/views/teams/edit.html.haml_spec.rb delete mode 100644 spec/views/teams/index.html.haml_spec.rb delete mode 100644 spec/views/teams/members/create.html.haml_spec.rb delete mode 100644 spec/views/teams/members/destroy.html.haml_spec.rb delete mode 100644 spec/views/teams/members/edit.html.haml_spec.rb delete mode 100644 spec/views/teams/members/index.html.haml_spec.rb delete mode 100644 spec/views/teams/members/new.html.haml_spec.rb delete mode 100644 spec/views/teams/members/update.html.haml_spec.rb delete mode 100644 spec/views/teams/new.html.haml_spec.rb delete mode 100644 spec/views/teams/projects/create.html.haml_spec.rb delete mode 100644 spec/views/teams/projects/destroy.html.haml_spec.rb delete mode 100644 spec/views/teams/projects/edit.html.haml_spec.rb delete mode 100644 spec/views/teams/projects/index.html.haml_spec.rb delete mode 100644 spec/views/teams/projects/new.html.haml_spec.rb delete mode 100644 spec/views/teams/projects/update.html.haml_spec.rb delete mode 100644 spec/views/teams/show.html.haml_spec.rb delete mode 100644 spec/views/teams/update.html.haml_spec.rb diff --git a/app/assets/javascripts/admin/teams/members.js.coffee b/app/assets/javascripts/admin/teams/members.js.coffee deleted file mode 100644 index 761567942fc..00000000000 --- a/app/assets/javascripts/admin/teams/members.js.coffee +++ /dev/null @@ -1,3 +0,0 @@ -# Place all the behaviors and hooks related to the matching controller here. -# All this logic will automatically be available in application.js. -# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/javascripts/admin/teams/projects.js.coffee b/app/assets/javascripts/admin/teams/projects.js.coffee deleted file mode 100644 index 761567942fc..00000000000 --- a/app/assets/javascripts/admin/teams/projects.js.coffee +++ /dev/null @@ -1,3 +0,0 @@ -# Place all the behaviors and hooks related to the matching controller here. -# All this logic will automatically be available in application.js. -# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/stylesheets/admin/teams/members.css.scss b/app/assets/stylesheets/admin/teams/members.css.scss deleted file mode 100644 index 47c2273c1c2..00000000000 --- a/app/assets/stylesheets/admin/teams/members.css.scss +++ /dev/null @@ -1,3 +0,0 @@ -// Place all the styles related to the Admin::Teams::Members controller here. -// They will automatically be included in application.css. -// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/admin/teams/projects.css.scss b/app/assets/stylesheets/admin/teams/projects.css.scss deleted file mode 100644 index e6a6ec39043..00000000000 --- a/app/assets/stylesheets/admin/teams/projects.css.scss +++ /dev/null @@ -1,3 +0,0 @@ -// Place all the styles related to the Admin::Teams::Projects controller here. -// They will automatically be included in application.css. -// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/spec/controllers/admin/projects/members_controller_spec.rb b/spec/controllers/admin/projects/members_controller_spec.rb deleted file mode 100644 index 73625e33d70..00000000000 --- a/spec/controllers/admin/projects/members_controller_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -require 'spec_helper' - -describe Admin::Projects::MembersController do - - describe "GET 'edit'" do - it "returns http success" do - get 'edit' - response.should be_success - end - end - - describe "GET 'update'" do - it "returns http success" do - get 'update' - response.should be_success - end - end - - describe "GET 'destroy'" do - it "returns http success" do - get 'destroy' - response.should be_success - end - end - -end diff --git a/spec/controllers/admin/teams/members_controller_spec.rb b/spec/controllers/admin/teams/members_controller_spec.rb deleted file mode 100644 index a9e41be59f7..00000000000 --- a/spec/controllers/admin/teams/members_controller_spec.rb +++ /dev/null @@ -1,40 +0,0 @@ -require 'spec_helper' - -describe Admin::Teams::MembersController do - - describe "GET 'new'" do - it "returns http success" do - get 'new' - response.should be_success - end - end - - describe "GET 'create'" do - it "returns http success" do - get 'create' - response.should be_success - end - end - - describe "GET 'edit'" do - it "returns http success" do - get 'edit' - response.should be_success - end - end - - describe "GET 'update'" do - it "returns http success" do - get 'update' - response.should be_success - end - end - - describe "GET 'destroy'" do - it "returns http success" do - get 'destroy' - response.should be_success - end - end - -end diff --git a/spec/controllers/admin/teams/projects_controller_spec.rb b/spec/controllers/admin/teams/projects_controller_spec.rb deleted file mode 100644 index 7fe6ee0ca26..00000000000 --- a/spec/controllers/admin/teams/projects_controller_spec.rb +++ /dev/null @@ -1,40 +0,0 @@ -require 'spec_helper' - -describe Admin::Teams::ProjectsController do - - describe "GET 'new'" do - it "returns http success" do - get 'new' - response.should be_success - end - end - - describe "GET 'create'" do - it "returns http success" do - get 'create' - response.should be_success - end - end - - describe "GET 'edit'" do - it "returns http success" do - get 'edit' - response.should be_success - end - end - - describe "GET 'update'" do - it "returns http success" do - get 'update' - response.should be_success - end - end - - describe "GET 'destroy'" do - it "returns http success" do - get 'destroy' - response.should be_success - end - end - -end diff --git a/spec/controllers/admin/teams_controller_spec.rb b/spec/controllers/admin/teams_controller_spec.rb deleted file mode 100644 index 02d8f86a79d..00000000000 --- a/spec/controllers/admin/teams_controller_spec.rb +++ /dev/null @@ -1,47 +0,0 @@ -require 'spec_helper' - -describe Admin::TeamsController do - - describe "GET 'index'" do - it "returns http success" do - get 'index' - response.should be_success - end - end - - describe "GET 'show'" do - it "returns http success" do - get 'show' - response.should be_success - end - end - - describe "GET 'create'" do - it "returns http success" do - get 'create' - response.should be_success - end - end - - describe "GET 'edit'" do - it "returns http success" do - get 'edit' - response.should be_success - end - end - - describe "GET 'update'" do - it "returns http success" do - get 'update' - response.should be_success - end - end - - describe "GET 'destroy'" do - it "returns http success" do - get 'destroy' - response.should be_success - end - end - -end diff --git a/spec/controllers/teams/members_controller_spec.rb b/spec/controllers/teams/members_controller_spec.rb deleted file mode 100644 index e1ac558a6cd..00000000000 --- a/spec/controllers/teams/members_controller_spec.rb +++ /dev/null @@ -1,47 +0,0 @@ -require 'spec_helper' - -describe Teams::MembersController do - - describe "GET 'index'" do - it "returns http success" do - get 'index' - response.should be_success - end - end - - describe "GET 'new'" do - it "returns http success" do - get 'new' - response.should be_success - end - end - - describe "GET 'create'" do - it "returns http success" do - get 'create' - response.should be_success - end - end - - describe "GET 'edit'" do - it "returns http success" do - get 'edit' - response.should be_success - end - end - - describe "GET 'update'" do - it "returns http success" do - get 'update' - response.should be_success - end - end - - describe "GET 'destroy'" do - it "returns http success" do - get 'destroy' - response.should be_success - end - end - -end diff --git a/spec/controllers/teams/projects_controller_spec.rb b/spec/controllers/teams/projects_controller_spec.rb deleted file mode 100644 index b379c3721bb..00000000000 --- a/spec/controllers/teams/projects_controller_spec.rb +++ /dev/null @@ -1,47 +0,0 @@ -require 'spec_helper' - -describe Teams::ProjectsController do - - describe "GET 'index'" do - it "returns http success" do - get 'index' - response.should be_success - end - end - - describe "GET 'new'" do - it "returns http success" do - get 'new' - response.should be_success - end - end - - describe "GET 'create'" do - it "returns http success" do - get 'create' - response.should be_success - end - end - - describe "GET 'edit'" do - it "returns http success" do - get 'edit' - response.should be_success - end - end - - describe "GET 'update'" do - it "returns http success" do - get 'update' - response.should be_success - end - end - - describe "GET 'destroy'" do - it "returns http success" do - get 'destroy' - response.should be_success - end - end - -end diff --git a/spec/controllers/teams_controller_spec.rb b/spec/controllers/teams_controller_spec.rb deleted file mode 100644 index 923261fce9c..00000000000 --- a/spec/controllers/teams_controller_spec.rb +++ /dev/null @@ -1,54 +0,0 @@ -require 'spec_helper' - -describe TeamsController do - - describe "GET 'index'" do - it "returns http success" do - get 'index' - response.should be_success - end - end - - describe "GET 'show'" do - it "returns http success" do - get 'show' - response.should be_success - end - end - - describe "GET 'new'" do - it "returns http success" do - get 'new' - response.should be_success - end - end - - describe "GET 'edit'" do - it "returns http success" do - get 'edit' - response.should be_success - end - end - - describe "GET 'update'" do - it "returns http success" do - get 'update' - response.should be_success - end - end - - describe "GET 'create'" do - it "returns http success" do - get 'create' - response.should be_success - end - end - - describe "GET 'destroy'" do - it "returns http success" do - get 'destroy' - response.should be_success - end - end - -end diff --git a/spec/helpers/admin/teams/members_helper_spec.rb b/spec/helpers/admin/teams/members_helper_spec.rb deleted file mode 100644 index ceef71c0be6..00000000000 --- a/spec/helpers/admin/teams/members_helper_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'spec_helper' - -# Specs in this file have access to a helper object that includes -# the Admin::Teams::MembersHelper. For example: -# -# describe Admin::Teams::MembersHelper do -# describe "string concat" do -# it "concats two strings with spaces" do -# helper.concat_strings("this","that").should == "this that" -# end -# end -# end -describe Admin::Teams::MembersHelper do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/helpers/admin/teams/projects_helper_spec.rb b/spec/helpers/admin/teams/projects_helper_spec.rb deleted file mode 100644 index 1c98d23cdb7..00000000000 --- a/spec/helpers/admin/teams/projects_helper_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'spec_helper' - -# Specs in this file have access to a helper object that includes -# the Admin::Teams::ProjectsHelper. For example: -# -# describe Admin::Teams::ProjectsHelper do -# describe "string concat" do -# it "concats two strings with spaces" do -# helper.concat_strings("this","that").should == "this that" -# end -# end -# end -describe Admin::Teams::ProjectsHelper do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/views/admin/teams/create.html.haml_spec.rb b/spec/views/admin/teams/create.html.haml_spec.rb deleted file mode 100644 index 27f57d89693..00000000000 --- a/spec/views/admin/teams/create.html.haml_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe "teams/create.html.haml" do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/views/admin/teams/destroy.html.haml_spec.rb b/spec/views/admin/teams/destroy.html.haml_spec.rb deleted file mode 100644 index 87670e4dc66..00000000000 --- a/spec/views/admin/teams/destroy.html.haml_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe "teams/destroy.html.haml" do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/views/admin/teams/edit.html.haml_spec.rb b/spec/views/admin/teams/edit.html.haml_spec.rb deleted file mode 100644 index 5180d713f7f..00000000000 --- a/spec/views/admin/teams/edit.html.haml_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe "teams/edit.html.haml" do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/views/admin/teams/index.html.haml_spec.rb b/spec/views/admin/teams/index.html.haml_spec.rb deleted file mode 100644 index 7a0d69bd316..00000000000 --- a/spec/views/admin/teams/index.html.haml_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe "teams/index.html.haml" do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/views/admin/teams/members/create.html.haml_spec.rb b/spec/views/admin/teams/members/create.html.haml_spec.rb deleted file mode 100644 index b6f817617e4..00000000000 --- a/spec/views/admin/teams/members/create.html.haml_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe "members/create.html.haml" do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/views/admin/teams/members/destroy.html.haml_spec.rb b/spec/views/admin/teams/members/destroy.html.haml_spec.rb deleted file mode 100644 index 3ff1634461c..00000000000 --- a/spec/views/admin/teams/members/destroy.html.haml_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe "members/destroy.html.haml" do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/views/admin/teams/members/edit.html.haml_spec.rb b/spec/views/admin/teams/members/edit.html.haml_spec.rb deleted file mode 100644 index 3e952e898a9..00000000000 --- a/spec/views/admin/teams/members/edit.html.haml_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe "members/edit.html.haml" do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/views/admin/teams/members/new.html.haml_spec.rb b/spec/views/admin/teams/members/new.html.haml_spec.rb deleted file mode 100644 index f03eed1f29f..00000000000 --- a/spec/views/admin/teams/members/new.html.haml_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe "members/new.html.haml" do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/views/admin/teams/members/update.html.haml_spec.rb b/spec/views/admin/teams/members/update.html.haml_spec.rb deleted file mode 100644 index 43b84bad99b..00000000000 --- a/spec/views/admin/teams/members/update.html.haml_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe "members/update.html.haml" do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/views/admin/teams/projects/create.html.haml_spec.rb b/spec/views/admin/teams/projects/create.html.haml_spec.rb deleted file mode 100644 index 74c4ee2d837..00000000000 --- a/spec/views/admin/teams/projects/create.html.haml_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe "projects/create.html.haml" do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/views/admin/teams/projects/destroy.html.haml_spec.rb b/spec/views/admin/teams/projects/destroy.html.haml_spec.rb deleted file mode 100644 index b3eee48f38b..00000000000 --- a/spec/views/admin/teams/projects/destroy.html.haml_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe "projects/destroy.html.haml" do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/views/admin/teams/projects/edit.html.haml_spec.rb b/spec/views/admin/teams/projects/edit.html.haml_spec.rb deleted file mode 100644 index ef41b7b0814..00000000000 --- a/spec/views/admin/teams/projects/edit.html.haml_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe "projects/edit.html.haml" do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/views/admin/teams/projects/new.html.haml_spec.rb b/spec/views/admin/teams/projects/new.html.haml_spec.rb deleted file mode 100644 index 9ee68e5ae05..00000000000 --- a/spec/views/admin/teams/projects/new.html.haml_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe "projects/new.html.haml" do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/views/admin/teams/projects/update.html.haml_spec.rb b/spec/views/admin/teams/projects/update.html.haml_spec.rb deleted file mode 100644 index fdaafd3924b..00000000000 --- a/spec/views/admin/teams/projects/update.html.haml_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe "projects/update.html.haml" do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/views/admin/teams/show.html.haml_spec.rb b/spec/views/admin/teams/show.html.haml_spec.rb deleted file mode 100644 index b7f7b669c2e..00000000000 --- a/spec/views/admin/teams/show.html.haml_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe "teams/show.html.haml" do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/views/admin/teams/update.html.haml_spec.rb b/spec/views/admin/teams/update.html.haml_spec.rb deleted file mode 100644 index b28cfa4f699..00000000000 --- a/spec/views/admin/teams/update.html.haml_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe "teams/update.html.haml" do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/views/teams/create.html.haml_spec.rb b/spec/views/teams/create.html.haml_spec.rb deleted file mode 100644 index 27f57d89693..00000000000 --- a/spec/views/teams/create.html.haml_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe "teams/create.html.haml" do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/views/teams/destroy.html.haml_spec.rb b/spec/views/teams/destroy.html.haml_spec.rb deleted file mode 100644 index 87670e4dc66..00000000000 --- a/spec/views/teams/destroy.html.haml_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe "teams/destroy.html.haml" do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/views/teams/edit.html.haml_spec.rb b/spec/views/teams/edit.html.haml_spec.rb deleted file mode 100644 index 5180d713f7f..00000000000 --- a/spec/views/teams/edit.html.haml_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe "teams/edit.html.haml" do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/views/teams/index.html.haml_spec.rb b/spec/views/teams/index.html.haml_spec.rb deleted file mode 100644 index 7a0d69bd316..00000000000 --- a/spec/views/teams/index.html.haml_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe "teams/index.html.haml" do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/views/teams/members/create.html.haml_spec.rb b/spec/views/teams/members/create.html.haml_spec.rb deleted file mode 100644 index b6f817617e4..00000000000 --- a/spec/views/teams/members/create.html.haml_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe "members/create.html.haml" do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/views/teams/members/destroy.html.haml_spec.rb b/spec/views/teams/members/destroy.html.haml_spec.rb deleted file mode 100644 index 3ff1634461c..00000000000 --- a/spec/views/teams/members/destroy.html.haml_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe "members/destroy.html.haml" do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/views/teams/members/edit.html.haml_spec.rb b/spec/views/teams/members/edit.html.haml_spec.rb deleted file mode 100644 index 3e952e898a9..00000000000 --- a/spec/views/teams/members/edit.html.haml_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe "members/edit.html.haml" do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/views/teams/members/index.html.haml_spec.rb b/spec/views/teams/members/index.html.haml_spec.rb deleted file mode 100644 index 363430d769f..00000000000 --- a/spec/views/teams/members/index.html.haml_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe "members/index.html.haml" do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/views/teams/members/new.html.haml_spec.rb b/spec/views/teams/members/new.html.haml_spec.rb deleted file mode 100644 index f03eed1f29f..00000000000 --- a/spec/views/teams/members/new.html.haml_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe "members/new.html.haml" do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/views/teams/members/update.html.haml_spec.rb b/spec/views/teams/members/update.html.haml_spec.rb deleted file mode 100644 index 43b84bad99b..00000000000 --- a/spec/views/teams/members/update.html.haml_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe "members/update.html.haml" do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/views/teams/new.html.haml_spec.rb b/spec/views/teams/new.html.haml_spec.rb deleted file mode 100644 index 8ef621b708f..00000000000 --- a/spec/views/teams/new.html.haml_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe "teams/new.html.haml" do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/views/teams/projects/create.html.haml_spec.rb b/spec/views/teams/projects/create.html.haml_spec.rb deleted file mode 100644 index 74c4ee2d837..00000000000 --- a/spec/views/teams/projects/create.html.haml_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe "projects/create.html.haml" do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/views/teams/projects/destroy.html.haml_spec.rb b/spec/views/teams/projects/destroy.html.haml_spec.rb deleted file mode 100644 index b3eee48f38b..00000000000 --- a/spec/views/teams/projects/destroy.html.haml_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe "projects/destroy.html.haml" do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/views/teams/projects/edit.html.haml_spec.rb b/spec/views/teams/projects/edit.html.haml_spec.rb deleted file mode 100644 index ef41b7b0814..00000000000 --- a/spec/views/teams/projects/edit.html.haml_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe "projects/edit.html.haml" do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/views/teams/projects/index.html.haml_spec.rb b/spec/views/teams/projects/index.html.haml_spec.rb deleted file mode 100644 index 8cf0dbcd954..00000000000 --- a/spec/views/teams/projects/index.html.haml_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe "projects/index.html.haml" do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/views/teams/projects/new.html.haml_spec.rb b/spec/views/teams/projects/new.html.haml_spec.rb deleted file mode 100644 index 9ee68e5ae05..00000000000 --- a/spec/views/teams/projects/new.html.haml_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe "projects/new.html.haml" do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/views/teams/projects/update.html.haml_spec.rb b/spec/views/teams/projects/update.html.haml_spec.rb deleted file mode 100644 index fdaafd3924b..00000000000 --- a/spec/views/teams/projects/update.html.haml_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe "projects/update.html.haml" do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/views/teams/show.html.haml_spec.rb b/spec/views/teams/show.html.haml_spec.rb deleted file mode 100644 index b7f7b669c2e..00000000000 --- a/spec/views/teams/show.html.haml_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe "teams/show.html.haml" do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/views/teams/update.html.haml_spec.rb b/spec/views/teams/update.html.haml_spec.rb deleted file mode 100644 index b28cfa4f699..00000000000 --- a/spec/views/teams/update.html.haml_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe "teams/update.html.haml" do - pending "add some examples to (or delete) #{__FILE__}" -end From eb99feb4a7e01c4e83203ec014c082205b77ad02 Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Wed, 23 Jan 2013 20:43:23 +0400 Subject: [PATCH 41/56] simple refactoring --- app/assets/javascripts/dashboard.js.coffee | 8 ++++---- .../javascripts/merge_requests.js.coffee | 18 +++++++++--------- .../user_team_project_relationships.rb | 6 +++--- spec/factories/user_team_user_relationships.rb | 6 +++--- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/app/assets/javascripts/dashboard.js.coffee b/app/assets/javascripts/dashboard.js.coffee index f15d09dd475..6171e0d50fd 100644 --- a/app/assets/javascripts/dashboard.js.coffee +++ b/app/assets/javascripts/dashboard.js.coffee @@ -4,11 +4,11 @@ window.dashboardPage = -> event.preventDefault() toggleFilter $(this) reloadActivities() - + reloadActivities = -> $(".content_list").html '' Pager.init 20, true - + toggleFilter = (sender) -> sender.parent().toggleClass "inactive" event_filters = $.cookie("event_filter") @@ -17,11 +17,11 @@ toggleFilter = (sender) -> event_filters = event_filters.split(",") else event_filters = new Array() - + index = event_filters.indexOf(filter) if index is -1 event_filters.push filter else event_filters.splice index, 1 - + $.cookie "event_filter", event_filters.join(",") diff --git a/app/assets/javascripts/merge_requests.js.coffee b/app/assets/javascripts/merge_requests.js.coffee index 9c9cc6132b3..65ed817c7c6 100644 --- a/app/assets/javascripts/merge_requests.js.coffee +++ b/app/assets/javascripts/merge_requests.js.coffee @@ -1,6 +1,6 @@ # # * Filter merge requests -# +# @merge_requestsPage = -> $('#assignee_id').chosen() $('#milestone_id').chosen() @@ -8,16 +8,16 @@ $(this).closest('form').submit() class MergeRequest - + constructor: (@opts) -> this.$el = $('.merge-request') @diffs_loaded = false @commits_loaded = false - + this.activateTab(@opts.action) - + this.bindEvents() - + this.initMergeWidget() this.$('.show-all-commits').on 'click', => this.showAllCommits() @@ -28,7 +28,7 @@ class MergeRequest initMergeWidget: -> this.showState( @opts.current_state ) - + if this.$('.automerge_widget').length and @opts.check_enable $.get @opts.url_to_automerge_check, (data) => this.showState( data.state ) @@ -42,12 +42,12 @@ class MergeRequest bindEvents: -> this.$('.nav-tabs').on 'click', 'a', (event) => a = $(event.currentTarget) - + href = a.attr('href') History.replaceState {path: href}, document.title, href - + event.preventDefault() - + this.$('.nav-tabs').on 'click', 'li', (event) => this.activateTab($(event.currentTarget).data('action')) diff --git a/spec/factories/user_team_project_relationships.rb b/spec/factories/user_team_project_relationships.rb index fa0f26e7455..93c7b57d0fa 100644 --- a/spec/factories/user_team_project_relationships.rb +++ b/spec/factories/user_team_project_relationships.rb @@ -2,8 +2,8 @@ FactoryGirl.define do factory :user_team_project_relationship do - project_id 1 - user_team_id 1 - greatest_access 1 + project + user_team + greatest_access { UsersProject::MASTER } end end diff --git a/spec/factories/user_team_user_relationships.rb b/spec/factories/user_team_user_relationships.rb index 9b655e00686..55179f9a45b 100644 --- a/spec/factories/user_team_user_relationships.rb +++ b/spec/factories/user_team_user_relationships.rb @@ -2,9 +2,9 @@ FactoryGirl.define do factory :user_team_user_relationship do - user_id 1 - user_team_id 1 + user + user_team group_admin false - permission 1 + permission { UsersProject::MASTER } end end From 690db9693fcee3beedc467b48fd9e4bd42ee936d Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Wed, 23 Jan 2013 23:39:47 +0400 Subject: [PATCH 42/56] fix tests --- .../admin/teams/members_controller.rb | 7 ++--- app/controllers/teams/members_controller.rb | 11 +++---- app/views/admin/teams/show.html.haml | 6 ++-- app/views/teams/projects/index.html.haml | 2 +- features/admin/teams.feature | 3 -- features/steps/admin/admin_teams.rb | 18 ++++++----- features/steps/userteams/userteams.rb | 30 +++++++++++-------- features/support/env.rb | 2 +- features/teams/team.feature | 1 + spec/routing/admin_routing_spec.rb | 14 ++++----- 10 files changed, 47 insertions(+), 47 deletions(-) diff --git a/app/controllers/admin/teams/members_controller.rb b/app/controllers/admin/teams/members_controller.rb index cdcc96c0aef..7fd777dc72f 100644 --- a/app/controllers/admin/teams/members_controller.rb +++ b/app/controllers/admin/teams/members_controller.rb @@ -30,11 +30,8 @@ class Admin::Teams::MembersController < Admin::Teams::ApplicationController end def destroy - if user_team.remove_member(team_member) - redirect_to admin_team_path(user_team), notice: "Member #{team_member.name} was successfully removed from Team of users." - else - redirect_to admin_team_members(user_team), notice: "Something is wrong." - end + user_team.remove_member(team_member) + redirect_to admin_team_path(user_team), notice: "Member #{team_member.name} was successfully removed from Team of users." end protected diff --git a/app/controllers/teams/members_controller.rb b/app/controllers/teams/members_controller.rb index 95b8de1861b..56e952a3d40 100644 --- a/app/controllers/teams/members_controller.rb +++ b/app/controllers/teams/members_controller.rb @@ -20,7 +20,7 @@ class Teams::MembersController < Teams::ApplicationController user_team.add_members(user_ids, access, is_admin) end - redirect_to team_path(user_team), notice: 'Members was successfully added into Team of users.' + redirect_to team_members_path(user_team), notice: 'Members was successfully added into Team of users.' end def edit @@ -30,18 +30,15 @@ class Teams::MembersController < Teams::ApplicationController def update options = {default_projects_access: params[:default_project_access], group_admin: params[:group_admin]} if user_team.update_membership(team_member, options) - redirect_to team_path(user_team), notice: "Membership for #{team_member.name} was successfully updated in Team of users." + redirect_to team_members_path(user_team), notice: "Membership for #{team_member.name} was successfully updated in Team of users." else render :edit end end def destroy - if user_team.remove_member(team_member) - redirect_to team_path(user_team), notice: "Member #{team_member.name} was successfully removed from Team of users." - else - redirect_to team_members(user_team), notice: "Something is wrong." - end + user_team.remove_member(team_member) + redirect_to team_path(user_team), notice: "Member #{team_member.name} was successfully removed from Team of users." end protected diff --git a/app/views/admin/teams/show.html.haml b/app/views/admin/teams/show.html.haml index a7470c2d6e0..6a1deaff989 100644 --- a/app/views/admin/teams/show.html.haml +++ b/app/views/admin/teams/show.html.haml @@ -52,7 +52,7 @@ %th Team access %th.cred.span3 Danger Zone! - @team.members.each do |member| - %tr.member + %tr.member{ class: "user_#{member.id}"} %td = link_to [:admin, member] do = member.name @@ -62,7 +62,7 @@ %td.bgred = link_to 'Edit', edit_admin_team_member_path(@team, member), class: "btn small"   - = link_to 'Remove', admin_team_member_path(@team, member), confirm: 'Remove member from team. Are you sure?', method: :delete, class: "btn danger small" + = link_to 'Remove', admin_team_member_path(@team, member), confirm: 'Remove member from team. Are you sure?', method: :delete, class: "btn danger small", id: "remove_member_#{member.id}" %fieldset %legend @@ -84,7 +84,7 @@ %td.bgred = link_to 'Edit', edit_admin_team_project_path(@team, project), class: "btn small"   - = link_to 'Relegate', admin_team_project_path(@team, project), confirm: 'Remove project from team. Are you sure?', method: :delete, class: "btn danger small" + = link_to 'Relegate', admin_team_project_path(@team, project), confirm: 'Remove project from team. Are you sure?', method: :delete, class: "btn danger small", id: "relegate_project_#{project.id}" :javascript $(function(){ diff --git a/app/views/teams/projects/index.html.haml b/app/views/teams/projects/index.html.haml index b0a50e594cf..af6ffe5f3a4 100644 --- a/app/views/teams/projects/index.html.haml +++ b/app/views/teams/projects/index.html.haml @@ -13,7 +13,7 @@ %hr -%table +%table.projects-table %thead %tr %th Project name diff --git a/features/admin/teams.feature b/features/admin/teams.feature index 6ca7c4cbe02..b38a71e07b3 100644 --- a/features/admin/teams.feature +++ b/features/admin/teams.feature @@ -1,9 +1,6 @@ Feature: Admin Teams Background: Given I sign in as an admin - #And there are projects in system - #And system has users - #And I have own project And Create gitlab user "John" Scenario: Create a team diff --git a/features/steps/admin/admin_teams.rb b/features/steps/admin/admin_teams.rb index a1221cd1a8c..5c66b24bccf 100644 --- a/features/steps/admin/admin_teams.rb +++ b/features/steps/admin/admin_teams.rb @@ -83,8 +83,7 @@ class AdminTeams < Spinach::FeatureSteps end Then 'I should see empty projects table' do - projects_list = find("#projects_list") - projects_list.has_content?("Relegate").must_equal false + page.has_no_css?("#projects_list").must_equal true end When 'I select project "Shop" with max access "Reporter"' do @@ -177,11 +176,13 @@ class AdminTeams < Spinach::FeatureSteps end And 'I should see "Shop" in projects list' do - + project = Project.find_by_name("Shop") + find_in_list("#projects_list .project", project).must_equal true end When 'I click on remove "Jimm" user link' do - + user = User.find_by_name("Jimm") + click_link "remove_member_#{user.id}" end Then 'I should be redirected to "HardCoders" team admin page' do @@ -189,15 +190,18 @@ class AdminTeams < Spinach::FeatureSteps end And 'I should not to see "Jimm" user in members list' do - + user = User.find_by_name("Jimm") + find_in_list("#members_list .member", user).must_equal false end When 'I click on "Relegate" link on "Shop" project' do - + project = Project.find_by_name("Shop") + click_link "relegate_project_#{project.id}" end Then 'I should see projects liston team page without "Shop" project' do - + project = Project.find_by_name("Shop") + find_in_list("#projects_list .project", project).must_equal false end Then 'I should see "John" user with role "Reporter" in team table' do diff --git a/features/steps/userteams/userteams.rb b/features/steps/userteams/userteams.rb index 59ec3d2de6e..39a2588ec92 100644 --- a/features/steps/userteams/userteams.rb +++ b/features/steps/userteams/userteams.rb @@ -175,7 +175,12 @@ class Userteams < Spinach::FeatureSteps end And 'I select user "John" from list with role "Reporter"' do - pending 'step not implemented' + user = User.find_by_name("John") + within "#team_members" do + select user.name, :from => "user_ids" + select "Reporter", :from => "default_project_access" + end + click_button "Add" end Then 'I should see user "John" in team list' do @@ -185,7 +190,7 @@ class Userteams < Spinach::FeatureSteps end And 'I have my own project without teams' do - project = create :project, creator: current_user + @project = create :project, creator: current_user end And 'I visit my team page' do @@ -197,27 +202,26 @@ class Userteams < Spinach::FeatureSteps click_link "Projects" end + And 'I click link "Assign project to Team"' do + click_link "Assign project to Team" + end + Then 'I should see form with my own project in avaliable projects list' do - project = current_user.projects.first projects_select = find("#project_ids") - projects_select.should have_content(project.name) + projects_select.should have_content(@project.name) end When 'I submit form with selected project and max access' do - project = current_user.projects.first - within "#team_projects" do - select project.name, :from => "project_ids" + within "#assign_projects" do + select @project.name, :from => "project_ids" select "Reporter", :from => "greatest_project_access" end click_button "Add" end Then 'I should see my own project in team projects list' do - project = current_user.projects.first - projects = all("table .project") - projects.each do |project_row| - project_row.should have_content(project.name) - end + projects = find(".projects-table") + projects.should have_content(@project.name) end When 'I click link "New Team Member"' do @@ -227,7 +231,7 @@ class Userteams < Spinach::FeatureSteps protected def current_team - @user_team ||= Team.first + @user_team ||= UserTeam.first end def project diff --git a/features/support/env.rb b/features/support/env.rb index be10ad1b8b9..5651c4a09ba 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -21,7 +21,7 @@ Dir["#{Rails.root}/features/steps/shared/*.rb"].each {|file| require file} include GitoliteStub WebMock.allow_net_connect! - +Spinach.config.save_and_open_page_on_failure = true # # JS driver # diff --git a/features/teams/team.feature b/features/teams/team.feature index d914313efb6..b62d230fd56 100644 --- a/features/teams/team.feature +++ b/features/teams/team.feature @@ -70,6 +70,7 @@ Feature: UserTeams And I have my own project without teams And I visit my team page When I click on link "Projects" + And I click link "Assign project to Team" Then I should see form with my own project in avaliable projects list When I submit form with selected project and max access Then I should see my own project in team projects list diff --git a/spec/routing/admin_routing_spec.rb b/spec/routing/admin_routing_spec.rb index fb26bf98d0f..3e0e4bb3883 100644 --- a/spec/routing/admin_routing_spec.rb +++ b/spec/routing/admin_routing_spec.rb @@ -95,20 +95,20 @@ describe Admin::ProjectsController, "routing" do end end -# edit_admin_team_member GET /admin/team_members/:id/edit(.:format) admin/team_members#edit -# admin_team_member PUT /admin/team_members/:id(.:format) admin/team_members#update -# DELETE /admin/team_members/:id(.:format) admin/team_members#destroy -describe Admin::TeamMembersController, "routing" do +# edit_admin_project_member GET /admin/projects/:project_id/members/:id/edit(.:format) admin/projects/members#edit {:id=>/[^\/]+/, :project_id=>/[^\/]+/} +# admin_project_member PUT /admin/projects/:project_id/members/:id(.:format) admin/projects/members#update {:id=>/[^\/]+/, :project_id=>/[^\/]+/} +# DELETE /admin/projects/:project_id/members/:id(.:format) admin/projects/members#destroy {:id=>/[^\/]+/, :project_id=>/[^\/]+/} +describe Admin::Projects::MembersController, "routing" do it "to #edit" do - get("/admin/team_members/1/edit").should route_to('admin/team_members#edit', id: '1') + get("/admin/projects/test/members/1/edit").should route_to('admin/projects/members#edit', project_id: 'test', id: '1') end it "to #update" do - put("/admin/team_members/1").should route_to('admin/team_members#update', id: '1') + put("/admin/projects/test/members/1").should route_to('admin/projects/members#update', project_id: 'test', id: '1') end it "to #destroy" do - delete("/admin/team_members/1").should route_to('admin/team_members#destroy', id: '1') + delete("/admin/projects/test/members/1").should route_to('admin/projects/members#destroy', project_id: 'test', id: '1') end end From 9a604eb6798a2cc26df09ef9470273093acdb853 Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Thu, 24 Jan 2013 00:06:48 +0400 Subject: [PATCH 43/56] Remove pending steps (no functional - no tests) --- features/admin/teams.feature | 2 -- 1 file changed, 2 deletions(-) diff --git a/features/admin/teams.feature b/features/admin/teams.feature index b38a71e07b3..6a15fddcdcc 100644 --- a/features/admin/teams.feature +++ b/features/admin/teams.feature @@ -18,8 +18,6 @@ Feature: Admin Teams When I select user "John" from user list as "Developer" And submit form with new team member info Then I should see "John" in teams members list as "Developer" - When I visit "John" user admin page - Then I should see "HardCoders" team in teams table Scenario: Assign team to existing project When I visit admin teams page From b695db4af4c9fe0dc27f78e549a6a785bf936731 Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Thu, 24 Jan 2013 01:40:45 +0400 Subject: [PATCH 44/56] Remove save files with failed test %) --- features/support/env.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/features/support/env.rb b/features/support/env.rb index 5651c4a09ba..a08aa0de9f8 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -21,7 +21,6 @@ Dir["#{Rails.root}/features/steps/shared/*.rb"].each {|file| require file} include GitoliteStub WebMock.allow_net_connect! -Spinach.config.save_and_open_page_on_failure = true # # JS driver # From 2befa8fe30bd5f3512e67d671e25df6f128389f0 Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Thu, 24 Jan 2013 03:00:56 +0400 Subject: [PATCH 45/56] Switch user link to profile link --- app/views/teams/members/_show.html.haml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/teams/members/_show.html.haml b/app/views/teams/members/_show.html.haml index ec4728787cf..dbbb382d97f 100644 --- a/app/views/teams/members/_show.html.haml +++ b/app/views/teams/members/_show.html.haml @@ -3,9 +3,9 @@ %li{id: dom_id(member), class: "team_member_row user_#{user.id}"} .row .span5 - = link_to team_member_path(@team, user), title: user.name, class: "dark" do + = link_to user_path(user.username), title: user.name, class: "dark" do = image_tag gravatar_icon(user.email, 40), class: "avatar s32" - = link_to team_member_path(@team, user), title: user.name, class: "dark" do + = link_to user_path(user.username), title: user.name, class: "dark" do %strong= truncate(user.name, lenght: 40) %br %small.cgray= user.email From 1a917bc954f7e2b0c7233288c73476f572cad8d6 Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Thu, 24 Jan 2013 03:18:07 +0400 Subject: [PATCH 46/56] fix scope to empty relation --- app/models/user_team.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/user_team.rb b/app/models/user_team.rb index 0442123fc24..e3037bcd1aa 100644 --- a/app/models/user_team.rb +++ b/app/models/user_team.rb @@ -17,7 +17,7 @@ class UserTeam < ActiveRecord::Base scope :with_member, ->(user){ joins(:user_team_user_relationships).where(user_team_user_relationships: {user_id: user.id}) } scope :with_project, ->(project){ joins(:user_team_project_relationships).where(user_team_project_relationships: {project_id: project})} - scope :without_project, ->(project){ where("id NOT IN (:ids)", ids: with_project(project))} + scope :without_project, ->(project){ where("id NOT IN (:ids)", ids: (a = with_project(project); a.blank? ? 0 : a))} scope :created_by, ->(user){ where(owner_id: user) } class << self From 645f9604752ae258ab3f125c8fa98adf3b81c127 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 24 Jan 2013 10:16:03 +0200 Subject: [PATCH 47/56] Few UI improvements --- app/controllers/teams/application_controller.rb | 2 ++ app/views/dashboard/_teams.html.haml | 3 +-- app/views/layouts/_head_panel.html.haml | 2 +- app/views/layouts/group.html.haml | 2 +- app/views/layouts/user_team.html.haml | 2 +- app/views/teams/_projects.html.haml | 2 +- app/views/teams/index.html.haml | 8 ++++---- 7 files changed, 11 insertions(+), 10 deletions(-) diff --git a/app/controllers/teams/application_controller.rb b/app/controllers/teams/application_controller.rb index 2c1583d943e..fc23202610c 100644 --- a/app/controllers/teams/application_controller.rb +++ b/app/controllers/teams/application_controller.rb @@ -1,5 +1,7 @@ class Teams::ApplicationController < ApplicationController + layout 'user_team' + before_filter :authorize_manage_user_team! protected diff --git a/app/views/dashboard/_teams.html.haml b/app/views/dashboard/_teams.html.haml index 414bb12a945..4250faac685 100644 --- a/app/views/dashboard/_teams.html.haml +++ b/app/views/dashboard/_teams.html.haml @@ -20,7 +20,6 @@ → %span.last_activity %strong Projects: - %span= team.projects.count - %span.last_activity + %span= "#{team.projects.count}, " %strong Members: %span= team.members.count diff --git a/app/views/layouts/_head_panel.html.haml b/app/views/layouts/_head_panel.html.haml index 945500d4b6c..de4117ae296 100644 --- a/app/views/layouts/_head_panel.html.haml +++ b/app/views/layouts/_head_panel.html.haml @@ -10,7 +10,7 @@ %ul.nav %li = link_to teams_path, title: "Teams of users", class: 'has_bottom_tooltip', 'data-original-title' => 'Teams list' do - %i.icon-globe + %i.icon-group - if current_user.is_admin? %li = link_to admin_root_path, title: "Admin area", class: 'has_bottom_tooltip', 'data-original-title' => 'Admin area' do diff --git a/app/views/layouts/group.html.haml b/app/views/layouts/group.html.haml index f47e8b3e9ff..46bc9ef1457 100644 --- a/app/views/layouts/group.html.haml +++ b/app/views/layouts/group.html.haml @@ -3,7 +3,7 @@ = render "layouts/head", title: "#{@group.name}" %body{class: "#{app_theme} application"} = render "layouts/flash" - = render "layouts/head_panel", title: "#{@group.name}" + = render "layouts/head_panel", title: "group: #{@group.name}" .container %ul.main_menu = nav_link(path: 'groups#show', html_options: {class: 'home'}) do diff --git a/app/views/layouts/user_team.html.haml b/app/views/layouts/user_team.html.haml index aa613d71f90..769fc3b78c3 100644 --- a/app/views/layouts/user_team.html.haml +++ b/app/views/layouts/user_team.html.haml @@ -3,7 +3,7 @@ = render "layouts/head", title: "#{@team.name}" %body{class: "#{app_theme} application"} = render "layouts/flash" - = render "layouts/head_panel", title: "#{@team.name}" + = render "layouts/head_panel", title: "team: #{@team.name}" .container %ul.main_menu = nav_link(path: 'teams#show', html_options: {class: 'home'}) do diff --git a/app/views/teams/_projects.html.haml b/app/views/teams/_projects.html.haml index 040d1ae94aa..95202bc6ee5 100644 --- a/app/views/teams/_projects.html.haml +++ b/app/views/teams/_projects.html.haml @@ -10,7 +10,7 @@ New Project %ul.well-list - if projects.blank? - %p.nothing_here_message This groups has no projects yet + %p.nothing_here_message This team has no projects yet - projects.each do |project| %li = link_to project_path(project), class: dom_class(project) do diff --git a/app/views/teams/index.html.haml b/app/views/teams/index.html.haml index 8f8874328fc..6610cdbd76e 100644 --- a/app/views/teams/index.html.haml +++ b/app/views/teams/index.html.haml @@ -20,7 +20,7 @@ %th Projects %th Members %th Owner - %th + %th.cred Danger Zone! - @teams.each do |team| %tr @@ -30,9 +30,9 @@ %td= link_to team.projects.count, team_projects_path(team) %td= link_to team.members.count, team_members_path(team) %td= link_to team.owner.name, team_member_path(team, team.owner) - %td + %td.bgred - if current_user.can?(:manage_user_team, team) + = link_to "Edit", edit_team_path(team), class: "btn small" - if current_user.can?(:admin_user_team, team) - = link_to "Destroy", team_path(team), method: :delete, confirm: "You are shure?", class: "danger btn small right" + = link_to "Destroy", team_path(team), method: :delete, confirm: "You are shure?", class: "danger btn small"   - = link_to "Edit", edit_team_path(team), class: "btn small right" From ca105d0462090b1650019890feeeef3fdd356209 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 24 Jan 2013 10:39:16 +0200 Subject: [PATCH 48/56] Show only teams we have access to --- app/controllers/teams_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/teams_controller.rb b/app/controllers/teams_controller.rb index ea060b3a44d..7de094214d4 100644 --- a/app/controllers/teams_controller.rb +++ b/app/controllers/teams_controller.rb @@ -10,7 +10,7 @@ class TeamsController < ApplicationController layout 'user_team', only: [:show, :edit, :update, :destroy, :issues, :merge_requests, :search] def index - @teams = UserTeam.order('name ASC') + @teams = current_user.user_teams.order('name ASC') end def show From ca752e64fbf1cd03ff3eff1ada80a1cfbcd9b2b4 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 24 Jan 2013 11:19:09 +0200 Subject: [PATCH 49/56] Fix mispelling and ambiguous id in UserTeam.without_project --- app/controllers/projects/teams_controller.rb | 2 +- app/models/user_team.rb | 2 +- app/views/dashboard/_teams.html.haml | 6 +----- app/views/layouts/_head_panel.html.haml | 3 --- .../teams/{avaliable.html.haml => available.html.haml} | 0 app/views/team_members/index.html.haml | 2 +- app/views/teams/new.html.haml | 2 +- config/routes.rb | 2 +- 8 files changed, 6 insertions(+), 13 deletions(-) rename app/views/projects/teams/{avaliable.html.haml => available.html.haml} (100%) diff --git a/app/controllers/projects/teams_controller.rb b/app/controllers/projects/teams_controller.rb index c04835ed153..3ca724aaf4d 100644 --- a/app/controllers/projects/teams_controller.rb +++ b/app/controllers/projects/teams_controller.rb @@ -1,6 +1,6 @@ class Projects::TeamsController < Projects::ApplicationController - def avaliable + def available @teams = current_user.is_admin? ? UserTeam.scoped : current_user.user_teams @teams = @teams.without_project(project) unless @teams.any? diff --git a/app/models/user_team.rb b/app/models/user_team.rb index e3037bcd1aa..b28a6a041ac 100644 --- a/app/models/user_team.rb +++ b/app/models/user_team.rb @@ -17,7 +17,7 @@ class UserTeam < ActiveRecord::Base scope :with_member, ->(user){ joins(:user_team_user_relationships).where(user_team_user_relationships: {user_id: user.id}) } scope :with_project, ->(project){ joins(:user_team_project_relationships).where(user_team_project_relationships: {project_id: project})} - scope :without_project, ->(project){ where("id NOT IN (:ids)", ids: (a = with_project(project); a.blank? ? 0 : a))} + scope :without_project, ->(project){ where("user_teams.id NOT IN (:ids)", ids: (a = with_project(project); a.blank? ? 0 : a))} scope :created_by, ->(user){ where(owner_id: user) } class << self diff --git a/app/views/dashboard/_teams.html.haml b/app/views/dashboard/_teams.html.haml index 4250faac685..b047acf8d4a 100644 --- a/app/views/dashboard/_teams.html.haml +++ b/app/views/dashboard/_teams.html.haml @@ -1,16 +1,12 @@ .teams_box %h5.title - My Teams + Teams %small (#{@teams.count}) %span.right = link_to new_team_path, class: "btn very_small info" do %i.icon-plus New Team - %span.right - = link_to teams_path, class: "btn very_small info" do - %i.icon-user - All Teams %ul.well-list - @teams.each do |team| %li diff --git a/app/views/layouts/_head_panel.html.haml b/app/views/layouts/_head_panel.html.haml index de4117ae296..8f4f3d7815f 100644 --- a/app/views/layouts/_head_panel.html.haml +++ b/app/views/layouts/_head_panel.html.haml @@ -8,9 +8,6 @@ %span.separator %h1.project_name= title %ul.nav - %li - = link_to teams_path, title: "Teams of users", class: 'has_bottom_tooltip', 'data-original-title' => 'Teams list' do - %i.icon-group - if current_user.is_admin? %li = link_to admin_root_path, title: "Admin area", class: 'has_bottom_tooltip', 'data-original-title' => 'Admin area' do diff --git a/app/views/projects/teams/avaliable.html.haml b/app/views/projects/teams/available.html.haml similarity index 100% rename from app/views/projects/teams/avaliable.html.haml rename to app/views/projects/teams/available.html.haml diff --git a/app/views/team_members/index.html.haml b/app/views/team_members/index.html.haml index f694ccbca93..6425302b83b 100644 --- a/app/views/team_members/index.html.haml +++ b/app/views/team_members/index.html.haml @@ -10,7 +10,7 @@ %span.right = link_to import_project_team_members_path(@project), class: "btn small grouped", title: "Import team from another project" do Import team from another project - = link_to avaliable_project_teams_path(@project), class: "btn small grouped", title: "Assign project to team of users" do + = link_to available_project_teams_path(@project), class: "btn small grouped", title: "Assign project to team of users" do Assign project to Team of users = link_to new_project_team_member_path(@project), class: "btn success small grouped", title: "New Team Member" do New Team Member diff --git a/app/views/teams/new.html.haml b/app/views/teams/new.html.haml index a068c51e6ab..12695f2b5ae 100644 --- a/app/views/teams/new.html.haml +++ b/app/views/teams/new.html.haml @@ -8,7 +8,7 @@ = f.label :name do Team name is .input - = f.text_field :name, placeholder: "Ex. OpenSource", class: "xxlarge left" + = f.text_field :name, placeholder: "Ex. Ruby Developers", class: "xxlarge left"   = f.submit 'Create team', class: "btn primary" %hr diff --git a/config/routes.rb b/config/routes.rb index 387f94ba025..ba350a70bfa 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -272,7 +272,7 @@ Gitlab::Application.routes.draw do scope module: :projects do resources :teams, only: [] do collection do - get :avaliable + get :available post :assign end member do From b5dd9e6775e2da52a9efb07bbeedd7cd56230c1d Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 24 Jan 2013 11:43:09 +0200 Subject: [PATCH 50/56] Make a team and group boxes smaller on dashboard --- app/models/user_team_user_relationship.rb | 4 ++++ app/views/dashboard/_groups.html.haml | 10 ++++------ app/views/dashboard/_teams.html.haml | 15 +++++++-------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/app/models/user_team_user_relationship.rb b/app/models/user_team_user_relationship.rb index 00d12ebf607..63bdc49e5b6 100644 --- a/app/models/user_team_user_relationship.rb +++ b/app/models/user_team_user_relationship.rb @@ -12,4 +12,8 @@ class UserTeamUserRelationship < ActiveRecord::Base def user_name user.name end + + def access_human + UsersProject.access_roles.invert[permission] + end end diff --git a/app/views/dashboard/_groups.html.haml b/app/views/dashboard/_groups.html.haml index dc50bffda80..f9774669d9a 100644 --- a/app/views/dashboard/_groups.html.haml +++ b/app/views/dashboard/_groups.html.haml @@ -1,4 +1,4 @@ -.groups_box +.ui-box %h5.title Groups %small @@ -13,8 +13,6 @@ %li = link_to group_path(id: group.path), class: dom_class(group) do %strong.well-title= truncate(group.name, length: 35) - %span.arrow - → - %span.last_activity - %strong Projects: - %span= current_user.authorized_projects.where(namespace_id: group.id).count + %span.right.light + - if group.owner == current_user + %i.icon-wrench diff --git a/app/views/dashboard/_teams.html.haml b/app/views/dashboard/_teams.html.haml index b047acf8d4a..7912175b760 100644 --- a/app/views/dashboard/_teams.html.haml +++ b/app/views/dashboard/_teams.html.haml @@ -1,4 +1,4 @@ -.teams_box +.ui-box %h5.title Teams %small @@ -12,10 +12,9 @@ %li = link_to team_path(id: team.path), class: dom_class(team) do %strong.well-title= truncate(team.name, length: 35) - %span.arrow - → - %span.last_activity - %strong Projects: - %span= "#{team.projects.count}, " - %strong Members: - %span= team.members.count + %span.right.light + - if team.owner == current_user + %i.icon-wrench + - tm = current_user.user_team_user_relationships.find_by_user_team_id(team.id) + - if tm + = tm.access_human From 11b7b93cf7a0329ce9c012ef866c975acc42d9b4 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 24 Jan 2013 13:39:00 +0200 Subject: [PATCH 51/56] move team navs to upper nav --- app/views/layouts/user_team.html.haml | 18 ++++++++++++++++++ app/views/teams/_team_head.html.haml | 19 ------------------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/app/views/layouts/user_team.html.haml b/app/views/layouts/user_team.html.haml index 769fc3b78c3..12fce837238 100644 --- a/app/views/layouts/user_team.html.haml +++ b/app/views/layouts/user_team.html.haml @@ -8,15 +8,33 @@ %ul.main_menu = nav_link(path: 'teams#show', html_options: {class: 'home'}) do = link_to "Home", team_path(@team), title: "Home" + = nav_link(path: 'teams#issues') do = link_to issues_team_path(@team) do Issues %span.count= Issue.opened.of_user_team(@team).count + = nav_link(path: 'teams#merge_requests') do = link_to merge_requests_team_path(@team) do Merge Requests %span.count= MergeRequest.opened.of_user_team(@team).count + = nav_link(path: 'teams#search') do = link_to "Search", search_team_path(@team) + = nav_link(controller: [:members]) do + = link_to team_members_path(@team), class: "team-tab tab" do + Members + + - if can? current_user, :admin_user_team, @team + = nav_link(controller: [:projects]) do + = link_to team_projects_path(@team), class: "team-tab tab" do + %i.icon-briefcase + Projects + + = nav_link(path: 'teams#edit') do + = link_to edit_team_path(@team), class: "stat-tab tab " do + %i.icon-edit + Edit Team + .content= yield diff --git a/app/views/teams/_team_head.html.haml b/app/views/teams/_team_head.html.haml index cb5c9567ba6..e69de29bb2d 100644 --- a/app/views/teams/_team_head.html.haml +++ b/app/views/teams/_team_head.html.haml @@ -1,19 +0,0 @@ -%ul.nav.nav-tabs - = nav_link(path: 'teams#show') do - = link_to team_path(@team), class: "activities-tab tab" do - %i.icon-home - Show - = nav_link(controller: [:members]) do - = link_to team_members_path(@team), class: "team-tab tab" do - %i.icon-user - Members - = nav_link(controller: [:projects]) do - = link_to team_projects_path(@team), class: "team-tab tab" do - %i.icon-briefcase - Projects - - - if can? current_user, :admin_user_team, @team - = nav_link(path: 'teams#edit', html_options: {class: 'right'}) do - = link_to edit_team_path(@team), class: "stat-tab tab " do - %i.icon-edit - Edit Team From b4967b3703e1d520dd520f4bb7196ba3ecc302e9 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 24 Jan 2013 14:10:17 +0200 Subject: [PATCH 52/56] Dont allow to select a project you have no right to assign --- app/controllers/teams/projects_controller.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/controllers/teams/projects_controller.rb b/app/controllers/teams/projects_controller.rb index 21ddba865f3..9e9cd9f5f57 100644 --- a/app/controllers/teams/projects_controller.rb +++ b/app/controllers/teams/projects_controller.rb @@ -9,9 +9,8 @@ class Teams::ProjectsController < Teams::ApplicationController def new user_team - @avaliable_projects = Project.scoped + @avaliable_projects = current_user.owned_projects.scoped @avaliable_projects = @avaliable_projects.without_team(user_team) if user_team.projects.any? - #@projects.reject!(&:empty_repo?) redirect_to team_projects_path(user_team), notice: "No avalible projects." unless @avaliable_projects.any? end From 7403afea9748316b78242ecb250f619fe1a15b36 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 24 Jan 2013 14:15:14 +0200 Subject: [PATCH 53/56] Reject non-owned projects to assign to teams --- app/controllers/teams/projects_controller.rb | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/app/controllers/teams/projects_controller.rb b/app/controllers/teams/projects_controller.rb index 9e9cd9f5f57..f5729351508 100644 --- a/app/controllers/teams/projects_controller.rb +++ b/app/controllers/teams/projects_controller.rb @@ -16,13 +16,19 @@ class Teams::ProjectsController < Teams::ApplicationController end def create - unless params[:project_ids].blank? - project_ids = params[:project_ids] - access = params[:greatest_project_access] - user_team.assign_to_projects(project_ids, access) - end + redirect_to :back if params[:project_ids].blank? - redirect_to team_projects_path(user_team), notice: 'Team of users was successfully assgned to projects.' + project_ids = params[:project_ids] + access = params[:greatest_project_access] + + # Reject non-allowed projects + allowed_project_ids = current_user.owned_projects.map(&:id) + project_ids.select! { |id| allowed_project_ids.include?(id) } + + # Assign projects to team + user_team.assign_to_projects(project_ids, access) + + redirect_to team_projects_path(user_team), notice: 'Team of users was successfully assigned to projects.' end def edit From 6d713e84e185f60b00c38e792d11df27ed110605 Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Thu, 24 Jan 2013 22:18:43 +0400 Subject: [PATCH 54/56] remove unused code --- app/controllers/admin/teams_controller.rb | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/app/controllers/admin/teams_controller.rb b/app/controllers/admin/teams_controller.rb index 7371f4a446c..335add0f57d 100644 --- a/app/controllers/admin/teams_controller.rb +++ b/app/controllers/admin/teams_controller.rb @@ -6,13 +6,7 @@ class Admin::TeamsController < Admin::ApplicationController end def show - @projects = Project.scoped - @projects = @projects.without_team(user_team) if user_team.projects.any? - #@projects.reject!(&:empty_repo?) - - @users = User.active - @users = @users.not_in_team(user_team) if user_team.members.any? - @users = UserDecorator.decorate @users + user_team end def new From e52fec9cd9812e6fd8a7700c2188dbbf6e022c81 Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Thu, 24 Jan 2013 22:19:18 +0400 Subject: [PATCH 55/56] Update check If user can assign project to team --- app/controllers/teams/projects_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/teams/projects_controller.rb b/app/controllers/teams/projects_controller.rb index f5729351508..27dc934452f 100644 --- a/app/controllers/teams/projects_controller.rb +++ b/app/controllers/teams/projects_controller.rb @@ -4,7 +4,7 @@ class Teams::ProjectsController < Teams::ApplicationController def index @projects = user_team.projects - @avaliable_projects = current_user.admin? ? Project.without_team(user_team) : (Project.personal(current_user) + current_user.projects).uniq + @avaliable_projects = current_user.admin? ? Project.without_team(user_team) : current_user.owned_projects.without_team(user_team) end def new From d839f6c52571e3b873a05779b1131f7b00670b31 Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Thu, 24 Jan 2013 22:31:28 +0400 Subject: [PATCH 56/56] Remove simple code duplication in members controllers --- app/controllers/admin/teams/members_controller.rb | 3 +-- app/controllers/teams/members_controller.rb | 3 +-- app/models/user.rb | 1 + 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/app/controllers/admin/teams/members_controller.rb b/app/controllers/admin/teams/members_controller.rb index 7fd777dc72f..139b82ab66c 100644 --- a/app/controllers/admin/teams/members_controller.rb +++ b/app/controllers/admin/teams/members_controller.rb @@ -1,7 +1,6 @@ class Admin::Teams::MembersController < Admin::Teams::ApplicationController def new - @users = User.active - @users = @users.not_in_team(user_team) if user_team.members.any? + @users = User.potential_team_members(user_team) @users = UserDecorator.decorate @users end diff --git a/app/controllers/teams/members_controller.rb b/app/controllers/teams/members_controller.rb index 56e952a3d40..c41d5d7abe6 100644 --- a/app/controllers/teams/members_controller.rb +++ b/app/controllers/teams/members_controller.rb @@ -7,8 +7,7 @@ class Teams::MembersController < Teams::ApplicationController end def new - @users = User.active - @users = @users.not_in_team(user_team) if user_team.members.any? + @users = User.potential_team_members(user_team) @users = UserDecorator.decorate @users end diff --git a/app/models/user.rb b/app/models/user.rb index 16e07e9ce3f..b61d2cb0d83 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -91,6 +91,7 @@ class User < ActiveRecord::Base scope :alphabetically, order('name ASC') scope :in_team, ->(team){ where(id: team.member_ids) } scope :not_in_team, ->(team){ where('users.id NOT IN (:ids)', ids: team.member_ids) } + scope :potential_team_members, ->(team) { team.members.any? ? active : active.not_in_team(team) } # # Class methods