2012-10-02 13:42:15 -04:00
|
|
|
class GroupsController < ApplicationController
|
|
|
|
respond_to :html
|
2013-01-24 10:47:09 -05:00
|
|
|
layout 'group', except: [:new, :create]
|
2012-10-02 13:42:15 -04:00
|
|
|
|
2013-01-24 10:47:09 -05: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]
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
def people
|
2012-11-29 12:14:05 -05:00
|
|
|
@project = group.projects.find(params[:project_id]) if params[:project_id]
|
|
|
|
@users = @project ? @project.users : group.users
|
2012-12-14 00:14:05 -05:00
|
|
|
@users.sort_by!(&:name)
|
2012-11-29 12:14:05 -05:00
|
|
|
|
|
|
|
if @project
|
|
|
|
@team_member = @project.users_projects.new
|
2012-12-25 17:52:49 -05:00
|
|
|
else
|
|
|
|
@team_member = UsersProject.new
|
2012-11-29 12:14:05 -05:00
|
|
|
end
|
2012-10-02 13:42:15 -04:00
|
|
|
end
|
|
|
|
|
2012-12-25 17:52:49 -05:00
|
|
|
def team_members
|
2012-12-26 11:30:11 -05:00
|
|
|
@group.add_users_to_project_teams(params[:user_ids], params[:project_access])
|
2013-04-09 22:43:02 -04:00
|
|
|
redirect_to people_group_path(@group), notice: 'Users were successfully added.'
|
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
|
|
|
|
owner_id =group_params.delete(:owner_id)
|
|
|
|
|
|
|
|
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
|
2012-10-02 13:42:15 -04:00
|
|
|
end
|