Skip to content

Commit

Permalink
merge -r 2449:2525 branches/v1.1.0 trunk
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://rubyforge.org/var/svn/biocatalogue/trunk@2526 1acaf488-1b9d-4964-8077-0a2fdb83ef00
  • Loading branch information
jits committed Sep 22, 2011
1 parent d6c62f0 commit c2a9c64
Show file tree
Hide file tree
Showing 202 changed files with 4,526 additions and 2,451 deletions.
84 changes: 40 additions & 44 deletions app/controllers/annotations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class AnnotationsController < ApplicationController

before_filter :add_use_tab_cookie_to_session, :only => [ :create, :create_multiple, :update, :destroy, :set_as_field ]

before_filter :login_or_oauth_required, :only => [ :new, :create, :edit, :update, :destroy, :edit_popup, :create_inline, :change_attribute, :bulk_create ]
before_filter :login_or_oauth_required, :only => [ :new, :create, :edit, :update, :destroy, :edit_popup, :create_inline, :promote_alternative_name, :bulk_create ]

before_filter :parse_filtered_index_params, :only => :filtered_index

Expand All @@ -30,12 +30,12 @@ class AnnotationsController < ApplicationController

before_filter :find_annotations, :only => [ :index, :filtered_index ]

before_filter :find_annotation, :only => [ :show, :edit, :update, :destroy, :edit_popup, :download, :change_attribute ]
before_filter :find_annotation, :only => [ :show, :edit, :update, :destroy, :edit_popup, :download, :promote_alternative_name ]

before_filter :find_annotatable, :only => [ :new, :create, :new_popup, :create_inline ]

skip_before_filter :authorise_action
before_filter :authorise, :only => [ :edit, :edit_popup, :update, :destroy, :change_attribute, :bulk_create ]
before_filter :authorise, :only => [ :edit, :edit_popup, :update, :destroy, :promote_alternative_name, :bulk_create ]

def index
respond_to do |format|
Expand Down Expand Up @@ -103,24 +103,29 @@ def edit_popup
# PUT /annotations/1
# PUT /annotations/1.xml
def update
@annotation.value = params[:annotation][:value]
@annotation.version_creator_id = current_user.id
respond_to do |format|
if @annotation.save
flash[:notice] = 'Annotation was successfully updated.'

url_to_redirect_to = if @annotation.annotatable_type =~ /RestParameter|RestRepresentation/
request.env["HTTP_REFERER"]
else
url_for_web_interface(@annotation.annotatable) || home_url
end

format.html { redirect_to url_to_redirect_to }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @annotation.errors, :status => :unprocessable_entity }
# Only allow update for certain kind of annotation values
if [ 'TextValue', 'NumberValue' ].include?(@annotation.value_type)
@annotation.value.ann_content = params[:annotation][:value]
@annotation.version_creator_id = current_user.id
respond_to do |format|
if @annotation.save
flash[:notice] = 'Annotation was successfully updated.'

url_to_redirect_to = if @annotation.annotatable_type =~ /RestParameter|RestRepresentation/
request.env["HTTP_REFERER"]
else
url_for_web_interface(@annotation.annotatable) || home_url
end

format.html { redirect_to url_to_redirect_to }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @annotation.errors, :status => :unprocessable_entity }
end
end
else
error_to_back_or_home "Cannot perform this action!"
end
end

Expand All @@ -145,35 +150,26 @@ def create_inline
end

def download
send_data(@annotation.value, :type => "text/plain", :disposition => 'inline')
send_data(@annotation.value_content, :type => "text/plain", :disposition => 'inline')
end

def change_attribute
attribs_allowed_to_be_changed = %w( alternative_name )
attribs_allowed_to_be_changed_to = %w( display_name )

new_attrib = params[:new_attribute]

# Check that the attributes are allowed...
if attribs_allowed_to_be_changed.include?(@annotation.attribute_name.downcase) and
attribs_allowed_to_be_changed_to.include?(new_attrib.try(:downcase))

# Authorise and carry on...
if BioCatalogue::Auth.allow_user_to_curate_thing?(current_user, @annotation.annotatable)
@annotation.attribute_name = new_attrib

if @annotation.save
respond_to do |format|
flash[:notice] = "#{new_attrib.humanize} successfully updated"
format.html { redirect_to :back }
end
else
error_to_back_or_home "Sorry, something went wrong. Please try again. If this problem persists we would appreciate it if you contacted us."
def promote_alternative_name
if @annotation.attribute_name.downcase == "alternative_name" &&
BioCatalogue::Auth.allow_user_to_curate_thing?(current_user, @annotation.annotatable)

annotatable = @annotation.annotatable
annotatable.name = @annotation.val_content

if annotatable.save && @annotation.destroy
respond_to do |format|
flash[:notice] = "Display name successfully updated"
format.html { redirect_to :back }
end
else
error_to_back_or_home "You are not allowed to do that!"
error_to_back_or_home "Sorry, something went wrong. Please try again. If this problem persists we would appreciate it if you contacted us."
end

else
error_to_back_or_home "You are not allowed to do that!"
end
end

Expand Down
58 changes: 41 additions & 17 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# BioCatalogue: app/controllers/application_controller.rb
#
# Copyright (c) 2009-2010, University of Manchester, The European Bioinformatics
# Copyright (c) 2008-2011, University of Manchester, The European Bioinformatics
# Institute (EMBL-EBI) and the University of Southampton.
# See license.txt for details.

