blob: 076a4df9e5fd06d997c882b7fb2a3764901cbd4b [file] [log] [blame]
#--######################################################################
# Copyright (c) 2006 LogicaCMG
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
#
# Onno van der Straaten:: initial implementation
#++######################################################################
# {Copyright (c) 2006 LogicaCMG}[link:files/COPYRIGHT.html]
class SitesController < ApplicationController
before_filter :authenticate
before_filter :authenticate_admin, :only => [:new, :compare, :new_wiki, :create, :update_wiki, :update, :upload]
before_filter :authenticate_cadmin, :only => [:wikify_now, :update_wiki_now, :scan4content]
FLASH_NEED_TO_UPLOAD = "To be able to create baseline process you will first have to upload a EPF published site to a folder in #{ENV['EPFWIKI_SITES_FOLDER']}"
FLASH_UPLOAD_SUCCESS = 'The file was uploaded, if the folder is not in dropdown box, please refresh'
FLASH_WIKI_SITE_SCHEDULED = 'The Wiki is scheduled to be created! For performance reasons this is done using a nightly build process. An email will be send after the site is created'
FLASH_WIKI_CREATED = 'Wiki succesfully created'
FLASH_WIKI_SITE_UPDATE_SCHEDULED = 'The site is scheduled to be updated. An email will be send after the site is updated'
FLASH_NO_BL_CANDIDATE = 'No candidate baseline processes found'
FLASH_WIKI_UPDATE_SUCCESS = 'Wiki succesfully updated'
FLASH_CHECKOUTS_NO_UPDATE = 'There are checkouts, so the Wiki cannot be updated. An email was sent requesting checkin.'
#--
# FIXME R1 Invalid argument in console
# In the console when running built-in server the message ERROR Errno::EINVAL: Invalid argument is displayed
#++
def index
list
render :action => 'list'
end
def list
@baseline_processes = Site.find_baseline_processes
@pending_sites = Site.find_wikis_pending
@wiki_sites = Site.find_wikis - @pending_sites
@deleted_sites = Site.find_all_by_site_type('D')
end
#--
# FIXME R1 error occured while evaluating nil.original_filename
# after upload of zip and submit of the new site. Workaround is to
# refresh the page
# FIXED? with redirect_to instead of render?
#++
def upload
@site = Site.new_upload(params[:site])
flash['success'] = FLASH_UPLOAD_SUCCESS if @site.errors.empty?
@baseline = Baseline.new
@folders = Site.folders_with_unused_baseline_processes
redirect_to :action => 'new'
end
# Action #new creates a baseline process. This will also define a Baseline, see Site.new_baseline_process.
def new
@baseline = Baseline.new
@folders = Site.folders_with_unused_baseline_processes
if request.get?
@site = Site.new
flash['notice'] = FLASH_NEED_TO_UPLOAD if @folders.empty?
else
@site = Site.new_baseline_process(params[:site].merge(:user => session['user']))
if @site.save
flash[:success] = ::FLASH_RECORD_CREATED
redirect_to :action => 'list'
else
render :action => 'new'
end
end
end
# FIXME ERROR Errno::EINVAL: Invalid argument
# appears in logging when new wiki is called
def new_wiki
@baseline_processes = Site.find_baseline_processes
if request.get?
@site = Site.new
else
@site = Site.new_wiki(params[:site].merge(:user => session['user']))
if @site.save
Notifier::deliver_wiki_scheduled(@site, session['user'])
flash['success'] = FLASH_WIKI_SITE_SCHEDULED
redirect_to :action => 'list'
end
end
end
# action #wikify_now wikifies the Site
def wikify_now
@wiki = Site.find(params[:id])
@wiki.wikify
if @wiki.save
flash.now['success'] = FLASH_WIKI_CREATED
Notifier::deliver_wiki_created(@wiki,@wiki.user)
end
show
render :action => 'show'
end
# action #update_wiki allows an administrator to schedule an update of a site with a Baseline.
# The actual update is performed typically done by generic.job_daily. See also #update_wiki_now
def update_wiki
@site = Site.find(params[:id])
if request.get?
flash.now['notice'] = FLASH_NO_BL_CANDIDATE if @site.baseline_processes_candidate.empty?
else
if @site.update_attributes(params[:site])
flash['success'] = FLASH_WIKI_SITE_UPDATE_SCHEDULED
unless @site.checkouts.empty?
flash['notice'] = 'The site has checkouts, an email has been sent to the owners requesting checkin. Update will be postponed untill all pages are checked in.'
Notifier::deliver_update_site_checkin_request(@site)
end
Notifier::deliver_wiki_scheduled4update(@site, session['user'])
redirect_to :action => 'show', :id => @site
end
end
end
# action #update_wiki_now allows the central administrator to do the update immediately, see also #update_wiki
def update_wiki_now
wiki = Site.find(params[:id])
if wiki.checkouts.empty?
wiki.update_wiki
if wiki.save
flash['success'] = FLASH_WIKI_UPDATE_SUCCESS
Notifier::deliver_email(([session['user'], User.find_central_admin]).uniq,
"[#{ENV['EPFWIKI_APP_NAME']}] Site #{wiki.title} updated!",[],
"The wiki site <strong>#{wiki.title}</strong> was succesfully updated to baseline #{wiki.baseline.baseline}")
else
# TODO because of the redirection use of error_messages in view will not work,
# so we misuse flash for displaying possibly messages. Maybe move this to 'edit'?
flash['error'] = wiki.errors.full_messages.join(', ')
end
else
flash['notice'] = FLASH_CHECKOUTS_NO_UPDATE
end
redirect_to :action => 'show', :id => wiki.id
end
def show
@site = Site.find(params[:id])
case params[:tab]
when nil
@version_pages, @versions = paginate :version, :per_page => 25, :order => 'created_on DESC', :conditions => ['site_id = ? and version <> 0', @site.id ]
when 'comments'
@comment_pages, @comments = paginate :comment, :per_page => 25, :order => 'created_on DESC', :conditions => ['site_id = ?', @site.id ]
when 'pages'
@page_pages, @pages = paginate :page, :per_page => 25, :order => 'created_on DESC', :conditions => ['exists (select * from pages_sites rrs where rrs.site_id = ? and rrs.page_id = pages.id)', @site.id]
end
end
def edit
@site = Site.find(params[:id])
if request.get?
else
@site = Site.find(params[:id])
if @site.update_attributes(params[:site])
flash['success'] = 'Site was successfully updated.'
redirect_to :action => 'show', :id => @site
else
render :action => 'edit'
end
end
end
def scan4content
show
@site.scan4content
if @site.save
flash['success'] ="Site was succesfully scanned for content. #{@site.pages.size.to_s} pages were scanned."
end
render :action => 'show'
end
end