# # This is the central component to parlement # # An element is just the name for a poll/message/issue # class EltController < ApplicationController def index params[:id] = params[:id].gsub(/.html/, '') show end def show params[:id] = params[:id].gsub(/.html/, '') @elt = Elt.find(params[:id]) @title = @elt.subject @title += " (parlement)" if !@title.downcase.include? "parlement" if request.env['REQUEST_URI'].match '.dyndns' headers["Status"] = "301 Moved Permanently" redirect_to request.env['REQUEST_URI'].gsub(/.dyndns/, '') end render :layout => 'top' # TODO rescue ActiveRecord::RecordNotFound => e flash[:error] = "Element '#{params[:id]}' does not exist" headers["Status"] = "301 Moved Permanently" redirect_to '/' end def list @elt = Elt.find(params[:id]) if @elt == nil render :partial => '/elt/list', :locals => { :elt => @elt } end def listByDate @elt = Elt.find params[:id] unless @elt render :partial => 'listByDate' end def listByVote @elt = Elt.find params[:id] unless @elt render :partial => 'listByVote' end def rss params[:id] = params[:id].gsub(/.rss/, '') @headers["Content-Type"] = "text/xml; charset=utf-8" @elt = Elt.find(params[:id]) if @elt == nil end def vote_rss params[:id] = params[:id].gsub(/.rss/, '') @headers["Content-Type"] = "text/xml; charset=utf-8" @elt = Elt.find(params[:id]) if @elt == nil end # Used to initialise the elt, its subject mainly def new @elt = Elt.new @elt.parent = Elt.find(params[:id]) if @elt.parent.subject.include? 'Re: ' @elt.subject = @elt.parent.subject else @elt.subject = 'Re: '+@elt.parent.subject end end def preview render :inline => format(params[:elt][:body]) end def create @elt = Elt.new(params[:elt]) @elt.person = @session[:person] if @elt.subject.match(/([<>\/]|href)/) then logger.error "SPAM! '#{@elt.subject}'" logger.error "SPAM! '#{@elt.body}'" flash[:error] = 'Sorry, to fight spam "<" ">" or "href" are forbidden in the subject!' headers["Status"] = "404 Post considered as spam" render :controller => 'elt', :action => 'new', :status => 404 elsif params[:submit] == "preview" or (@elt.publish and @elt.parent.add_child(@elt)) then headers["Status"] = "201 Created" render :partial => '/elt/elt', :locals => { :elt => @elt, :eltTop => false } else flash[:notice] = 'Error' render :controller => 'elt', :action => 'new' end end def raw_elt @mail = Elt.find(params[:id]).mail #@elt = TMail::Mail.parse(Elt.find(params[:id]).mail.id) render :inline => "
<%= @mail.file %>
", :layout => 'top' end def vote @elt = Elt.find params[:id] vote = @elt.children.build vote.person = session[:person] vote.subject = @elt.subject vote.subject = 'Re: '+vote.subject if vote.subject and !vote.subject.include? 'Re: ' vote.body = params[:choice][:value] choice = Choice.find_by_elt_id_and_person_id @elt.id, (session[:person] ? session[:person].id : nil) if choice and choice.value == vote.body.to_i then logger.info "#{(session[:person] ? session[:person].name : 'null')} voting 0" vote.body = "0" else logger.info "#{(session[:person] ? session[:person].name : 'null')} voting #{params[:choice][:value]}" end vote.publish @elt.add_child vote expire_fragment :action => 'show', :id => @elt.id render :partial => '/elt/choice', :locals => { :elt => @elt } end def choices @elt = Elt.find params[:id] end end