2012-01-30 20:39:34 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
2011-10-16 21:39:45 +01:00
|
|
|
class GroupsController < ApplicationController
|
2011-11-30 15:27:19 +00:00
|
|
|
is_related_controller!
|
|
|
|
|
|
|
|
belongs_to :user, :optional => true
|
|
|
|
|
2011-10-16 21:39:45 +01:00
|
|
|
before_filter :authenticate_user!
|
|
|
|
before_filter :find_group, :only => [:show, :edit, :update, :destroy]
|
2011-11-19 11:41:11 +00:00
|
|
|
|
2012-03-21 13:52:35 +00:00
|
|
|
load_and_authorize_resource :except => :create
|
|
|
|
authorize_resource :only => :create
|
2011-12-11 23:42:13 +00:00
|
|
|
autocomplete :group, :uname
|
2011-10-16 21:39:45 +01:00
|
|
|
|
|
|
|
def index
|
2012-02-29 17:12:06 +00:00
|
|
|
@groups = current_user.groups#accessible_by(current_ability)
|
2011-11-30 15:27:19 +00:00
|
|
|
|
|
|
|
@groups = if params[:query]
|
|
|
|
@groups.where(["name LIKE ?", "%#{params[:query]}%"])
|
|
|
|
else
|
|
|
|
@groups
|
|
|
|
end.paginate(:page => params[:group_page])
|
2011-10-16 21:39:45 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
@platforms = @group.platforms.paginate(:page => params[:platform_page], :per_page => 10)
|
2011-12-08 14:47:18 +00:00
|
|
|
# @repositories = @group.repositories.paginate(:page => params[:repository_page], :per_page => 10)
|
2011-10-16 21:39:45 +01:00
|
|
|
@projects = @group.projects.paginate(:page => params[:project_page], :per_page => 10)
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@group = Group.new
|
|
|
|
end
|
|
|
|
|
2011-10-26 21:57:51 +01:00
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
2011-10-16 21:39:45 +01:00
|
|
|
def create
|
2012-03-21 13:52:35 +00:00
|
|
|
@group = Group.new(:description => params[:group][:description])
|
2012-03-03 01:34:24 +00:00
|
|
|
@group.owner = current_user
|
2012-03-21 13:52:35 +00:00
|
|
|
@group.uname = params[:group][:uname]
|
2011-11-30 15:27:19 +00:00
|
|
|
|
2012-03-03 00:19:31 +00:00
|
|
|
if @group.save
|
2011-10-16 21:39:45 +01:00
|
|
|
flash[:notice] = t('flash.group.saved')
|
2011-12-07 19:51:08 +00:00
|
|
|
redirect_to group_path(@group)
|
2011-10-16 21:39:45 +01:00
|
|
|
else
|
|
|
|
flash[:error] = t('flash.group.save_error')
|
2012-03-03 01:05:19 +00:00
|
|
|
flash[:warning] = @group.errors.full_messages.join('. ')
|
2011-10-16 21:39:45 +01:00
|
|
|
render :action => :new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-10-26 21:57:51 +01:00
|
|
|
def update
|
|
|
|
if @group.update_attributes(params[:group])
|
|
|
|
flash[:notice] = t('flash.group.saved')
|
2011-12-07 19:51:08 +00:00
|
|
|
redirect_to group_path(@group)
|
2011-10-26 21:57:51 +01:00
|
|
|
else
|
|
|
|
flash[:error] = t('flash.group.save_error')
|
|
|
|
render :action => :edit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@group.destroy
|
|
|
|
flash[:notice] = t("flash.group.destroyed")
|
|
|
|
redirect_to groups_path
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
2011-10-16 21:39:45 +01:00
|
|
|
def find_group
|
|
|
|
@group = Group.find(params[:id])
|
|
|
|
end
|
|
|
|
end
|