Expand All @@ -20,17 +20,9 @@ class ApplicationController < ActionController::Base
# Allow for SSL support
include SslRequirement
if ENABLE_SSL && Rails.env.production?
ssl_allowed :all
DEFAULT_PROTOCOL = 'https'
else
DEFAULT_PROTOCOL = 'http'
ssl_required :all
end

def default_protocol
DEFAULT_PROTOCOL
end
helper_method :default_protocol

# ============================================

# OAuth support
Expand Down Expand Up @@ -182,7 +174,7 @@ def mine?(thing)
return thing.source == current_user
when Service
return c_id == thing.submitter_id.to_i
when Favourite
when Favourite, ServiceResponsible
return c_id == thing.user_id
else
return false
Expand Down Expand Up @@ -220,7 +212,7 @@ def base_host
request.host_with_port
end

protected
protected

def debug_messages
BioCatalogue::Util.say ""
Expand Down Expand Up @@ -345,13 +337,12 @@ def error(messages, *args)
end

respond_to do |format|

if options[:back_first] && !session[:previous_url].blank?
if !options[:back_first].blank? && !session[:previous_url].blank? && session[:previous_url]!=request.env["REQUEST_URI"]
format.html { redirect_to(session[:previous_url]) }
else
format.html { render "home/index", :status => options[:status] }
end

if options[:forbidden]
format.xml { head :forbidden }
format.json { head :forbidden }
Expand All @@ -362,7 +353,7 @@ def error(messages, *args)
format.xml { render "api/errors", :status => options[:status] }
format.json { render :json => { "errors" => messages }.to_json, :status => options[:status] }
format.atom { render :atom => "", :status => options[:status] }
end
end
end
end

Expand Down Expand Up @@ -522,14 +513,42 @@ def generate_sort_url(resource, sort_by, sort_order)
helper_method :generate_sort_url

def is_sort_selected(sort_by, sort_order)
return params[:sort_by] == sort_by.downcase && params[:sort_order] == sort_order.downcase
return @sort_by == sort_by.downcase && @sort_order == sort_order.downcase
end
helper_method :is_sort_selected

def get_filter_groups
@filter_groups = BioCatalogue::Filtering.get_all_filter_groups_for(self.controller_name.underscore.to_sym, @limit || nil, params[:q])
end

def include_archived?
unless defined?(@include_archived)
session_key = "#{self.controller_name.downcase}_#{self.action_name.downcase}_include_archived"
if !params[:include_archived].blank?
@include_archived = !%w(false no 0).include?(params[:include_archived].downcase)
session[session_key] = @include_archived.to_s
elsif !session[session_key].blank?
@include_archived = (session[session_key] == "true")
else
@include_archived = true
session[session_key] = @include_archived.to_s
end
end
return @include_archived
end
helper_method :include_archived?

def generate_include_archived_url(resource, should_include_archived)
params_dup = BioCatalogue::Util.duplicate_params(params)
params_dup[:include_archived] = should_include_archived.to_s

# Reset page param
params_dup.delete(:page)

return eval("#{resource}_url(params_dup)")
end
helper_method :generate_include_archived_url

# ===============================


Expand Down Expand Up @@ -584,6 +603,11 @@ def log_event
ActivityLog.create(@log_event_core_data.merge(:action => "view_services_index",
:culprit => current_user,
:data => { :query => params[:q], :filters => @current_filters, :page => @page, :per_page => @per_page }))
# Archive/unarchive services
when "archive", "unarchive"
ActivityLog.create(@log_event_core_data.merge(:action => a,
:culprit => current_user,
:activity_loggable => @service))
else
do_generic_log = true
end
Expand Down
4 changes: 0 additions & 4 deletions app/controllers/contact_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ class ContactController < ApplicationController

before_filter :disable_action_for_api

if ENABLE_SSL && Rails.env.production?
ssl_required :all
end

# GET /contact
def index
respond_to do |format|
Expand Down
7 changes: 7 additions & 0 deletions app/controllers/curation_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ def annotation_level
end
end

def providers_without_services
@service_providers = BioCatalogue::Curation::Reports.providers_without_services

respond_to do |format|
format.html # providers_without_services.html.erb
end
end

protected

Expand Down
18 changes: 11 additions & 7 deletions app/controllers/oauth_clients_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ class OauthClientsController < ApplicationController
before_filter :get_client_application, :only => [ :show, :edit, :update, :destroy ]

before_filter :authorise, :only => [ :show, :edit, :update, :destroy ]

if ENABLE_SSL && Rails.env.production?
ssl_required :all
end


def index
@client_applications = current_user.client_applications
@tokens = current_user.tokens.find :all, :conditions => 'oauth_tokens.invalidated_at is null and oauth_tokens.authorized_at is not null'
Expand Down Expand Up @@ -53,8 +49,16 @@ def update
end

def destroy
@client_application.destroy
flash[:notice] = "Destroyed the client application registration"
begin
ClientApplication.transaction do
@client_application.destroy
end

flash[:notice] = "Destroyed the client application registration"
rescue
flash[:error] = "Could not delete the application"
end

redirect_to :action => "index"
end

Expand Down
4 changes: 0 additions & 4 deletions app/controllers/oauth_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ class OauthController < ApplicationController

before_filter :disable_action_for_api

if ENABLE_SSL && Rails.env.production?
ssl_required :all
end

# Override this to match your authorization page form
# It currently expects a checkbox called authorize
# def user_authorizes_token?
Expand Down
Loading

0 comments on commit c2a9c64

Please sign in to comment.