2014-03-23 00:22:25 +00:00
|
|
|
class GroupsController < ApplicationController
|
2020-03-16 23:57:47 +00:00
|
|
|
before_action :get_group, except: [:index, :new, :create]
|
2014-03-23 00:22:25 +00:00
|
|
|
|
|
|
|
def index
|
|
|
|
@groups = Group.all
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@group = Group.new
|
|
|
|
raise AccessError unless @group.can_create? cuser
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
@group.users.all
|
|
|
|
raise AccessError unless @group.can_update? cuser
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2020-03-18 03:38:17 +00:00
|
|
|
@group = Group.new(Group.params(params, cuser))
|
2014-03-23 00:22:25 +00:00
|
|
|
@group.founder = cuser
|
|
|
|
raise AccessError unless @group.can_create? cuser
|
|
|
|
if @group.save
|
|
|
|
flash[:notice] = t(:groups_create)
|
|
|
|
redirect_to @group
|
|
|
|
else
|
2014-03-31 21:33:16 +00:00
|
|
|
render :new
|
2014-03-23 00:22:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
raise AccessError unless @group.can_update? cuser
|
2020-03-18 03:38:17 +00:00
|
|
|
if @group.update_attributes(Group.params(params, cuser))
|
2014-03-23 00:22:25 +00:00
|
|
|
flash[:notice] = t(:groups_update)
|
|
|
|
redirect_to @group
|
|
|
|
else
|
2014-03-31 21:33:16 +00:00
|
|
|
render :edit
|
2014-03-23 00:22:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
raise AccessError unless @group.can_destroy? cuser
|
|
|
|
@group.destroy
|
|
|
|
redirect_to groups_url
|
|
|
|
end
|
|
|
|
|
|
|
|
def addUser
|
2020-04-02 02:51:37 +00:00
|
|
|
@user = User.where(username: params[:username])
|
2014-03-23 00:22:25 +00:00
|
|
|
raise AccessError unless @group.can_update? cuser
|
|
|
|
raise Error, t(:duplicate_user) if @group.users.include? @user
|
|
|
|
|
|
|
|
@group.users << @user if @user
|
2014-03-31 21:33:16 +00:00
|
|
|
redirect_to edit_group_url(@group, groupTab: "groupTabMembers")
|
2014-03-23 00:22:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def delUser
|
|
|
|
@user = User.find params[:id2]
|
|
|
|
raise AccessError unless @group.can_update? cuser
|
|
|
|
|
|
|
|
@group.users.delete @user
|
2014-03-31 21:33:16 +00:00
|
|
|
redirect_to edit_group_url(@group, groupTab: "groupTabMembers")
|
2014-03-23 00:22:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def get_group
|
|
|
|
@group = Group.find params[:id]
|
|
|
|
end
|
|
|
|
end
|