Class: ProjectValidator

Inherits:
ActiveModel::Validator
  • Object
show all
Defined in:
app/models/project_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate(project) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/models/project_validator.rb', line 2

def validate(project)
    # we need this because this method references the metadata_json which is not updated until the project is saved
    project. = project.

    # Required fields, always validate
    validate_role(project:, netid: project..data_manager, role: "Data Manager")
    validate_role(project:, netid: project..data_sponsor, role: "Data Sponsor")

    # Validate if present
    project..data_user_read_only&.each { |read_only| validate_role(project:, netid: read_only, role: "Data User Read Only")}
    project..data_user_read_write&.each { |read_write| validate_role(project:, netid: read_write, role: "Data User Read Write")}

    # validate all required fields
     = []
     = required_attributes(project:)
    if .values.include?(nil)
        required_keys.each do |attr|
            value = [attr]
             << "Missing metadata value for #{attr}" if value.nil? && project..include?(attr)
        end
    end
    if .count > 0
        project.errors.add :base, "Invalid Project Metadata it does not match the schema #{TigerdataSchema::SCHEMA_VERSION}\n #{.join(", ")}"
    end
end