2012-10-02 13:42:15 -04:00
|
|
|
class GroupsController < ApplicationController
|
|
|
|
respond_to :html
|
2013-06-21 16:47:42 -04:00
|
|
|
before_filter :group, except: [:new, :create]
|
2012-10-02 13:42:15 -04:00
|
|
|
|
2012-11-29 10:17:01 -05:00
|
|
|
# Authorize
|
2013-01-24 10:47:09 -05:00
|
|
|
before_filter :authorize_read_group!, except: [:new, :create]
|
2013-02-01 12:04:11 -05:00
|
|
|
before_filter :authorize_admin_group!, only: [:edit, :update, :destroy]
|
2013-01-25 04:30:49 -05:00
|
|
|
before_filter :authorize_create_group!, only: [:new, :create]
|
2013-01-24 10:47:09 -05:00
|
|
|
|
|
|
|
# Load group projects
|
|
|
|
before_filter :projects, except: [:new, :create]
|
|
|
|
|
2013-06-08 09:26:57 -04:00
|
|
|
layout :determine_layout
|
|
|
|
|
2013-06-07 10:41:01 -04:00
|
|
|
before_filter :set_title, only: [:new, :create]
|
|
|
|
|
2013-01-24 10:47:09 -05:00
|
|
|
def new
|
|
|
|
@group = Group.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@group = Group.new(params[:group])
|
|
|
|
@group.path = @group.name.dup.parameterize if @group.name
|
|
|
|
@group.owner = current_user
|
|
|
|
|
|
|
|
if @group.save
|
|
|
|
redirect_to @group, notice: 'Group was successfully created.'
|
|
|
|
else
|
|
|
|
render action: "new"
|
|
|
|
end
|
|
|
|
end
|
2012-11-29 10:17:01 -05:00
|
|
|
|
2012-10-02 13:42:15 -04:00
|
|
|
def show
|
2012-10-09 15:09:46 -04:00
|
|
|
@events = Event.in_projects(project_ids).limit(20).offset(params[:offset] || 0)
|
2012-10-02 13:42:15 -04:00
|
|
|
@last_push = current_user.recent_push
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.js
|
|
|
|
format.atom { render layout: false }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Get authored or assigned open merge requests
|
|
|
|
def merge_requests
|
2013-01-07 13:48:57 -05:00
|
|
|
@merge_requests = current_user.cared_merge_requests.of_group(@group)
|
|
|
|
@merge_requests = FilterContext.new(@merge_requests, params).execute
|
|
|
|
@merge_requests = @merge_requests.recent.page(params[:page]).per(20)
|
2012-10-02 13:42:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
# Get only assigned issues
|
|
|
|
def issues
|
2013-01-07 13:48:57 -05:00
|
|
|
@issues = current_user.assigned_issues.of_group(@group)
|
|
|
|
@issues = FilterContext.new(@issues, params).execute
|
|
|
|
@issues = @issues.recent.page(params[:page]).per(20)
|
2012-10-02 13:42:15 -04:00
|
|
|
@issues = @issues.includes(:author, :project)
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.atom { render layout: false }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-07-12 12:01:39 -04:00
|
|
|
def members
|
2012-11-29 12:14:05 -05:00
|
|
|
@project = group.projects.find(params[:project_id]) if params[:project_id]
|
2013-06-17 14:00:59 -04:00
|
|
|
@members = group.users_groups.order('group_access DESC')
|
2013-06-17 09:51:43 -04:00
|
|
|
@users_group = UsersGroup.new
|
2012-12-25 17:52:49 -05:00
|
|
|
end
|
|
|
|
|
2013-02-01 12:04:11 -05:00
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
group_params = params[:group].dup
|
2013-06-18 09:56:31 -04:00
|
|
|
owner_id = group_params.delete(:owner_id)
|
2013-02-01 12:04:11 -05:00
|
|
|
|
|
|
|
if owner_id
|
|
|
|
@group.owner = User.find(owner_id)
|
2013-03-14 05:31:33 -04:00
|
|
|
@group.save
|
2013-02-01 12:04:11 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
if @group.update_attributes(group_params)
|
|
|
|
redirect_to @group, notice: 'Group was successfully updated.'
|
|
|
|
else
|
|
|
|
render action: "edit"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@group.truncate_teams
|
|
|
|
@group.destroy
|
|
|
|
|
|
|
|
redirect_to root_path, notice: 'Group was removed.'
|
|
|
|
end
|
|
|
|
|
2012-10-02 13:42:15 -04:00
|
|
|
protected
|
|
|
|
|
|
|
|
def group
|
2012-11-23 14:31:09 -05:00
|
|
|
@group ||= Group.find_by_path(params[:id])
|
2012-10-02 13:42:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def projects
|
2013-01-02 12:00:00 -05:00
|
|
|
@projects ||= current_user.authorized_projects.where(namespace_id: group.id).sorted_by_activity
|
2012-10-02 13:42:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def project_ids
|
|
|
|
projects.map(&:id)
|
|
|
|
end
|
2012-11-29 10:17:01 -05:00
|
|
|
|
|
|
|
# Dont allow unauthorized access to group
|
|
|
|
def authorize_read_group!
|
|
|
|
unless projects.present? or can?(current_user, :manage_group, @group)
|
|
|
|
return render_404
|
|
|
|
end
|
|
|
|
end
|
2013-01-25 04:30:49 -05:00
|
|
|
|
|
|
|
def authorize_create_group!
|
2013-02-01 12:04:11 -05:00
|
|
|
unless can?(current_user, :create_group, nil)
|
|
|
|
return render_404
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def authorize_admin_group!
|
|
|
|
unless can?(current_user, :manage_group, group)
|
|
|
|
return render_404
|
|
|
|
end
|
2013-01-25 04:30:49 -05:00
|
|
|
end
|
2013-06-07 10:41:01 -04:00
|
|
|
|
|
|
|
def set_title
|
|
|
|
@title = 'New Group'
|
|
|
|
end
|
2013-06-08 09:26:57 -04:00
|
|
|
|
|
|
|
def determine_layout
|
|
|
|
if [:new, :create].include?(action_name.to_sym)
|
|
|
|
'navless'
|
|
|
|
else
|
|
|
|
'group'
|
|
|
|
end
|
|
|
|
end
|
2012-10-02 13:42:15 -04:00
|
|
|
end
|