Refactoring
This commit is contained in:
@@ -24,7 +24,7 @@ require 'authentication.rb'
|
|||||||
|
|
||||||
class ApplicationController < ActionController::Base
|
class ApplicationController < ActionController::Base
|
||||||
helper :all
|
helper :all
|
||||||
# protect_from_forgery
|
protect_from_forgery
|
||||||
|
|
||||||
include AuthenticationSystem
|
include AuthenticationSystem
|
||||||
|
|
||||||
@@ -59,7 +59,8 @@ class ApplicationController < ActionController::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def show_not_found
|
def show_not_found(exception)
|
||||||
|
fail Exception if Rails.env.production?
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { render file: "#{Rails.root}/public/404.html", status: 404, layout: false }
|
format.html { render file: "#{Rails.root}/public/404.html", status: 404, layout: false }
|
||||||
format.xml { head 404 }
|
format.xml { head 404 }
|
||||||
|
|||||||
@@ -20,103 +20,93 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
class AttachmentsController < ApplicationController
|
class AttachmentsController < ApplicationController
|
||||||
|
before_filter :find_attachment
|
||||||
|
|
||||||
#verify :method => :post, :only => [ :destroy, :create, :update ],
|
def show
|
||||||
# :redirect_to => { :controller => 'courses', :action => :show }
|
respond_to do |format|
|
||||||
|
format.html
|
||||||
|
format.xml { render xml: @attachment }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
#after_filter :cache_sweep, :only => [ :create, :update, :destroy ]
|
def new
|
||||||
|
end
|
||||||
|
|
||||||
before_filter :find_attachment
|
def create
|
||||||
|
@attachment.course_id = @course.id
|
||||||
|
@attachment.path = params[:attachment][:path]
|
||||||
|
@attachment.front_page = params[:attachment][:front_page]
|
||||||
|
@attachment.description = params[:attachment][:description]
|
||||||
|
@attachment.file_name = "blank"
|
||||||
|
unless params[:attachment][:file].nil?
|
||||||
|
@attachment.file = params[:attachment][:file]
|
||||||
|
@attachment.file_name = params[:attachment][:file].original_filename
|
||||||
|
@attachment.content_type = params[:attachment][:file].content_type
|
||||||
|
end
|
||||||
|
@attachment.save!
|
||||||
|
|
||||||
def show
|
AttachmentCreateLogEntry.create!(target_id: @attachment.id, user: @current_user, course: @course)
|
||||||
respond_to do |format|
|
flash[:notice] = t(:attachment_created)
|
||||||
format.html
|
|
||||||
format.xml { render :xml => @attachment }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def new
|
respond_to do |format|
|
||||||
end
|
format.html { redirect_to course_attachment_url(@course, @attachment) }
|
||||||
|
format.xml { head :created, location: course_attachment_url(@course, @attachment, format: :xml) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def create
|
def edit
|
||||||
@attachment.course_id = @course.id
|
end
|
||||||
@attachment.path = params[:attachment][:path]
|
|
||||||
@attachment.front_page = params[:attachment][:front_page]
|
|
||||||
@attachment.description = params[:attachment][:description]
|
|
||||||
@attachment.file_name = "blank"
|
|
||||||
unless params[:attachment][:file].nil?
|
|
||||||
@attachment.file = params[:attachment][:file]
|
|
||||||
@attachment.file_name = params[:attachment][:file].original_filename
|
|
||||||
@attachment.content_type = params[:attachment][:file].content_type
|
|
||||||
end
|
|
||||||
@attachment.save!
|
|
||||||
|
|
||||||
AttachmentCreateLogEntry.create!(:target_id => @attachment.id, :user => @current_user, :course => @course)
|
def update
|
||||||
flash[:notice] = t(:attachment_created)
|
@attachment.path = params[:attachment][:path]
|
||||||
|
@attachment.front_page = params[:attachment][:front_page]
|
||||||
|
@attachment.description = params[:attachment][:description]
|
||||||
|
unless params[:attachment][:file].nil?
|
||||||
|
@attachment.file = params[:attachment][:file]
|
||||||
|
@attachment.file_name = params[:attachment][:file].original_filename
|
||||||
|
@attachment.content_type = params[:attachment][:file].content_type
|
||||||
|
end
|
||||||
|
changed = @attachment.changed?
|
||||||
|
|
||||||
respond_to do |format|
|
if changed
|
||||||
format.html { redirect_to course_attachment_url(@course, @attachment) }
|
@attachment.last_modified = Time.now.utc
|
||||||
format.xml { head :created, :location => course_attachment_url(@course, @attachment, :format => :xml) }
|
@attachment.save!
|
||||||
end
|
AttachmentEditLogEntry.create!(target_id: @attachment.id, user: @current_user, course: @course)
|
||||||
end
|
flash[:notice] = t(:attachment_updated)
|
||||||
|
end
|
||||||
|
|
||||||
def edit
|
respond_to do |format|
|
||||||
end
|
format.html { redirect_to course_attachment_url(@course, @attachment) }
|
||||||
|
format.xml { head :created, location: course_attachment_url(@course, @attachment, format: :xml) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def update
|
def destroy
|
||||||
@attachment.path = params[:attachment][:path]
|
@attachment.destroy
|
||||||
@attachment.front_page = params[:attachment][:front_page]
|
flash[:notice] = t(:attachment_removed)
|
||||||
@attachment.description = params[:attachment][:description]
|
|
||||||
unless params[:attachment][:file].nil?
|
|
||||||
@attachment.file = params[:attachment][:file]
|
|
||||||
@attachment.file_name = params[:attachment][:file].original_filename
|
|
||||||
@attachment.content_type = params[:attachment][:file].content_type
|
|
||||||
end
|
|
||||||
changed = @attachment.changed?
|
|
||||||
|
|
||||||
if changed
|
log = AttachmentDeleteLogEntry.create!(target_id: @attachment.id, user: @current_user, course: @course)
|
||||||
@attachment.last_modified = Time.now.utc
|
flash[:undo] = undo_course_log_url(@course, log)
|
||||||
@attachment.save!
|
|
||||||
AttachmentEditLogEntry.create!(:target_id => @attachment.id, :user => @current_user, :course => @course)
|
|
||||||
flash[:notice] = t(:attachment_updated)
|
|
||||||
end
|
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { redirect_to course_attachment_url(@course, @attachment) }
|
format.html { redirect_to course_url(@course) }
|
||||||
format.xml { head :created, :location => course_attachment_url(@course, @attachment, :format => :xml) }
|
format.xml { head :ok }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def download
|
||||||
@attachment.destroy
|
send_file("#{Rails.root}/public/upload/#{@course.id}/#{@attachment.id}",
|
||||||
flash[:notice] = t(:attachment_removed)
|
filename: @attachment.file_name,
|
||||||
|
type: @attachment.content_type,
|
||||||
|
disposition: 'inline',
|
||||||
|
streaming: 'true')
|
||||||
|
end
|
||||||
|
|
||||||
log = AttachmentDeleteLogEntry.create!(:target_id => @attachment.id, :user => @current_user, :course => @course)
|
protected
|
||||||
flash[:undo] = undo_course_log_url(@course, log)
|
|
||||||
|
|
||||||
respond_to do |format|
|
def find_attachment
|
||||||
format.html { redirect_to course_url(@course) }
|
params[:course_id] = Course.find(:first, conditions: ['short_name = ?', params[:course_id]], order: 'period desc').id if !params[:course_id].is_numeric? && !Course.find_by_short_name(params[:course_id]).nil?
|
||||||
format.xml { head :ok }
|
@course = Course.find(params[:course_id])
|
||||||
end
|
@attachment = params[:id] ? @course.attachments.find(params[:id]) : Attachment.new
|
||||||
end
|
end
|
||||||
|
|
||||||
def download
|
|
||||||
|
|
||||||
send_file("#{Rails.root}/public/upload/#{@course.id}/#{@attachment.id}",
|
|
||||||
:filename => @attachment.file_name,
|
|
||||||
:type => @attachment.content_type,
|
|
||||||
:disposition => 'inline',
|
|
||||||
:streaming => 'true')
|
|
||||||
end
|
|
||||||
|
|
||||||
protected
|
|
||||||
def find_attachment
|
|
||||||
params[:course_id] = Course.find(:first, :conditions => ['short_name = ?', params[:course_id]], :order => 'period desc').id if !params[:course_id].is_numeric? and !Course.find_by_short_name(params[:course_id]).nil?
|
|
||||||
@course = Course.find(params[:course_id])
|
|
||||||
@attachment = params[:id] ? @course.attachments.find(params[:id]) : Attachment.new
|
|
||||||
end
|
|
||||||
|
|
||||||
def cache_sweep
|
|
||||||
expire_fragment(course_path(@course.id))
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -24,11 +24,9 @@ class CoursesController < ApplicationController
|
|||||||
:destroy]
|
:destroy]
|
||||||
before_filter :require_login, only: [:enroll, :unenroll]
|
before_filter :require_login, only: [:enroll, :unenroll]
|
||||||
before_filter :find_course, except: [:index]
|
before_filter :find_course, except: [:index]
|
||||||
# after_filter :cache_sweep, only: [ :create, :update, :destroy ]
|
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@period = params[:period] || App.current_period
|
@period = params[:period].blank? ? App.current_period : params[:period]
|
||||||
@courses = Course.visible.where(period: @period)
|
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html
|
format.html
|
||||||
@@ -115,10 +113,4 @@ class CoursesController < ApplicationController
|
|||||||
def require_admin
|
def require_admin
|
||||||
fail AccessDenied, 'only admins can modify courses' unless admin?
|
fail AccessDenied, 'only admins can modify courses' unless admin?
|
||||||
end
|
end
|
||||||
|
|
||||||
def cache_sweep
|
|
||||||
expire_fragment(course_path(@course.id, part: 'right'))
|
|
||||||
expire_fragment(course_path(@course.id))
|
|
||||||
expire_fragment(courses_path)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -23,9 +23,6 @@ class WikiController < ApplicationController
|
|||||||
# verify params: :text, only: :preview, redirect_to: { action: :show }
|
# verify params: :text, only: :preview, redirect_to: { action: :show }
|
||||||
# verify params: [:from, :to], only: :diff, redirect_to: { action: :versions }
|
# verify params: [:from, :to], only: :diff, redirect_to: { action: :versions }
|
||||||
|
|
||||||
# after_filter :cache_sweep, only: [ :create, :update, :destroy, :move_up,
|
|
||||||
# :move_down, :undelete ]
|
|
||||||
|
|
||||||
before_filter :find_wiki, except: [:preview]
|
before_filter :find_wiki, except: [:preview]
|
||||||
before_filter :require_login, only: [:new, :create, :edit, :update, :destroy,
|
before_filter :require_login, only: [:new, :create, :edit, :update, :destroy,
|
||||||
:move_up, :move_down]
|
:move_up, :move_down]
|
||||||
@@ -169,9 +166,4 @@ class WikiController < ApplicationController
|
|||||||
@wiki_page = WikiPage.new(params[:wiki_page])
|
@wiki_page = WikiPage.new(params[:wiki_page])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def cache_sweep
|
|
||||||
expire_fragment course_url(@course.id)
|
|
||||||
expire_fragment course_wiki_instance_url(@course.id, @wiki_page.id)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -88,7 +88,8 @@ class Course < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.pluck_periods
|
def self.pluck_periods
|
||||||
Course.uniq.pluck(:period).reject!(&:blank?).sort.reverse
|
periods = Course.uniq.reorder('').pluck(:period).reject!(&:blank?) || []
|
||||||
|
periods.sort.reverse
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.from_param(param)
|
def self.from_param(param)
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ class User < ActiveRecord::Base
|
|||||||
acts_as_paranoid
|
acts_as_paranoid
|
||||||
|
|
||||||
has_and_belongs_to_many :courses, order: 'full_name',
|
has_and_belongs_to_many :courses, order: 'full_name',
|
||||||
conditions: "period = #{App.current_period}"
|
conditions: "period = '#{App.current_period}'"
|
||||||
|
|
||||||
validates_length_of :login, within: 3..40
|
validates_length_of :login, within: 3..40
|
||||||
validates_length_of :name, within: 3..40
|
validates_length_of :name, within: 3..40
|
||||||
@@ -86,8 +86,12 @@ class User < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def courses_not_enrolled(period)
|
def courses_not_enrolled(period)
|
||||||
Course.all(conditions: ['period = ? and hidden = ? and id not in (?)',
|
if courses.empty?
|
||||||
period, false, courses])
|
Course.visible.where(period: period)
|
||||||
|
else
|
||||||
|
Course.where('period = ? and hidden = ? and id not in (?)',
|
||||||
|
period, false, courses)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|||||||
@@ -17,6 +17,8 @@
|
|||||||
.right
|
.right
|
||||||
= action_icon('subtract', 'Desmatricular-se', unenroll_course_url(course))
|
= action_icon('subtract', 'Desmatricular-se', unenroll_course_url(course))
|
||||||
= link_to h(course.full_name), course_url(course)
|
= link_to h(course.full_name), course_url(course)
|
||||||
|
- else
|
||||||
|
- @courses = Course.visible.where(period: @period)
|
||||||
|
|
||||||
-# cache(courses_path) do
|
-# cache(courses_path) do
|
||||||
- old_grade = 0
|
- old_grade = 0
|
||||||
|
|||||||
@@ -66,9 +66,9 @@
|
|||||||
#footer
|
#footer
|
||||||
%p
|
%p
|
||||||
%b Wiki
|
%b Wiki
|
||||||
UFC
|
UFC 1.1
|
||||||
%p
|
%p
|
||||||
Desenvolvido em Ruby on Rails
|
Powered by Ruby on Rails, PostgreSQL & Linux
|
||||||
%p
|
%p
|
||||||
Distribuido livremente sob a
|
Distribuido livremente sob a
|
||||||
%a{href: 'https://www.gnu.org/licenses/agpl-3.0.en.html'}
|
%a{href: 'https://www.gnu.org/licenses/agpl-3.0.en.html'}
|
||||||
|
|||||||
Reference in New Issue
Block a user