Skip to content
Snippets Groups Projects
Commit 18bd1c9d authored by Andrey Kumanyaev's avatar Andrey Kumanyaev Committed by Dmitriy Zaporozhets
Browse files

update all teams code. refactoring and some corrections

parent 7658f8c1
No related branches found
No related tags found
2 merge requests!2940Expanding repos and hooks paths in settings,!2746New feature: Teams
Showing
with 178 additions and 206 deletions
Loading
Loading
@@ -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
 
Loading
Loading
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
 
Loading
Loading
@@ -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
Loading
Loading
@@ -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
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
 
Loading
Loading
@@ -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
Loading
Loading
@@ -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
Loading
Loading
@@ -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
Loading
Loading
@@ -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
Loading
Loading
@@ -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
Loading
Loading
Loading
Loading
@@ -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
Loading
Loading
@@ -135,4 +143,5 @@ class ApplicationController < ActionController::Base
def dev_tools
Rack::MiniProfiler.authorize_request
end
end
Loading
Loading
@@ -4,6 +4,7 @@ class TeamMembersController < ProjectResourceController
before_filter :authorize_admin_project!, except: [:index, :show]
 
def index
@teams = UserTeam.scoped
end
 
def show
Loading
Loading
Loading
Loading
@@ -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
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])
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
 
@project.team << [users, params[:default_project_access]]
redirect_to team_path(user_team), notice: 'Members was successfully added into Team of users.'
end
 
if params[:redirect_to]
redirect_to params[:redirect_to]
else
redirect_to project_team_index_path(@project)
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
Loading
Loading
@@ -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
Loading
Loading
@@ -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
Loading
Loading
@@ -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
Loading
Loading
@@ -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
class TeamsController < ApplicationController
respond_to :html
layout 'user_team', only: [:show, :edit, :update, :destroy, :issues, :merge_requests, :search]
# Authorize
before_filter :authorize_manage_user_team!
before_filter :authorize_admin_user_team!
 
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]
# 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]
 
# Authorize
before_filter :authorize_manage_user_team!, only: [:edit, :update]
before_filter :authorize_admin_user_team!, only: [:destroy]
layout 'user_team', only: [:show, :edit, :update, :destroy, :issues, :merge_requests, :search]
 
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
Loading
Loading
@@ -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)
end
def authorize_manage_user_team!
unless user_team.present? or can?(current_user, :manage_user_team, user_team)
return render_404
end
def user_team
@team ||= UserTeam.find_by_path(params[:id])
end
 
def authorize_admin_user_team!
unless user_team.owner == current_user || current_user.admin?
return render_404
end
end
end
Loading
Loading
@@ -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"
Loading
Loading
@@ -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
Loading
Loading
@@ -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"
&nbsp;
= 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"
&nbsp;
= 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"
&nbsp;
= 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"
&nbsp;
= 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(){
Loading
Loading
Loading
Loading
@@ -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
Loading
Loading
@@ -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)
Loading
Loading
@@ -20,4 +20,7 @@
&rarr;
%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
Loading
Loading
@@ -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
Loading
Loading
!!! 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
%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
= 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
Loading
Loading
@@ -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"
Loading
Loading
@@ -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
Loading
Loading
@@ -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"
&nbsp;
= link_to "Edit", edit_team_path(team), class: "btn small right"
%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"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment