A stronger validation
This commit is contained in:
parent
54a33e02ab
commit
0936a338d1
@ -54,7 +54,7 @@ class DmsfFile < ActiveRecord::Base
|
||||
validates :name, :presence => true
|
||||
validates_format_of :name, :with => /\A[^#{DmsfFolder::INVALID_CHARACTERS}]*\z/,
|
||||
:message => l(:error_contains_invalid_character)
|
||||
|
||||
validates :project, :presence => true
|
||||
validate :validates_name_uniqueness
|
||||
|
||||
def validates_name_uniqueness
|
||||
|
||||
@ -69,6 +69,7 @@ class DmsfFileRevision < ActiveRecord::Base
|
||||
validates_format_of :name, :with => /\A[^#{DmsfFolder::INVALID_CHARACTERS}]*\z/,
|
||||
:message => l(:error_contains_invalid_character)
|
||||
validates :description, length: { maximum: 1.kilobyte }
|
||||
validates :dmsf_file, :presence => true
|
||||
|
||||
def project
|
||||
self.dmsf_file.project if self.dmsf_file
|
||||
|
||||
@ -26,6 +26,8 @@ class DmsfFileRevisionAccess < ActiveRecord::Base
|
||||
delegate :dmsf_file, :to => :dmsf_file_revision, :allow_nil => false
|
||||
delegate :project, :to => :dmsf_file, :allow_nil => false
|
||||
|
||||
validates :dmsf_file_revision, :presence => true
|
||||
|
||||
DownloadAction = 0.freeze
|
||||
EmailAction = 1.freeze
|
||||
|
||||
|
||||
@ -101,6 +101,7 @@ class DmsfFolder < ActiveRecord::Base
|
||||
:message => l(:error_contains_invalid_character)
|
||||
validate :check_cycle
|
||||
validates_length_of :description, :maximum => 65535
|
||||
validates :project, :presence => true
|
||||
|
||||
before_create :default_values
|
||||
|
||||
|
||||
@ -22,6 +22,8 @@ class DmsfFolderPermission < ActiveRecord::Base
|
||||
|
||||
belongs_to :dmsf_folder
|
||||
|
||||
validates :dmsf_folder, :presence => true
|
||||
|
||||
scope :users, -> { where(:object_type => User.model_name.to_s) }
|
||||
scope :roles, -> { where(:object_type => Role.model_name.to_s) }
|
||||
|
||||
|
||||
@ -31,6 +31,7 @@ class DmsfLink < ActiveRecord::Base
|
||||
validates_length_of :name, :maximum => 255
|
||||
validates_length_of :external_url, :maximum => 255
|
||||
validate :validate_url
|
||||
validates :project, :presence => true
|
||||
|
||||
def validate_url
|
||||
if self.target_type == 'DmsfUrl'
|
||||
|
||||
@ -20,10 +20,13 @@
|
||||
|
||||
class DmsfWorkflowStep < ActiveRecord::Base
|
||||
belongs_to :dmsf_workflow
|
||||
belongs_to :user
|
||||
|
||||
has_many :dmsf_workflow_step_assignments, :dependent => :destroy
|
||||
validates :dmsf_workflow_id, :presence => true
|
||||
|
||||
validates :dmsf_workflow, :presence => true
|
||||
validates :step, :presence => true
|
||||
validates :user_id, :presence => true
|
||||
validates :user, :presence => true
|
||||
validates :operator, :presence => true
|
||||
validates_uniqueness_of :user_id, :scope => [:dmsf_workflow_id, :step]
|
||||
validates_length_of :name, :maximum => 30
|
||||
@ -39,10 +42,6 @@ class DmsfWorkflowStep < ActiveRecord::Base
|
||||
operator == 1 ? l(:dmsf_and) : l(:dmsf_or)
|
||||
end
|
||||
|
||||
def user
|
||||
User.find(user_id)
|
||||
end
|
||||
|
||||
def assign(dmsf_file_revision_id)
|
||||
step_assignment = DmsfWorkflowStepAssignment.new(
|
||||
:dmsf_workflow_step_id => id,
|
||||
|
||||
@ -23,17 +23,18 @@ class DmsfWorkflowStepAction < ActiveRecord::Base
|
||||
belongs_to :dmsf_workflow_step_assignment
|
||||
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
|
||||
|
||||
validates :dmsf_workflow_step_assignment_id, :presence => true
|
||||
validates :dmsf_workflow_step_assignment, :presence => true
|
||||
validates :action, :presence => true
|
||||
validates :note, :presence => true, :unless => lambda { self.action == DmsfWorkflowStepAction::ACTION_APPROVE }
|
||||
validates :author_id, :presence => true
|
||||
validates_uniqueness_of :dmsf_workflow_step_assignment_id, :scope => [:action], :unless => lambda {self.action == DmsfWorkflowStepAction::ACTION_DELEGATE}
|
||||
validates_uniqueness_of :dmsf_workflow_step_assignment_id, :scope => [:action],
|
||||
:unless => lambda {self.action == DmsfWorkflowStepAction::ACTION_DELEGATE}
|
||||
|
||||
ACTION_APPROVE = 1
|
||||
ACTION_REJECT = 2
|
||||
ACTION_DELEGATE = 3
|
||||
ACTION_ASSIGN = 4
|
||||
ACTION_START = 5
|
||||
ACTION_APPROVE = 1.freeze
|
||||
ACTION_REJECT = 2.freeze
|
||||
ACTION_DELEGATE = 3.freeze
|
||||
ACTION_ASSIGN = 4.freeze
|
||||
ACTION_START = 5.freeze
|
||||
|
||||
def initialize(*args)
|
||||
super
|
||||
|
||||
@ -22,8 +22,10 @@ class DmsfWorkflowStepAssignment < ActiveRecord::Base
|
||||
belongs_to :dmsf_workflow_step
|
||||
belongs_to :user
|
||||
belongs_to :dmsf_file_revision
|
||||
|
||||
has_many :dmsf_workflow_step_actions, :dependent => :destroy
|
||||
validates :dmsf_workflow_step_id, :dmsf_file_revision_id, :presence => true
|
||||
|
||||
validates :dmsf_workflow_step, :dmsf_file_revision, :presence => true
|
||||
validates_uniqueness_of :dmsf_workflow_step_id, :scope => [:dmsf_file_revision_id]
|
||||
|
||||
def add?(dmsf_file_revision_id)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user