Refactor courses
This commit is contained in:
@@ -23,64 +23,67 @@ require 'yaml'
|
||||
require 'authentication.rb'
|
||||
|
||||
class ApplicationController < ActionController::Base
|
||||
helper :all
|
||||
protect_from_forgery
|
||||
helper :all
|
||||
protect_from_forgery
|
||||
|
||||
include AuthenticationSystem
|
||||
include AuthenticationSystem
|
||||
|
||||
before_filter :startup
|
||||
#before_filter :set_timezone
|
||||
before_filter :require_login, :only => [ :edit, :new, :create, :update, :delete, :destroy ]
|
||||
before_filter :startup
|
||||
# before_filter :set_timezone
|
||||
before_filter :require_login, only: [:edit, :new, :create, :update, :delete,
|
||||
:destroy]
|
||||
|
||||
protected
|
||||
def rescue_action(exception)
|
||||
# Acesso negado
|
||||
if exception.is_a?(AccessDenied)
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
if logged_in?
|
||||
render :file => "#{Rails.root}/public/401.html", :status => 401
|
||||
else
|
||||
login_by_html
|
||||
end
|
||||
}
|
||||
format.xml { head 401 }
|
||||
end
|
||||
rescue_from AccessDenied, with: :deny_access
|
||||
rescue_from ActiveRecord::RecordInvalid, with: :reshow_form
|
||||
rescue_from ActiveRecord::RecordNotFound, with: :show_not_found
|
||||
|
||||
# Erro de validacao
|
||||
elsif exception.is_a?(ActiveRecord::RecordInvalid)
|
||||
respond_to do |format|
|
||||
format.html { render :action => (params[:from].nil? ? (exception.record.new_record? ? 'new' : 'edit') : params[:from]) }
|
||||
format.xml { render :xml => exception.record.errors, :status => :unprocessable_entity }
|
||||
end
|
||||
protected
|
||||
|
||||
# Registro nao encontrado
|
||||
elsif (RAILS_ENV == 'production') and exception.is_a?(ActiveRecord::RecordNotFound)
|
||||
respond_to do |format|
|
||||
format.html { render :file => "#{Rails.root}/public/404.html", :status => 404 }
|
||||
format.xml { head 404 }
|
||||
end
|
||||
def deny_access
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
if logged_in?
|
||||
render file: "#{Rails.root}/public/401.html", status: 401
|
||||
else
|
||||
login_by_html
|
||||
end
|
||||
end
|
||||
format.xml { head 401 }
|
||||
end
|
||||
end
|
||||
|
||||
# Outras excecoes
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
def reshow_form(exception)
|
||||
respond_to do |format|
|
||||
format.html { render action: (params[:from].nil? ? (exception.record.new_record? ? 'new' : 'edit') : params[:from]) }
|
||||
format.xml { render xml: exception.record.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
|
||||
#def set_timezone
|
||||
# #Time.zone = session[:user].tz
|
||||
# Time.zone = "America/Fortaleza"
|
||||
#end
|
||||
def show_not_found
|
||||
if (RAILS_ENV == 'production')
|
||||
respond_to do |format|
|
||||
format.html { render file: "#{Rails.root}/public/404.html", status: 404 }
|
||||
format.xml { head 404 }
|
||||
end
|
||||
else
|
||||
fail ActiveRecord::RecordNotFound
|
||||
end
|
||||
end
|
||||
|
||||
def startup
|
||||
if session[:user_id]
|
||||
@current_user = User.find(session[:user_id])
|
||||
else
|
||||
login_by_token
|
||||
end
|
||||
# def set_timezone
|
||||
# #Time.zone = session[:user].tz
|
||||
# Time.zone = "America/Fortaleza"
|
||||
# end
|
||||
|
||||
@color = App.default_color
|
||||
@color = @current_user.pref_color if @current_user
|
||||
@color = params[:color].to_i if params[:color]
|
||||
end
|
||||
def startup
|
||||
if session[:user_id]
|
||||
@current_user = User.find(session[:user_id])
|
||||
else
|
||||
login_by_token
|
||||
end
|
||||
|
||||
@color = App.default_color
|
||||
@color = @current_user.pref_color if @current_user
|
||||
@color = params[:color].to_i if params[:color]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -20,35 +20,26 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
class CoursesController < ApplicationController
|
||||
|
||||
before_filter :require_admin, :only => [:new, :create, :edit, :update, :destroy]
|
||||
before_filter :require_login, :only => [:enroll, :unenroll]
|
||||
before_filter :find_course, :except => [:index]
|
||||
#after_filter :cache_sweep, :only => [ :create, :update, :destroy ]
|
||||
before_filter :require_admin, only: [:new, :create, :edit, :update,
|
||||
:destroy]
|
||||
before_filter :require_login, only: [:enroll, :unenroll]
|
||||
before_filter :find_course, except: [:index]
|
||||
# after_filter :cache_sweep, only: [ :create, :update, :destroy ]
|
||||
|
||||
def index
|
||||
params[:period] = nil if params[:period] == App.current_period
|
||||
@period = params[:period] || App.current_period
|
||||
|
||||
if logged_in? and !@current_user.courses.empty?
|
||||
@courses = Course.all(:order => 'grade asc, full_name asc',
|
||||
:conditions => ['period = ? and hidden = ? and id not in (?)',
|
||||
@period, false, @current_user.courses])
|
||||
else
|
||||
@courses = Course.all(:order => 'grade asc, full_name asc',
|
||||
:conditions => ['period = ? and hidden = ?', @period, false])
|
||||
end
|
||||
@courses = Course.visible.where(period: @period)
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.xml { render :xml => @courses }
|
||||
format.xml { render xml: @courses }
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.xml { render :xml => @course }
|
||||
format.xml { render xml: @course }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -61,8 +52,9 @@ class CoursesController < ApplicationController
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to course_path(@course) }
|
||||
format.xml { head :created, :location => course_url(@course,
|
||||
:format => :xml) }
|
||||
format.xml do
|
||||
head :created, location: course_url(@course, format: :xml)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -111,19 +103,21 @@ class CoursesController < ApplicationController
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def find_course
|
||||
if params[:id]
|
||||
params[:id] = Course.first(:conditions => ['short_name = ?', params[:id]], :order => 'period desc').id if !params[:id].is_numeric? and !Course.find_by_short_name(params[:id]).nil?
|
||||
@course = Course.from_param(params[:id])
|
||||
else
|
||||
@course = Course.new(params[:course])
|
||||
end
|
||||
@course = params[:id] ? Course.find(params[:id]) : Course.new(params[:course])
|
||||
end
|
||||
|
||||
def require_admin
|
||||
raise AccessDenied.new unless admin?
|
||||
fail AccessDenied, 'only admins can modify courses' unless admin?
|
||||
end
|
||||
|
||||
def cache_sweep
|
||||
expire_fragment(course_path(@course.id, :part => 'right'))
|
||||
expire_fragment(course_path(@course.id, part: 'right'))
|
||||
expire_fragment(course_path(@course.id))
|
||||
expire_fragment(courses_path)
|
||||
end
|
||||
|
||||
@@ -27,7 +27,7 @@ module AttachmentsHelper
|
||||
end
|
||||
|
||||
def nest_path(items, paths, from, to, level)
|
||||
result = {}
|
||||
result = { }
|
||||
|
||||
base = from - 1
|
||||
base = base + 1 while base+1 <= to and paths[base+1][level].nil?
|
||||
|
||||
@@ -20,64 +20,70 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
class Course < ActiveRecord::Base
|
||||
|
||||
acts_as_paranoid
|
||||
|
||||
default_scope order('grade asc, full_name asc, period desc')
|
||||
|
||||
scope :visible, where(hidden: false)
|
||||
|
||||
has_many :attachments,
|
||||
:order => 'path is not null, path, file_name',
|
||||
:dependent => :destroy
|
||||
order: 'path is not null, path, file_name',
|
||||
dependent: :destroy
|
||||
|
||||
has_many :events,
|
||||
:order => 'time asc',
|
||||
:dependent => :destroy
|
||||
order: 'time asc',
|
||||
dependent: :destroy
|
||||
|
||||
has_many :news,
|
||||
:foreign_key => 'receiver_id',
|
||||
:order => 'id desc',
|
||||
:class_name => 'News',
|
||||
:dependent => :destroy
|
||||
foreign_key: 'receiver_id',
|
||||
order: 'id desc',
|
||||
class_name: 'News',
|
||||
dependent: :destroy
|
||||
|
||||
has_many :log_entries,
|
||||
:order => 'created_at desc',
|
||||
:dependent => :destroy
|
||||
order: 'created_at desc',
|
||||
dependent: :destroy
|
||||
|
||||
has_many :wiki_pages,
|
||||
:order => 'position',
|
||||
:dependent => :destroy
|
||||
order: 'position',
|
||||
dependent: :destroy
|
||||
|
||||
has_and_belongs_to_many :users,
|
||||
:order => 'last_seen desc'
|
||||
order: 'last_seen desc'
|
||||
|
||||
validates_presence_of :short_name
|
||||
validates_presence_of :full_name
|
||||
validates_presence_of :code
|
||||
validates_numericality_of :grade, :only_integer => true
|
||||
validates_inclusion_of :hidden, :in => [true, false], :allow_nil => false
|
||||
validates_format_of :short_name, :with => /^[^0-9]/
|
||||
validates_numericality_of :grade, only_integer: true
|
||||
validates_inclusion_of :hidden, in: [true, false], allow_nil: false
|
||||
validates_format_of :short_name, with: /^[^0-9]/
|
||||
|
||||
after_create :add_initial_wiki_pages
|
||||
|
||||
def related_courses
|
||||
Course.all(:conditions => ['short_name = ?', self.short_name], :limit => 4,
|
||||
:order => 'period desc')
|
||||
Course.all(conditions: ['short_name = ?', short_name], limit: 4,
|
||||
order: 'period desc')
|
||||
end
|
||||
|
||||
def recent_news
|
||||
self.news.all(:conditions => ['timestamp > ?', 7.days.ago])
|
||||
news.all(conditions: ['timestamp > ?', 7.days.ago])
|
||||
end
|
||||
|
||||
def add_initial_wiki_pages
|
||||
App.initial_wiki_pages.each do |page_title|
|
||||
wiki_page = WikiPage.new(:title => page_title, :description => 'New course',
|
||||
:content => App.initial_wiki_page_content)
|
||||
wiki_page = WikiPage.new(title: page_title, description: 'New course',
|
||||
content: App.initial_wiki_page_content)
|
||||
wiki_page.user = User.first
|
||||
self.wiki_pages << wiki_page
|
||||
wiki_pages << wiki_page
|
||||
wiki_page.save!
|
||||
end
|
||||
end
|
||||
|
||||
def to_param
|
||||
return self.short_name if self.period == App.current_period
|
||||
return self.id.to_s
|
||||
period == App.current_period ? short_name : id.to_s
|
||||
end
|
||||
|
||||
def self.from_param(param)
|
||||
param.is_numeric? ? Course.find(param) : Course.find_by_short_name(param)
|
||||
end
|
||||
end
|
||||
|
||||
5
app/models/coverage/.last_run.json
Normal file
5
app/models/coverage/.last_run.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"result": {
|
||||
"covered_percent": 3.57
|
||||
}
|
||||
}
|
||||
0
app/models/coverage/.resultset.json.lock
Normal file
0
app/models/coverage/.resultset.json.lock
Normal file
@@ -20,21 +20,28 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
class AttachmentLogEntry < LogEntry
|
||||
belongs_to :attachment,
|
||||
:foreign_key => "target_id",
|
||||
:with_deleted => true
|
||||
belongs_to :attachment,
|
||||
:foreign_key => "target_id",
|
||||
:with_deleted => true
|
||||
end
|
||||
|
||||
class AttachmentDeleteLogEntry < AttachmentLogEntry
|
||||
def reversible?()
|
||||
attachment.deleted?
|
||||
end
|
||||
def undo!(current_user)
|
||||
attachment.update_attribute(:deleted_at, nil)
|
||||
AttachmentRestoreLogEntry.create!(:target_id => attachment.id, :user_id => current_user.id, :course => attachment.course)
|
||||
end
|
||||
def reversible?()
|
||||
attachment.deleted?
|
||||
end
|
||||
|
||||
def undo!(current_user)
|
||||
attachment.update_attribute(:deleted_at, nil)
|
||||
AttachmentRestoreLogEntry.create!(:target_id => attachment.id,
|
||||
:user_id => current_user.id, :course => attachment.course)
|
||||
end
|
||||
end
|
||||
|
||||
class AttachmentEditLogEntry < AttachmentLogEntry; end
|
||||
class AttachmentCreateLogEntry < AttachmentLogEntry; end
|
||||
class AttachmentRestoreLogEntry < AttachmentLogEntry; end
|
||||
class AttachmentEditLogEntry < AttachmentLogEntry
|
||||
end
|
||||
|
||||
class AttachmentCreateLogEntry < AttachmentLogEntry
|
||||
end
|
||||
|
||||
class AttachmentRestoreLogEntry < AttachmentLogEntry
|
||||
end
|
||||
|
||||
@@ -20,21 +20,27 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
class EventLogEntry < LogEntry
|
||||
belongs_to :event,
|
||||
:foreign_key => "target_id",
|
||||
:with_deleted => true
|
||||
belongs_to :event,
|
||||
:foreign_key => "target_id",
|
||||
:with_deleted => true
|
||||
end
|
||||
|
||||
class EventDeleteLogEntry < EventLogEntry
|
||||
def reversible?()
|
||||
event.deleted?
|
||||
end
|
||||
def undo!(current_user)
|
||||
event.recover!
|
||||
EventRestoreLogEntry.create!(:target_id => event.id, :user_id => current_user.id, :course => event.course, :version => event.version)
|
||||
end
|
||||
def reversible?()
|
||||
event.deleted?
|
||||
end
|
||||
|
||||
def undo!(current_user)
|
||||
event.recover!
|
||||
EventRestoreLogEntry.create!(:target_id => event.id, :user_id => current_user.id, :course => event.course, :version => event.version)
|
||||
end
|
||||
end
|
||||
|
||||
class EventEditLogEntry < EventLogEntry; end
|
||||
class EventCreateLogEntry < EventLogEntry; end
|
||||
class EventRestoreLogEntry < EventLogEntry; end
|
||||
class EventEditLogEntry < EventLogEntry
|
||||
end
|
||||
|
||||
class EventCreateLogEntry < EventLogEntry
|
||||
end
|
||||
|
||||
class EventRestoreLogEntry < EventLogEntry
|
||||
end
|
||||
|
||||
@@ -22,100 +22,102 @@
|
||||
require 'digest/sha1'
|
||||
|
||||
class User < ActiveRecord::Base
|
||||
acts_as_paranoid
|
||||
|
||||
# Plugins
|
||||
acts_as_paranoid
|
||||
has_and_belongs_to_many :courses, order: 'full_name',
|
||||
conditions: "period = #{App.current_period}"
|
||||
|
||||
# Associacoes
|
||||
has_and_belongs_to_many :courses, :order => 'full_name', :conditions => "period = #{App.current_period}"
|
||||
validates_length_of :login, within: 3..40
|
||||
validates_length_of :name, within: 3..40
|
||||
validates_length_of :display_name, within: 3..40
|
||||
|
||||
# Validacao
|
||||
validates_length_of :login, :within => 3..40
|
||||
validates_length_of :name, :within => 3..40
|
||||
validates_length_of :display_name, :within => 3..40
|
||||
validates_presence_of :login, :email, :display_name
|
||||
validates_uniqueness_of :login, :email, :display_name
|
||||
|
||||
validates_presence_of :login, :email, :display_name
|
||||
validates_uniqueness_of :login, :email, :display_name
|
||||
validates_format_of :login, with: /^[^0-9]/
|
||||
validates_format_of :display_name, with: /^[^0-9]/
|
||||
|
||||
validates_format_of :login, :with => /^[^0-9]/
|
||||
validates_format_of :display_name, :with => /^[^0-9]/
|
||||
validates_format_of :email,
|
||||
with: /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
|
||||
|
||||
validates_format_of :email,
|
||||
:with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
|
||||
attr_protected :id, :salt
|
||||
attr_accessor :password, :password_confirmation
|
||||
|
||||
# Seguranca
|
||||
attr_protected :id, :salt
|
||||
attr_accessor :password, :password_confirmation
|
||||
def self.find_by_login_and_pass(login, pass)
|
||||
user = find(:first, conditions: ['login = ?', login])
|
||||
(!user.nil? && User.encrypt(pass, user.salt) == user.hashed_password) ? user : nil
|
||||
end
|
||||
|
||||
def User.find_by_login_and_pass(login, pass)
|
||||
user = find(:first, :conditions => [ "login = ?", login ])
|
||||
return (!user.nil? and User.encrypt(pass, user.salt) == user.hashed_password) ? user : nil
|
||||
end
|
||||
def to_xml(options = {})
|
||||
options[:indent] ||= 2
|
||||
xml = options[:builder] ||= Builder::XmlMarkup.new(indent: options[:indent])
|
||||
xml.instruct! unless options[:skip_instruct]
|
||||
xml.user do
|
||||
xml.id id
|
||||
xml.name name
|
||||
xml.display_name display_name
|
||||
xml.login login
|
||||
xml.created_at created_at
|
||||
xml.last_seen last_seen
|
||||
xml.description description
|
||||
end
|
||||
end
|
||||
|
||||
def to_xml(options = {})
|
||||
options[:indent] ||= 2
|
||||
xml = options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent])
|
||||
xml.instruct! unless options[:skip_instruct]
|
||||
xml.user do
|
||||
xml.id self.id
|
||||
xml.name self.name
|
||||
xml.display_name self.display_name
|
||||
xml.login self.login
|
||||
xml.created_at self.created_at
|
||||
xml.last_seen self.last_seen
|
||||
xml.description self.description
|
||||
end
|
||||
end
|
||||
# Gera uma nova senha, e a envia por email.
|
||||
def generate_password_reset_key!
|
||||
update_attribute(:password_reset_key, User.random_string(30))
|
||||
save!
|
||||
Notifications.deliver_forgot_password(email, password_reset_key)
|
||||
end
|
||||
|
||||
# Gera uma nova senha, e a envia por email.
|
||||
def generate_password_reset_key!
|
||||
update_attribute(:password_reset_key, User.random_string(30))
|
||||
save!
|
||||
Notifications.deliver_forgot_password(self.email, self.password_reset_key)
|
||||
end
|
||||
def reset_login_key
|
||||
self.login_key = Digest::SHA1.hexdigest(Time.now.to_s + password.to_s +
|
||||
rand(123_456_789).to_s).to_s
|
||||
end
|
||||
|
||||
def reset_login_key
|
||||
self.login_key = Digest::SHA1.hexdigest(Time.now.to_s + password.to_s + rand(123456789).to_s).to_s
|
||||
end
|
||||
def reset_login_key!
|
||||
reset_login_key
|
||||
save!
|
||||
login_key
|
||||
end
|
||||
|
||||
def reset_login_key!
|
||||
reset_login_key
|
||||
save!
|
||||
self.login_key
|
||||
end
|
||||
def to_param
|
||||
login.match(/^[-_a-z0-9]*$/i).nil? ? id.to_s : login
|
||||
end
|
||||
|
||||
def to_param
|
||||
self.login.match(/^[-_a-z0-9]*$/i).nil? ? self.id.to_s : self.login
|
||||
end
|
||||
def courses_not_enrolled(period)
|
||||
Course.all(conditions: ['period = ? and hidden = ? and id not in (?)',
|
||||
period, false, courses])
|
||||
end
|
||||
|
||||
protected
|
||||
def validate
|
||||
if new_record?
|
||||
errors.add_on_blank :password
|
||||
errors.add_on_blank :password_confirmation
|
||||
end
|
||||
protected
|
||||
|
||||
if !@password.blank?
|
||||
errors.add(:password_confirmation) if @password_confirmation.blank? or @password != @password_confirmation
|
||||
errors.add(:password, 'é muito curta') if !(5..40).include?(@password.length)
|
||||
end
|
||||
end
|
||||
def validate
|
||||
if new_record?
|
||||
errors.add_on_blank :password
|
||||
errors.add_on_blank :password_confirmation
|
||||
end
|
||||
|
||||
def before_save
|
||||
self.salt = User.random_string(10) if !self.salt?
|
||||
self.secret = User.random_string(32) if !self.secret?
|
||||
self.hashed_password = User.encrypt(@password, self.salt) if !@password.blank?
|
||||
end
|
||||
return unless @password.blank?
|
||||
errors.add(:password_confirmation) if @password_confirmation.blank? ||
|
||||
@password != @password_confirmation
|
||||
errors.add(:password, 'é muito curta') unless @password.length >= 5
|
||||
end
|
||||
|
||||
def self.encrypt(pass, salt)
|
||||
Digest::SHA1.hexdigest(pass + salt)
|
||||
end
|
||||
def before_save
|
||||
self.salt = User.random_string(10) unless self.salt?
|
||||
self.secret = User.random_string(32) unless self.secret?
|
||||
self.hashed_password = User.encrypt(@password, salt) unless @password.blank?
|
||||
end
|
||||
|
||||
def self.random_string(len)
|
||||
chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
|
||||
newpass = ""
|
||||
1.upto(len) { |i| newpass << chars[rand(chars.size-1)] }
|
||||
return newpass
|
||||
end
|
||||
def self.encrypt(pass, salt)
|
||||
Digest::SHA1.hexdigest(pass + salt)
|
||||
end
|
||||
|
||||
def self.random_string(len)
|
||||
chars = ('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a
|
||||
newpass = ''
|
||||
1.upto(len) { |_i| newpass << chars[rand(chars.size - 1)] }
|
||||
newpass
|
||||
end
|
||||
end
|
||||
|
||||
@@ -22,73 +22,68 @@
|
||||
require 'acts_as_versioned'
|
||||
require 'tempfile'
|
||||
|
||||
|
||||
class WikiPage < ActiveRecord::Base
|
||||
|
||||
attr_accessible :title, :front_page, :content, :description
|
||||
attr_writer :type
|
||||
|
||||
# Plugins
|
||||
acts_as_paranoid
|
||||
acts_as_list :scope => 'course_id = #{course_id}'
|
||||
acts_as_versioned :if_changed => [:content, :description, :title]
|
||||
self.non_versioned_columns << 'front_page'
|
||||
self.non_versioned_columns << 'position'
|
||||
self.non_versioned_columns << 'deleted_at'
|
||||
self.non_versioned_columns << 'canonical_title'
|
||||
acts_as_list scope: 'course_id = #{course_id}'
|
||||
acts_as_versioned if_changed: [:content, :description, :title]
|
||||
non_versioned_columns << 'front_page'
|
||||
non_versioned_columns << 'position'
|
||||
non_versioned_columns << 'deleted_at'
|
||||
non_versioned_columns << 'canonical_title'
|
||||
|
||||
# Associacoes
|
||||
belongs_to :course
|
||||
belongs_to :user, :with_deleted => true
|
||||
belongs_to :user, with_deleted: true
|
||||
|
||||
# Valicacao
|
||||
validates_presence_of :front_page
|
||||
validates_presence_of :description
|
||||
validates_presence_of :title
|
||||
validates_presence_of :content
|
||||
validates_uniqueness_of :title, :scope => :course_id
|
||||
validates_uniqueness_of :canonical_title, :scope => :course_id
|
||||
validates_format_of :title, :with => /^[^0-9]/
|
||||
validates_uniqueness_of :title, scope: :course_id
|
||||
validates_uniqueness_of :canonical_title, scope: :course_id
|
||||
validates_format_of :title, with: /^[^0-9]/
|
||||
|
||||
before_validation :set_canonical_title
|
||||
before_save :set_position
|
||||
|
||||
# acts_as_paranoid_versioned
|
||||
self.versioned_class.class_eval do
|
||||
def self.delete_all(conditions = nil)
|
||||
return
|
||||
versioned_class.class_eval do
|
||||
def self.delete_all(_conditions = nil)
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def set_canonical_title
|
||||
self.canonical_title = self.title.pretty_url
|
||||
canonical_title = title.pretty_url
|
||||
end
|
||||
|
||||
def set_position
|
||||
if !self.front_page
|
||||
self.remove_from_list
|
||||
elsif self.position.nil?
|
||||
self.update_attribute(:position, (self.course.wiki_pages.maximum(:position)||0) + 1)
|
||||
if !front_page
|
||||
remove_from_list
|
||||
elsif position.nil?
|
||||
update_attribute(:position, (course.wiki_pages.maximum(:position) || 0) + 1)
|
||||
end
|
||||
end
|
||||
|
||||
def validate
|
||||
begin
|
||||
self.content.format_wiki
|
||||
rescue
|
||||
errors.add("content", "possui erro de sintaxe: " + $!.to_s.html_escape)
|
||||
end
|
||||
content.format_wiki
|
||||
rescue
|
||||
errors.add("content", "possui erro de sintaxe: " + $ERROR_INFO.to_s.html_escape)
|
||||
end
|
||||
|
||||
def to_param
|
||||
self.canonical_title
|
||||
canonical_title
|
||||
end
|
||||
|
||||
def self.find_front_page
|
||||
WikiPage.all(:conditions => ["front_page = ?", true])
|
||||
WikiPage.all(conditions: ["front_page = ?", true])
|
||||
end
|
||||
|
||||
def WikiPage.diff(from, to)
|
||||
def self.diff(from, to)
|
||||
# Cria um arquivo com o conteudo da versao antiga
|
||||
original_content_file = Tempfile.new("old")
|
||||
original_content_file << from.content << "\n"
|
||||
@@ -100,12 +95,12 @@ class WikiPage < ActiveRecord::Base
|
||||
new_content_file.flush
|
||||
|
||||
# Calcula as diferencas
|
||||
diff = `diff -u #{original_content_file.path()} #{new_content_file.path()}`
|
||||
diff = `diff -u #{original_content_file.path} #{new_content_file.path}`
|
||||
|
||||
# Fecha os arquivos temporarios
|
||||
new_content_file.close!
|
||||
original_content_file.close!
|
||||
|
||||
return diff
|
||||
diff
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,29 +2,29 @@
|
||||
|
||||
%dl
|
||||
%dt
|
||||
%label{:for => "course_full_name"} Nome completo
|
||||
%dd= text_field 'course', 'full_name'
|
||||
%label{:for => "course_full_name"}= Course.human_attribute_name(:full_name)
|
||||
%dd= text_field 'course', 'full_name'
|
||||
|
||||
%dt
|
||||
%label{:for => "course_short_name"} Nome abreviado
|
||||
%label{:for => "course_short_name"}= Course.human_attribute_name(:short_name)
|
||||
%dd= text_field 'course', 'short_name'
|
||||
|
||||
%dt
|
||||
%label{:for => "course_code"} Código
|
||||
%label{:for => "course_code"}= Course.human_attribute_name(:code)
|
||||
%dd= text_field 'course', 'code'
|
||||
|
||||
%dt
|
||||
%label{:for => "course_grade"} Semestre
|
||||
%label{:for => "course_grade"}= Course.human_attribute_name(:grade)
|
||||
%dd= text_field 'course', 'grade'
|
||||
|
||||
%dt
|
||||
%label{:for => "course_period"} Data
|
||||
%label{:for => "course_period"}= Course.human_attribute_name(:period)
|
||||
%dd= text_field 'course', 'period'
|
||||
|
||||
%dt
|
||||
%label{:for => "course_hidden"} Ocultar
|
||||
%label{:for => "course_hidden"}= Course.human_attribute_name(:hidden)
|
||||
%dd= check_box 'course', 'hidden'
|
||||
|
||||
%dt
|
||||
%label{:for => "course_description"} Descrição
|
||||
%label{:for => "course_description"}= Course.human_attribute_name(:description)
|
||||
%dd= preserve(text_area('course', 'description', :cols => 60, :rows => 10))
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
%h4.title= App.title
|
||||
%h1.title Editar disciplina
|
||||
%h1.title= t(:edit_course)
|
||||
|
||||
%p
|
||||
= form_tag course_path(@course.id), :method => :put do
|
||||
= render :partial => 'form'
|
||||
= submit_tag 'Editar', :accesskey => 'e'
|
||||
= submit_tag t(:edit), :accesskey => 'e'
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
.cmd
|
||||
= action_icon('add', 'Cadastrar nova disciplina', new_course_url, :accesskey => '+') if admin?
|
||||
= action_icon('add', 'Cadastrar nova disciplina', new_course_url, accesskey: '+') if admin?
|
||||
|
||||
%h4.title= App.title
|
||||
%h1.title= "Disciplinas #{@period}"
|
||||
@@ -8,6 +8,7 @@
|
||||
%ul
|
||||
- if logged_in?
|
||||
- if params[:period].nil?
|
||||
- @courses = @current_user.courses_not_enrolled(@period)
|
||||
%h3 Disciplinas Matriculadas
|
||||
- if @current_user.courses.empty?
|
||||
%li.no_itens Nenhuma disciplina matriculada
|
||||
@@ -17,7 +18,7 @@
|
||||
= action_icon('subtract', 'Desmatricular-se', unenroll_course_url(course))
|
||||
= link_to h(course.full_name), course_url(course)
|
||||
|
||||
-# cache(courses_path) do
|
||||
-# cache(courses_path) do
|
||||
- old_grade = 0
|
||||
- for course in @courses
|
||||
- if course.grade != old_grade
|
||||
@@ -32,5 +33,5 @@
|
||||
|
||||
%h3
|
||||
Outros Semestres
|
||||
%li= link_to "2008.2", :period => '2008.2'
|
||||
%li= link_to "2008.1", :period => '2008.1'
|
||||
%li= link_to "2008.2", period: '2008.2'
|
||||
%li= link_to "2008.1", period: '2008.1'
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
%h4.title= App.title
|
||||
%h1.title Adicionar disciplina
|
||||
%h1.title= t(:new_course)
|
||||
|
||||
= form_tag courses_url, :method => :post do
|
||||
= render :partial => 'form'
|
||||
= submit_tag "Cadastrar", :accesskey => 'e'
|
||||
= submit_tag t(:create), :accesskey => 'e'
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
.cmd
|
||||
- if admin?
|
||||
= action_icon 'edit', 'Editar disciplina', edit_course_url, :accesskey => 'e'
|
||||
= action_icon 'edit', t(:edit_course), edit_course_url, :accesskey => 'e'
|
||||
=# action_icon 'trash', 'Excluir disciplina', course_url, :confirm => 'Tem certeza que deseja excluir?', :method => :delete
|
||||
|
||||
-# cache(course_path(@course.id)) do
|
||||
|
||||
%h4.title Disciplina
|
||||
%h4.title= t(:course).capitalize
|
||||
%h1.title= h(@course.full_name)
|
||||
|
||||
%p= @course.description.format_wiki
|
||||
@@ -31,32 +29,31 @@
|
||||
|
||||
.box
|
||||
.cmd
|
||||
= action_icon 'add', 'Adicionar página wiki', new_course_wiki_instance_url(@course)
|
||||
= action_icon 'add', t(:create_wiki_page), new_course_wiki_instance_url(@course)
|
||||
|
||||
%h3 Páginas Wiki
|
||||
%h3= t(:wiki_pages)
|
||||
%ul.wiki
|
||||
- @course.wiki_pages.find_front_page.each do |wiki|
|
||||
%li{highlight(wiki.id)}
|
||||
.cmd{:style => 'margin-bottom: -27px; margin-top: -9px;'}
|
||||
=action_icon 'arrow2_n', 'Mover para cima', move_up_course_wiki_instance_url(@course.to_param, wiki.id) unless wiki.first?
|
||||
=action_icon 'arrow2_s', 'Mover para baixo', move_down_course_wiki_instance_url(@course.to_param, wiki.id) unless wiki.last?
|
||||
=action_icon 'arrow2_n', t(:move_up), move_up_course_wiki_instance_url(@course.to_param, wiki.id) unless wiki.first?
|
||||
=action_icon 'arrow2_s', t(:move_down), move_down_course_wiki_instance_url(@course.to_param, wiki.id) unless wiki.last?
|
||||
- if wiki.last?
|
||||
%span{:style => 'margin-right: 14px'}
|
||||
=link_to h(wiki.title), course_wiki_instance_url(@course.to_param, wiki.id)
|
||||
- if @course.wiki_pages.empty?
|
||||
%li.no_itens Nenhuma página wiki
|
||||
%li.no_itens= t(:no_wiki_pages)
|
||||
- else
|
||||
%li.show_all= link_to "Ver todas as páginas wiki", course_wiki_url(@course)
|
||||
%li.show_all= link_to t(:see_all_wiki_pages), course_wiki_url(@course)
|
||||
|
||||
.box
|
||||
.cmd= action_icon 'add', 'Adicionar anexo', new_course_attachment_url(@course)
|
||||
.cmd= action_icon 'add', t(:create_attachment), new_course_attachment_url(@course)
|
||||
|
||||
%h3 Repositório de Arquivos
|
||||
%h3= t(:repository)
|
||||
.repositorio
|
||||
= nested_attachments_to_html(attachments_to_nested_hash(@course.attachments.find_front_page))
|
||||
- if @course.attachments.empty?
|
||||
%ul.wiki
|
||||
%li.no_itens Nenhum arquivo
|
||||
%li.no_itens= t(:no_attachments)
|
||||
- else
|
||||
%li.show_all= link_to "Ver todos os arquivos", course_attachments_url(@course)
|
||||
|
||||
%li.show_all= link_to t(:see_all_attachments), course_attachments_url(@course)
|
||||
|
||||
Reference in New Issue
Block a user