Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/admin/groups_controller.rb66
-rw-r--r--app/models/group.rb6
-rw-r--r--app/models/project.rb5
-rw-r--r--app/views/admin/groups/_form.html.haml19
-rw-r--r--app/views/admin/groups/index.html.haml24
-rw-r--r--app/views/admin/groups/new.html.haml3
-rw-r--r--app/views/admin/groups/show.html.haml48
-rw-r--r--config/routes.rb5
8 files changed, 175 insertions, 1 deletions
diff --git a/app/controllers/admin/groups_controller.rb b/app/controllers/admin/groups_controller.rb
new file mode 100644
index 00000000000..612abf8c50a
--- /dev/null
+++ b/app/controllers/admin/groups_controller.rb
@@ -0,0 +1,66 @@
+class Admin::GroupsController < AdminController
+ before_filter :group, only: [:edit, :show, :update, :destroy, :project_update]
+
+ def index
+ @groups = Group.scoped
+ @groups = @groups.search(params[:name]) if params[:name].present?
+ @groups = @groups.page(params[:page]).per(20)
+ end
+
+ def show
+ @projects = Project.scoped
+ @projects = @projects.not_in_group(@group) if @group.projects.present?
+ @projects = @projects.all
+ end
+
+ def new
+ @group = Group.new
+ end
+
+ def edit
+ end
+
+ def create
+ @group = Group.new(params[:group])
+ @group.owner = current_user
+
+ if @group.save
+ redirect_to [:admin, @group], notice: 'Group was successfully created.'
+ else
+ render action: "new"
+ end
+ end
+
+ def update
+ owner_id = params[:group].delete(:owner_id)
+
+ if owner_id
+ @group.owner = User.find(owner_id)
+ end
+
+ if @group.update_attributes(params[:group])
+ redirect_to [:admin, @group], notice: 'Group was successfully updated.'
+ else
+ render action: "edit"
+ end
+ end
+
+ def project_update
+ project_ids = params[:project_ids]
+ Project.where(id: project_ids).update_all(group_id: @group.id)
+
+ redirect_to :back, notice: 'Group was successfully updated.'
+ end
+
+ def destroy
+ @group.destroy
+
+ redirect_to groups_url, notice: 'Group was successfully deleted.'
+ end
+
+ private
+
+ def group
+ @group = Group.find_by_code(params[:id])
+ end
+end
diff --git a/app/models/group.rb b/app/models/group.rb
index f18b7d57650..4328306602c 100644
--- a/app/models/group.rb
+++ b/app/models/group.rb
@@ -19,4 +19,10 @@ class Group < ActiveRecord::Base
validates :name, presence: true, uniqueness: true
validates :code, presence: true, uniqueness: true
validates :owner_id, presence: true
+
+ delegate :name, to: :owner, allow_nil: true, prefix: true
+
+ def to_param
+ code
+ end
end
diff --git a/app/models/project.rb b/app/models/project.rb
index 9d2b99e599b..f525f292222 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -26,9 +26,12 @@ class Project < ActiveRecord::Base
has_many :wikis, dependent: :destroy
has_many :protected_branches, dependent: :destroy
+ delegate :name, to: :owner, allow_nil: true, prefix: true
+
# Scopes
scope :public_only, where(private_flag: false)
- scope :without_user, lambda { |user| where("id not in (:ids)", ids: user.projects.map(&:id) ) }
+ scope :without_user, ->(user) { where("id not in (:ids)", ids: user.projects.map(&:id) ) }
+ scope :not_in_group, ->(group) { where("id not in (:ids)", ids: group.project_ids ) }
def self.active
joins(:issues, :notes, :merge_requests).order("issues.created_at, notes.created_at, merge_requests.created_at DESC")
diff --git a/app/views/admin/groups/_form.html.haml b/app/views/admin/groups/_form.html.haml
new file mode 100644
index 00000000000..a1ba940672d
--- /dev/null
+++ b/app/views/admin/groups/_form.html.haml
@@ -0,0 +1,19 @@
+= form_for [:admin, @group] do |f|
+ - if @group.errors.any?
+ .alert-message.block-message.error
+ %span= @group.errors.full_messages.first
+ .clearfix.group_name_holder
+ = f.label :name do
+ Group name is
+ .input
+ = f.text_field :name, placeholder: "Example Group", class: "xxlarge"
+ .clearfix
+ = f.label :code do
+ URL
+ .input
+ .input-prepend
+ %span.add-on= web_app_url
+ = f.text_field :code, placeholder: "example"
+
+ .form-actions
+ = f.submit 'Create group', class: "btn primary"
diff --git a/app/views/admin/groups/index.html.haml b/app/views/admin/groups/index.html.haml
new file mode 100644
index 00000000000..b90efc83562
--- /dev/null
+++ b/app/views/admin/groups/index.html.haml
@@ -0,0 +1,24 @@
+%h3.page_title
+ Groups
+ = link_to 'New Group', new_admin_group_path, class: "btn small right"
+%br
+= form_tag admin_groups_path, method: :get, class: 'form-inline' do
+ = text_field_tag :name, params[:name], class: "xlarge"
+ = submit_tag "Search", class: "btn submit primary"
+
+%table
+ %thead
+ %th Name
+ %th Path
+ %th Projects
+ %th Edit
+ %th.cred Danger Zone!
+
+ - @groups.each do |group|
+ %tr
+ %td= link_to group.name, [:admin, group]
+ %td= group.path
+ %td= group.projects.count
+ %td= link_to 'Edit', edit_admin_group_path(group), id: "edit_#{dom_id(group)}", class: "btn small"
+ %td.bgred= link_to 'Destroy', [:admin, group], confirm: "REMOVE #{group.name}? Are you sure?", method: :delete, class: "btn small danger"
+= paginate @groups, theme: "admin"
diff --git a/app/views/admin/groups/new.html.haml b/app/views/admin/groups/new.html.haml
new file mode 100644
index 00000000000..d6b6ea1535e
--- /dev/null
+++ b/app/views/admin/groups/new.html.haml
@@ -0,0 +1,3 @@
+%h3.page_title New Group
+%br
+= render 'form'
diff --git a/app/views/admin/groups/show.html.haml b/app/views/admin/groups/show.html.haml
new file mode 100644
index 00000000000..5d348eecd6d
--- /dev/null
+++ b/app/views/admin/groups/show.html.haml
@@ -0,0 +1,48 @@
+%h3.page_title
+ Group: #{@group.name}
+ = link_to edit_admin_group_path(@group), class: "btn right" do
+ %i.icon-edit
+ Edit
+
+%br
+%table.zebra-striped
+ %thead
+ %tr
+ %th Group
+ %th
+ %tr
+ %td
+ %b
+ Name:
+ %td
+ = @group.name
+ %tr
+ %td
+ %b
+ Code:
+ %td
+ = @group.code
+ %tr
+ %td
+ %b
+ Owner:
+ %td
+ = @group.owner_name
+.ui-box
+ %h5
+ Projects
+ %small
+ (#{@group.projects.count})
+ %ul.unstyled
+ - @group.projects.each do |project|
+ %li.wll
+ %strong
+ = link_to project.name, [:admin, project]
+
+%br
+%h3 Add new project
+%br
+= form_tag project_update_admin_group_path(@group), class: "bulk_import", method: :put do
+ = select_tag :project_ids, options_from_collection_for_select(@projects , :id, :name), multiple: true, data: {placeholder: 'Select projects'}, class: 'chosen span5'
+ .form-actions
+ = submit_tag 'Add', class: "btn primary"
diff --git a/config/routes.rb b/config/routes.rb
index 21521a979e5..2b92337994a 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -43,6 +43,11 @@ Gitlab::Application.routes.draw do
put :unblock
end
end
+ resources :groups, constraints: { id: /[^\/]+/ } do
+ member do
+ put :project_update
+ end
+ end
resources :projects, constraints: { id: /[^\/]+/ } do
member do
get :team