Admin teams section added

This commit is contained in:
Andrey Kumanyaev 2013-01-19 21:11:11 +04:00 committed by Dmitriy Zaporozhets
parent 8a86fe7bb0
commit 82499a4cbf
10 changed files with 603 additions and 0 deletions

View file

@ -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

View file

@ -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"

View file

@ -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"

View file

@ -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"
&nbsp;
= 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

View file

@ -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
&nbsp;
= 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();
})
})

View file

@ -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