Module: Ixtlan::Controllers::GroupsController

Defined in:
lib/ixtlan/controllers/groups_controller.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
8
9
# File 'lib/ixtlan/controllers/groups_controller.rb', line 5

def self.included(base)
  base.send(:include, Ixtlan::Controllers::SearchQuery)
  # do not want to expose groups on filesystem cache
  base.cache_headers :private
end

Instance Method Details

#createObject

POST /groups POST /groups.xml



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/ixtlan/controllers/groups_controller.rb', line 74

def create
  group = params[:group] || {}
  group.delete(:locales)
  group.delete(:domains)
  @group = GROUP.new(group)
  @group.current_user = current_user

  respond_to do |format|
    if @group.save
      flash[:notice] = 'Group was successfully created.'
      format.html { redirect_to(group_url(@group.id)) }
      format.xml  { render :xml => @group, :status => :created, :location => group_url(@group.id) + ".xml" }
    else
      format.html { render :action => "new" }
      format.xml  { render :xml => @group.errors, :status => :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /groups/1 DELETE /groups/1.xml



115
116
117
118
119
120
121
122
123
124
125
# File 'lib/ixtlan/controllers/groups_controller.rb', line 115

def destroy
  @group = GROUP.first_or_get(params[:id])
  @group.current_user = current_user
  @group.destroy if @group

  respond_to do |format|
    flash[:notice] = 'Group was successfully deleted.'
    format.html { redirect_to(groups_url) }
    format.xml  { head :ok }
  end
end

#editObject

GET /groups/1/edit



68
69
70
# File 'lib/ixtlan/controllers/groups_controller.rb', line 68

def edit
  @group = GROUP.first_or_get!(params[:id])
end

#indexObject

GET /groups GET /groups.xml



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ixtlan/controllers/groups_controller.rb', line 19

def index
  @groups = query(GROUP, :name)

  # restrict the groups to the groups of the current user
  # unless the current user is allowed to create groups
  # and need to see all
  unless allowed(:create)
    allowed_group_ids = current_user.groups.collect {|g| g.id }
    @groups.delete_if do |g|
      ! allowed_group_ids.member?(g.id)
    end
  end

  respond_to do |format|
    format.html
    format.xml  { render :xml => @groups }
  end
end

#newObject

GET /groups/new GET /groups/new.xml



58
59
60
61
62
63
64
65
# File 'lib/ixtlan/controllers/groups_controller.rb', line 58

def new
  @group = GROUP.new

  respond_to do |format|
    format.html # new.html.erb
    format.xml  { render :xml => @group }
  end
end

#showObject

GET /groups/1 GET /groups/1.xml



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ixtlan/controllers/groups_controller.rb', line 40

def show
  @group = GROUP.first_or_get!(params[:id])

  # restrict the groups to the groups of the current user
  # unless the current user is allowed to create groups
  # and need to see all
  unless allowed(:create)
    allowed_groups = current_user.groups
  end

  respond_to do |format|
    format.html # show.html.erb
    format.xml  { render :xml => @group }
  end
end

#updateObject

PUT /groups/1 PUT /groups/1.xml



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/ixtlan/controllers/groups_controller.rb', line 95

def update
  @group = GROUP.first_or_get!(params[:id])
  @group.current_user = current_user

  @group.update_children((params[:group] || {}).delete(:locales), :locale)

  respond_to do |format|
    if @group.update(params[:group]) or not @group.dirty?
      flash[:notice] = 'Group was successfully updated.'
      format.html { redirect_to(group_url(@group.id)) }
      format.xml  { render :xml => @group }
    else
      format.html { render :action => "edit" }
      format.xml  { render :xml => @group.errors, :status => :unprocessable_entity }
    end
  end
end