aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/admin_public_body_categories_controller.rb44
-rw-r--r--app/controllers/admin_public_body_controller.rb6
-rw-r--r--app/controllers/admin_public_body_headings_controller.rb63
-rw-r--r--app/controllers/general_controller.rb17
-rw-r--r--app/controllers/public_body_controller.rb3
-rw-r--r--app/controllers/request_controller.rb8
-rw-r--r--app/controllers/user_controller.rb12
7 files changed, 96 insertions, 57 deletions
diff --git a/app/controllers/admin_public_body_categories_controller.rb b/app/controllers/admin_public_body_categories_controller.rb
index 5e305dde3..a86171c76 100644
--- a/app/controllers/admin_public_body_categories_controller.rb
+++ b/app/controllers/admin_public_body_categories_controller.rb
@@ -7,17 +7,39 @@ class AdminPublicBodyCategoriesController < AdminController
def new
@category = PublicBodyCategory.new
- render :formats => [:html]
+ @category.build_all_translations
+ end
+
+ def create
+ I18n.with_locale(I18n.default_locale) do
+ @category = PublicBodyCategory.new(params[:public_body_category])
+ if @category.save
+ # FIXME: This can't handle failure (e.g. if a PublicBodyHeading
+ # doesn't exist)
+ if params[:headings]
+ params[:headings].values.each do |heading_id|
+ PublicBodyHeading.find(heading_id).add_category(@category)
+ end
+ end
+ flash[:notice] = 'Category was successfully created.'
+ redirect_to admin_categories_path
+ else
+ @category.build_all_translations
+ render :action => 'new'
+ end
+ end
end
def edit
@category = PublicBodyCategory.find(params[:id])
+ @category.build_all_translations
@tagged_public_bodies = PublicBody.find_by_tag(@category.category_tag)
end
def update
@category = PublicBodyCategory.find(params[:id])
@tagged_public_bodies = PublicBody.find_by_tag(@category.category_tag)
+
heading_ids = []
I18n.with_locale(I18n.default_locale) do
@@ -43,6 +65,8 @@ class AdminPublicBodyCategoriesController < AdminController
end
added_headings.each do |heading_id|
+ # FIXME: This can't handle failure (e.g. if a
+ # PublicBodyHeading doesn't exist)
PublicBodyHeading.find(heading_id).add_category(@category)
end
end
@@ -51,29 +75,13 @@ class AdminPublicBodyCategoriesController < AdminController
flash[:notice] = 'Category was successfully updated.'
redirect_to edit_admin_category_path(@category)
else
+ @category.build_all_translations
render :action => 'edit'
end
end
end
end
- def create
- I18n.with_locale(I18n.default_locale) do
- @category = PublicBodyCategory.new(params[:public_body_category])
- if @category.save
- if params[:headings]
- params[:headings].values.each do |heading_id|
- PublicBodyHeading.find(heading_id).add_category(@category)
- end
- end
- flash[:notice] = 'Category was successfully created.'
- redirect_to admin_categories_path
- else
- render :action => 'new'
- end
- end
- end
-
def destroy
@locale = self.locale_from_params
I18n.with_locale(@locale) do
diff --git a/app/controllers/admin_public_body_controller.rb b/app/controllers/admin_public_body_controller.rb
index cfb6f240d..7de27121a 100644
--- a/app/controllers/admin_public_body_controller.rb
+++ b/app/controllers/admin_public_body_controller.rb
@@ -23,6 +23,8 @@ class AdminPublicBodyController < AdminController
def new
@public_body = PublicBody.new
+ @public_body.build_all_translations
+
if params[:change_request_id]
@change_request = PublicBodyChangeRequest.find(params[:change_request_id])
end
@@ -53,6 +55,7 @@ class AdminPublicBodyController < AdminController
flash[:notice] = 'PublicBody was successfully created.'
redirect_to admin_body_url(@public_body)
else
+ @public_body.build_all_translations
render :action => 'new'
end
end
@@ -60,6 +63,8 @@ class AdminPublicBodyController < AdminController
def edit
@public_body = PublicBody.find(params[:id])
+ @public_body.build_all_translations
+
if params[:change_request_id]
@change_request = PublicBodyChangeRequest.find(params[:change_request_id])
end
@@ -89,6 +94,7 @@ class AdminPublicBodyController < AdminController
flash[:notice] = 'PublicBody was successfully updated.'
redirect_to admin_body_url(@public_body)
else
+ @public_body.build_all_translations
render :action => 'edit'
end
end
diff --git a/app/controllers/admin_public_body_headings_controller.rb b/app/controllers/admin_public_body_headings_controller.rb
index e893e760d..a7fe27390 100644
--- a/app/controllers/admin_public_body_headings_controller.rb
+++ b/app/controllers/admin_public_body_headings_controller.rb
@@ -1,22 +1,52 @@
class AdminPublicBodyHeadingsController < AdminController
+ def new
+ @heading = PublicBodyHeading.new
+ @heading.build_all_translations
+ end
+
+ def create
+ I18n.with_locale(I18n.default_locale) do
+ @heading = PublicBodyHeading.new(params[:public_body_heading])
+ if @heading.save
+ flash[:notice] = 'Heading was successfully created.'
+ redirect_to admin_categories_url
+ else
+ @heading.build_all_translations
+ render :action => 'new'
+ end
+ end
+ end
+
def edit
@heading = PublicBodyHeading.find(params[:id])
- render :formats => [:html]
+ @heading.build_all_translations
end
def update
+ @heading = PublicBodyHeading.find(params[:id])
+
I18n.with_locale(I18n.default_locale) do
- @heading = PublicBodyHeading.find(params[:id])
if @heading.update_attributes(params[:public_body_heading])
- flash[:notice] = 'Category heading was successfully updated.'
+ flash[:notice] = 'Heading was successfully updated.'
redirect_to edit_admin_heading_path(@heading)
else
+ @heading.build_all_translations
render :action => 'edit'
end
end
end
+ def destroy
+ @locale = self.locale_from_params
+ I18n.with_locale(@locale) do
+ heading = PublicBodyHeading.find(params[:id])
+ heading.destroy
+ flash[:notice] = "Heading was successfully destroyed."
+ redirect_to admin_categories_url
+ end
+ end
+
def reorder
transaction = reorder_headings(params[:headings])
if transaction[:success]
@@ -35,33 +65,6 @@ class AdminPublicBodyHeadingsController < AdminController
end
end
- def new
- @heading = PublicBodyHeading.new
- render :formats => [:html]
- end
-
- def create
- I18n.with_locale(I18n.default_locale) do
- @heading = PublicBodyHeading.new(params[:public_body_heading])
- if @heading.save
- flash[:notice] = 'Category heading was successfully created.'
- redirect_to admin_categories_url
- else
- render :action => 'new'
- end
- end
- end
-
- def destroy
- @locale = self.locale_from_params()
- I18n.with_locale(@locale) do
- heading = PublicBodyHeading.find(params[:id])
- heading.destroy
- flash[:notice] = "Category heading was successfully destroyed."
- redirect_to admin_categories_url
- end
- end
-
protected
def reorder_headings(headings)
diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb
index 2c8abbaf4..438bbfd3f 100644
--- a/app/controllers/general_controller.rb
+++ b/app/controllers/general_controller.rb
@@ -9,6 +9,8 @@ require 'open-uri'
class GeneralController < ApplicationController
+ MAX_RESULTS = 500
+
# New, improved front page!
def frontpage
medium_cache
@@ -124,38 +126,45 @@ class GeneralController < ApplicationController
end
end
+ @page = get_search_page_from_params
+
# Query each type separately for separate display (TODO: we are calling
# perform_search multiple times and it clobbers per_page for each one,
# so set as separate var)
requests_per_page = params[:requests_per_page] ? params[:requests_per_page].to_i : 25
- @this_page_hits = @total_hits = @xapian_requests_hits = @xapian_bodies_hits = @xapian_users_hits = 0
+ # Later pages are very expensive to load
+ if @page > MAX_RESULTS / requests_per_page
+ raise ActiveRecord::RecordNotFound.new("Sorry. No pages after #{MAX_RESULTS / requests_per_page}.")
+ end
+
+ @total_hits = @xapian_requests_hits = @xapian_bodies_hits = @xapian_users_hits = 0
if @requests
@xapian_requests = perform_search([InfoRequestEvent], @query, @sortby, 'request_collapse', requests_per_page)
@requests_per_page = @per_page
- @this_page_hits += @xapian_requests.results.size
@xapian_requests_hits = @xapian_requests.results.size
@xapian_requests_total_hits = @xapian_requests.matches_estimated
@total_hits += @xapian_requests.matches_estimated
@request_for_spelling = @xapian_requests
+ @max_requests = (@xapian_requests.matches_estimated > MAX_RESULTS) ? MAX_RESULTS : @xapian_requests.matches_estimated
end
if @bodies
@xapian_bodies = perform_search([PublicBody], @query, @sortby, nil, 5)
@bodies_per_page = @per_page
- @this_page_hits += @xapian_bodies.results.size
@xapian_bodies_hits = @xapian_bodies.results.size
@xapian_bodies_total_hits = @xapian_bodies.matches_estimated
@total_hits += @xapian_bodies.matches_estimated
@request_for_spelling = @xapian_bodies
+ @max_bodies = (@xapian_bodies.matches_estimated > MAX_RESULTS) ? MAX_RESULTS : @xapian_bodies.matches_estimated
end
if @users
@xapian_users = perform_search([User], @query, @sortby, nil, 5)
@users_per_page = @per_page
- @this_page_hits += @xapian_users.results.size
@xapian_users_hits = @xapian_users.results.size
@xapian_users_total_hits = @xapian_users.matches_estimated
@total_hits += @xapian_users.matches_estimated
@request_for_spelling = @xapian_users
+ @max_users = (@xapian_users.matches_estimated > MAX_RESULTS) ? MAX_RESULTS : @xapian_users.matches_estimated
end
# Spelling and highight words are same for all three queries
diff --git a/app/controllers/public_body_controller.rb b/app/controllers/public_body_controller.rb
index 2e540d198..cc3d0b64a 100644
--- a/app/controllers/public_body_controller.rb
+++ b/app/controllers/public_body_controller.rb
@@ -58,6 +58,9 @@ class PublicBodyController < ApplicationController
flash.keep(:search_params)
@track_thing = TrackThing.create_track_for_public_body(@public_body)
+ if @user
+ @existing_track = TrackThing.find_existing(@user, @track_thing)
+ end
@feed_autodetect = [ { :url => do_track_url(@track_thing, 'feed'), :title => @track_thing.params[:title_in_rss], :has_json => true } ]
respond_to do |format|
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb
index 081c14d7f..e847cae1e 100644
--- a/app/controllers/request_controller.rb
+++ b/app/controllers/request_controller.rb
@@ -16,11 +16,9 @@ class RequestController < ApplicationController
@@custom_states_loaded = false
begin
- if !Rails.env.test?
- require 'customstates'
- include RequestControllerCustomStates
- @@custom_states_loaded = true
- end
+ require 'customstates'
+ include RequestControllerCustomStates
+ @@custom_states_loaded = true
rescue MissingSourceFile, NameError
end
diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb
index 56f42891d..d66b4aa8e 100644
--- a/app/controllers/user_controller.rb
+++ b/app/controllers/user_controller.rb
@@ -460,6 +460,12 @@ class UserController < ApplicationController
return
end
if !params[:submitted_draft_profile_photo].nil?
+ if @user.banned?
+ flash[:error]= _('Banned users cannot edit their profile')
+ redirect_to set_profile_photo_path
+ return
+ end
+
# check for uploaded image
file_name = nil
file_content = nil
@@ -569,6 +575,12 @@ class UserController < ApplicationController
return
end
+ if @user.banned?
+ flash[:error] = _('Banned users cannot edit their profile')
+ redirect_to set_profile_about_me_path
+ return
+ end
+
@about_me = AboutMeValidator.new(params[:about_me])
if !@about_me.valid?
render :action => 'set_profile_about_me'