proofs_controller.rb revision 543c1be79aecb1d19f3bd50d8581da5c1cd0893b
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagherclass ProofsController < InheritedResources::Base
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher defaults resource_class: Proof
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher before_filter :check_write_permissions
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher helper_method :ontology
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher def new
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher resource
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher render template: 'proofs/new'
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher end
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher def new
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher render template: 'proofs/new'
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher end
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher def create
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher if resource.valid?
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher resource.save!
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher flash[:success] = t('proofs.create.starting_jobs')
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher redirect_to(redirect_chain)
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher else
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher flash[:alert] = t('proofs.create.invalid_resource')
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher redirect_to(action: :new)
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher end
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher end
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher protected
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher def resource
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher @resource ||= resource_class.new(params)
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher end
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher def ontology
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher resource.ontology
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher end
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher def redirect_chain
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher @redirect_chain = resource_chain
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher if resource.theorem?
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher @redirect_chain << resource.proof_obligation
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose else
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose @redirect_chain << :theorems
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose end
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose end
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose def check_write_permissions
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose authorize! :write, ontology.repository
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose end
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Boseend
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose