aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server/src/main/webapp/WEB-INF/app/controllers/events_controller.rb
blob: eda1d32255d32f404aee07a80852c35c8c545467 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#
# Sonar, entreprise quality control tool.
# Copyright (C) 2008-2011 SonarSource
# mailto:contact AT sonarsource DOT com
#
# Sonar is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
#
# Sonar is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with Sonar; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
#
class EventsController < ApplicationController

  SECTION=Navigation::SECTION_CONFIGURATION

  # GET /events?rid=123
  # GET /events.xml?rid=123
  def index
    @resource=Project.by_key(params[:rid])
    access_denied unless has_role?(:user, @resource)

    @events = Event.find(:all, :conditions => {:resource_id => @resource.id}, :order => 'created_at')

    respond_to do |format|
      format.html { render :layout => !request.xhr? }
      format.xml  { render :xml => @events }
    end
  end

  # GET /events/1
  # GET /events/1.xml
  def show
    @event = Event.find(params[:id])
    access_denied unless has_role?(:user, @event.resource)
    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @event }
    end
  end

  # GET /events/new?rid=123
  # GET /events/new.xml?rid=123
  def new
    resource = Project.find(params[:rid])
    @event = Event.new(:resource => resource)
    if params[:sid]
      snapshot=Snapshot.find(params[:sid])
      @event.event_date=snapshot.created_at
    end

    @categories=EventCategory.categories(true)

    respond_to do |format|
      format.html { render :layout => !request.xhr? }
      format.xml  { render :xml => @event }
    end
  end

  # GET /events/1/edit
  def edit
    @event = Event.find(params[:id])
    @categories=EventCategory.categories(true)
    render :layout => !request.xhr?
  end

  # POST /events
  # POST /events.xml
  def create
    @event = Event.new(params[:event])
    access_denied unless is_admin?(@event.resource)
    respond_to do |format|
      if @event.save
        flash[:notice] = 'Event is created.'
        format.html { redirect_to(:action => 'index') }
        format.xml  { render :xml => @event, :status => :created, :location => @event }
        format.js   # create.js.rjs
      else
        format.html { render :action => "new", :layout => !request.xhr? }
        format.xml  { render :xml => @event.errors, :status => :unprocessable_entity }
        format.js   # create.js.rjs
      end
    end
  end

  # PUT /events/1
  # PUT /events/1.xml
  def update
    @event = Event.find(params[:id])
    access_denied unless is_admin?(@event.resource)
    respond_to do |format|
      if @event.update_attributes(params[:event])
        flash[:notice] = 'Event was successfully updated.'
        format.html { redirect_to(@event) }
        format.xml  { head :ok }
        format.js   # create.js.rjs
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @event.errors, :status => :unprocessable_entity }
        format.js   # create.js.rjs
      end
    end
  end

  # DELETE /events/1
  # DELETE /events/1.xml
  def destroy
    @event = Event.find(params[:id])
    access_denied unless is_admin?(@event.resource)
    @event.destroy
    flash[:notice] = 'Event is deleted.'

    respond_to do |format|
      format.html { redirect_to(:controller => 'project', :action => 'index', :id => @event.resource_id) }
      format.xml  { head :ok }
    end
  end


end