code
stringlengths
1
1.73M
language
stringclasses
1 value
class AddDefaultOptionsAndCategories < ActiveRecord::Migration def up Option.reset_column_information Category.reset_column_information Categorization.reset_column_information options = { :control_type => [], :control_kind => ["Reactive", "Directive", "Detective", "Preventative"], :...
Ruby
class AddProductStartStopDates < ActiveRecord::Migration def up change_table :products do |t| t.datetime :start_date t.datetime :stop_date end end def down change_table :products do |t| t.remove :start_date t.remove :stop_date end end end
Ruby
class AddRequiredToCategories < ActiveRecord::Migration def change add_column :categories, :required, :boolean end end
Ruby
class ConsolidateRiskFields < ActiveRecord::Migration def up transaction do Risk.all.each do |risk| impact = [risk.financial_impact, risk.reputational_impact, risk.operational_impact] impact = impact.map(&:presence).compact.join("<br />") risk.update_attribute(:impact, impact) ...
Ruby
class CreateRequests < ActiveRecord::Migration def change create_table :requests do |t| t.references :pbc_list t.references :type t.references :control t.string :pbc_control_code t.text :pbc_control_desc t.text :request t.text :test t.text :notes t.string :com...
Ruby
class RemoveParentheticalsFromStatusValues < ActiveRecord::Migration REQUEST_STATUS_MIGRATIONS = [ ["Responded (by Compliance)", "Responded"], ["Amended/Updated Request (by Auditor)", "Amended/Updated Request"], ["Accepted (by Auditor)", "Accepted"] ] def up REQUEST_STATUS_MIGRATIONS.each do |old...
Ruby
class AddPersonLanguage < ActiveRecord::Migration # Add a 'language_id' association from Person to the Option table # Local models so that migration is safe class Option < ActiveRecord::Base attr_accessible :role, :title end def up add_column :people, :language_id, :integer Option.reset_column_...
Ruby
class AddRequiredToOptions < ActiveRecord::Migration def change add_column :options, :required, :boolean end end
Ruby
class AddBaseMarketRelationships < ActiveRecord::Migration def up new_relationship_types = [ # Relationship types are in alphabetical order! { :relationship_type => 'market_contains_a_market', :description => "Markets can have submarkets.", :forward_phrase =>"containing", ...
Ruby
class AddObjectObjectStartStopDates < ActiveRecord::Migration def up change_table :object_people do |t| t.datetime :start_date t.datetime :stop_date end change_table :object_documents do |t| t.datetime :start_date t.datetime :stop_date end end def down change_table :ob...
Ruby
class AddProgramIdToCycles < ActiveRecord::Migration def change add_column :cycles, :program_id, :integer end end
Ruby
class AddNotesToSystems < ActiveRecord::Migration def change add_column :systems, :notes, :text end end
Ruby
class AddNotesToControls < ActiveRecord::Migration def change add_column :controls, :notes, :text end end
Ruby
class RenameLocationsToFacilities < ActiveRecord::Migration RELATIONSHIP_TYPE_NAME_CHANGES = [ ["location_has_process", "facility_has_process"], ["location_has_risky_attribute", "facility_has_risky_attribute"], ["location_is_dependent_on_location", "facility_is_dependent_on_faci...
Ruby
class CreatePbcLists < ActiveRecord::Migration def change create_table :pbc_lists do |t| t.references :audit_cycle t.string :title t.string :audit_firm t.string :audit_lead t.text :description t.datetime :list_import_date t.string :status t.text :notes t.refer...
Ruby
class CreateHelps < ActiveRecord::Migration def change create_table :helps do |t| t.string :slug t.string :content t.timestamps end end end
Ruby
class CreateControlAssessments < ActiveRecord::Migration def change create_table :control_assessments do |t| t.references :pbc_list t.references :control t.string :control_version t.boolean :internal_tod, :default => nil, :null => true t.boolean :internal_toe, :default => nil, :null ...
Ruby
class AddOptionReferences < ActiveRecord::Migration def up change_table :controls do |t| t.references :type t.references :kind t.references :means end change_table :systems do |t| t.references :type end end def down change_table :controls do |t| t.remove :type_i...
Ruby
class AddPopulationSampleForExistingResponses < ActiveRecord::Migration def up Request.all. select { |r| r.type_name == 'Population Sample' }. map { |r| r.responses.all }. flatten. each { |r| r.create_population_sample if r.population_sample.nil? } end def down end end
Ruby
class RemoveNameFromAccounts < ActiveRecord::Migration def up Account.all.each do |a| person = Person.find_by_email(a.email) if person person.name = "#{a.name} #{a.surname}" person.save!(:validate => false) else a.person = Person.create({:email => a.email, ...
Ruby
class AddSystemsIsBizProcess < ActiveRecord::Migration def up change_table :systems do |t| t.boolean :is_biz_process, :default => false end end def down change_table :systems do |t| t.remove :is_biz_process end end end
Ruby
class ChangeHelpsContentType < ActiveRecord::Migration def up change_column :helps, :content, :text, :limit => nil end def down change_column :helps, :content, :string end end
Ruby
class SetDefaultKindForPrograms < ActiveRecord::Migration def up transaction do Program.all.each do |program| program.kind = "Directive" if program.kind.blank? program.save! end end end def down end end
Ruby
class CreateBaseRelationshipTypes < ActiveRecord::Migration class RelationshipType < ActiveRecord::Base self.primary_key = 'relationship_type' end def up RelationshipType.create({:relationship_type => 'within_scope_of', :description => 'The source is within the scope of the ...
Ruby
class AddKindToPrograms < ActiveRecord::Migration def change add_column :programs, :kind, :string end end
Ruby
class AddControlAssessmentIdToRequests < ActiveRecord::Migration def change add_column :requests, :control_assessment_id, :integer add_index :requests, :control_assessment_id end end
Ruby
class UpdateRelationshipTypeIds < ActiveRecord::Migration RELATIONSHIP_TYPE_NAME_CHANGES = [ [:program_is_relevant_to_org_group, :program_applies_to_org_group], [:program_is_relevant_to_product, :program_applies_to_product], [:program_is_relevant_to_facility, :program_applies_to_facility], ...
Ruby
class AddProgramColumns < ActiveRecord::Migration def up change_table :programs do |t| t.string :version t.datetime :start_date t.datetime :stop_date t.string :url t.string :organization t.text :scope t.references :kind t.datetime :audit_start_date t.reference...
Ruby
class CreateResponses < ActiveRecord::Migration def change create_table :responses do |t| t.references :request t.references :system t.string :status t.references :modified_by t.timestamps end end end
Ruby
class ReorgControls < ActiveRecord::Migration class Program < ActiveRecord::Base end class Section < ActiveRecord::Base belongs_to :parent, :class_name => "Section" end def up raise "do not know how to migrate ControlControls" unless ControlControl.count == 0 rename_table :control_control_object...
Ruby
class RemovePbcListsColumns < ActiveRecord::Migration def up change_table :pbc_lists do |t| t.remove :title t.remove :description t.remove :audit_firm t.remove :audit_lead t.remove :notes t.remove :list_import_date t.remove :status end end def down end end
Ruby
class CreateProgramDirectives < ActiveRecord::Migration def change create_table :program_directives do |t| t.references :program, :null => false t.references :directive, :null => false t.references :modified_by t.timestamps end end end
Ruby
class AddTypeToRiskyAttributes < ActiveRecord::Migration def change change_table :risky_attributes do |t| t.string :type_string end end end
Ruby
class FixResponsesWithoutPopSamples < ActiveRecord::Migration def up end def down end end
Ruby
class CreateVersions < ActiveRecord::Migration def self.up create_table :versions do |t| t.string :item_type, :null => false t.integer :item_id, :null => false t.string :event, :null => false t.string :whodunnit t.text :object t.datetime :created_at end ...
Ruby
class AddPersonCompany < ActiveRecord::Migration def up add_column :people, :company, :string end def down remove_column :people, :company end end
Ruby
class ChangeLikelihoodPg < ActiveRecord::Migration def _is_postgresql? begin ActiveRecord::Base.connection.kind_of?( ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) rescue false end end def up if _is_postgresql? connection.execute(%q{ alter table risks...
Ruby
class AddMissingSystemFields < ActiveRecord::Migration def up change_table :systems do |t| t.datetime :start_date t.datetime :stop_date t.string :url t.string :version end end def down change_table :systems do |t| t.remove :start_date t.remove :stop_date t.re...
Ruby
class AddAssertionsToControls < ActiveRecord::Migration def change change_table :controls do |t| t.boolean :fraud_related t.boolean :key_control t.boolean :active end end end
Ruby
class CreateTransactions < ActiveRecord::Migration def change create_table :transactions do |t| t.string :title, :null => false t.text :description t.references :system t.references :modified_by t.timestamps end end end
Ruby
class ChangeStatusValues < ActiveRecord::Migration # "Draft" remains "Draft" in the new arrangement. REQUEST_STATUS_MIGRATIONS = [ ["Waiting Compliance", "Requested"], ["Waiting Auditors", "Responded (by Compliance)"], ["Completed", "Accepted (by Auditor)"] ] def up REQUEST_STATUS_M...
Ruby
class FixResponsesWithoutPopSamples2 < ActiveRecord::Migration def up transaction do Response .joins( :request ) .where( :requests => { :type_id => 2 } ) .joins("left outer join population_samples as population_sample on population_sample.response_id = responses.id") .where(:popu...
Ruby
class AddCompanyControlsProgram < ActiveRecord::Migration def up transaction do p = Program.where(:kind => "Company Controls").first if p.nil? p = Program.create(:kind => "Company Controls", :title => "Company Controls") end Directive.where(:kind => "Company Controls").each do |d|...
Ruby
class ChangeDirectiveKindToString < ActiveRecord::Migration def up transaction do Directive.all.each do |directive| option = Option.where(:role => 'directive_kind', :id => directive.kind_id).first kind = option ? option.title : "Regulation" kind = "Org Group Policy" if kind == "Opera...
Ruby
class AddRiskFields < ActiveRecord::Migration def change add_column :risks, :inherent_risk, :text add_column :risks, :risk_mitigation, :text add_column :risks, :residual_risk, :text add_column :risks, :impact, :text end end
Ruby
class CreateDataAssets < ActiveRecord::Migration def change create_table :data_assets do |t| t.string :slug t.string :title t.text :description t.string :url t.references :modified_by t.datetime :start_date t.datetime :stop_date t.timestamps end end end
Ruby
class RemoveDirectiveIdFromCycles < ActiveRecord::Migration def up remove_column :cycles, :directive_id end def down add_column :cycles, :directive_id, :integer end end
Ruby
class FixRelationshipDescription < ActiveRecord::Migration def up rename_column :relationship_types, :forward_short_description, :forward_phrase rename_column :relationship_types, :backward_short_description, :backward_phrase end def down rename_column :relationship_types, :forward_phrase, :forward_s...
Ruby
class CreateInitialTables < ActiveRecord::Migration def up create_table :accounts do |t| t.string :username t.string :name t.string :surname t.string :email t.string :crypted_password t.string :role t.string :persistence_token t.belongs_to :modified_by t.time...
Ruby
class FixCategoryScopes < ActiveRecord::Migration def up # Fix previously-created categories which don't specify a scope_id Category.where(:scope_id => nil).update_all(:scope_id => Control::CATEGORY_TYPE_ID) end def down end end
Ruby
class AddTitleToHelps < ActiveRecord::Migration def change add_column :helps, :title, :string end end
Ruby
class AddProgramForEachDirective < ActiveRecord::Migration def up transaction do Directive.all.each do |directive| if directive.programs.count == 0 program = Program.create!( :title => directive.title ) program_directive = ProgramDirective.create!( ...
Ruby
class RenameProgramsToDirectives < ActiveRecord::Migration def up rename_table :programs, :directives rename_column :controls, :program_id, :directive_id rename_column :sections, :program_id, :directive_id rename_column :cycles, :program_id, :directive_id end def down rename_table :directive...
Ruby
class DeprecateUnusedAccountRoles < ActiveRecord::Migration class Account < ActiveRecord::Base end def up Account.where(:role => :admin).each do |account| account.role = :superuser account.save end Account.where(:role => :admin).each do |account| account.role = :superuser acc...
Ruby
class CopyBizProcessesToSystems < ActiveRecord::Migration class BizProcess < ActiveRecord::Base end def up System.reset_column_information # Copy BizProcess and relations to System BizProcess.all.each do |bp| sys = System.create!( :title => bp.title, :slug => bp.slug, :...
Ruby
class CreateCategories < ActiveRecord::Migration def change create_table :categories do |t| t.string :name t.integer :parent_id t.integer :lft t.integer :rgt t.integer :scope_id t.integer :depth t.timestamps end create_table :categorizations do |t| t.refer...
Ruby
class AddNewRisksFields < ActiveRecord::Migration def change change_table :risks do |t| t.text :likelihood t.text :threat_vector t.text :trigger t.text :preconditions t.text :financial_impact t.text :reputational_impact t.text :operational_impact t.integer :likeli...
Ruby
class FixNilRequestStatuses < ActiveRecord::Migration def up Request.where(:status => nil).all.each do |req| req.update_attribute(:status, 'Draft') end end def down end end
Ruby
class AddEndAtToCycles < ActiveRecord::Migration def change add_column :cycles, :end_at, :date end end
Ruby
class LinkAccountsAndPeople < ActiveRecord::Migration # This migration does a few different things: # Adds an association between accounts and people # Renames the username attribute to email in people # Links accounts to people via e-mail, creating people # as necessary to map to accounts. # Local models ...
Ruby
class CreateOrgGroups < ActiveRecord::Migration def change create_table :org_groups do |t| t.string :slug t.string :title t.text :description t.string :url t.references :modified_by t.datetime :start_date t.datetime :stop_date t.timestamps end end end
Ruby
class AddReportDueAtToAuditCycle < ActiveRecord::Migration def change add_column :cycles, :report_due_at, :date end end
Ruby
class UpdateAccountRoles < ActiveRecord::Migration def up Account.where(:role => 'superuser').each do |account| account.role = 'admin' account.save end end def down end end
Ruby
class MoveProgramHelps < ActiveRecord::Migration HELP_SLUG_CHANGES = { :program_cycles => :directive_cycles, :program_info => :directive_info, :programs_list => :directives_list, :program_controls => :directive_controls, :program_more_info => :directive_more_info, :program => :directive } ...
Ruby
class RegulationToProgram < ActiveRecord::Migration def up rename_table :regulations, :programs rename_table :control_objectives, :sections change_table :sections do |t| t.integer :parent_id t.index :parent_id end end end
Ruby
class ChangePolymorphicTypesFromLocationToFacility < ActiveRecord::Migration def up ObjectPerson.where(:personable_type => 'Location').all.each do |o| o.update_attribute(:personable_type, 'Facility') end ObjectDocument.where(:documentable_type => 'Location').all.each do |o| o.update_attribute(...
Ruby
class CreateSystemSystems < ActiveRecord::Migration def change create_table :system_systems do |t| t.references :parent, :null => false t.references :child, :null => false t.string :type t.integer :order t.references :modified_by t.timestamps end end end
Ruby
class CreatePrograms < ActiveRecord::Migration def change create_table :programs do |t| t.string :slug t.string :title t.text :description t.string :url t.references :modified_by t.datetime :start_date t.datetime :stop_date t.timestamps end end end
Ruby
class RemoveRiskFields < ActiveRecord::Migration def up remove_column :risks, :financial_impact remove_column :risks, :reputational_impact remove_column :risks, :operational_impact end def down end end
Ruby
class AddDocumentOptionColumns < ActiveRecord::Migration def up change_table :documents do |t| t.text :description t.references :type t.references :kind t.references :year t.references :language end end def down change_table :documents do |t| t.remove :description ...
Ruby
class AddRelationshipTypeSymmetric < ActiveRecord::Migration def change add_column :relationship_types, :symmetric, :boolean, :default => false end end
Ruby
class EnsureRequestTypeIdIsNotNil < ActiveRecord::Migration def up Request.all.reject(&:type_name).each{ |r| r.update_attribute(:type_id, 1) } end def down end end
Ruby
class CreateControlRisks < ActiveRecord::Migration def change create_table :control_risks do |t| t.references :control, :null => false t.references :risk, :null => false t.references :modified_by t.timestamps end end end
Ruby
class CreateRelationshipTypes < ActiveRecord::Migration def change create_table :relationship_types, :id => false do |t| t.string :relationship_type t.string :description t.string :forward_short_description t.string :backward_short_description t.timestamps end add_index...
Ruby
class CreateRiskRiskyAttributes < ActiveRecord::Migration def change create_table :risk_risky_attributes do |t| t.references :risk, :null => false t.references :risky_attribute, :null => false t.references :modified_by t.timestamps end end end
Ruby
class CreateRiskyAttributes < ActiveRecord::Migration def change create_table :risky_attributes do |t| t.string :slug t.string :title t.text :description t.string :url t.references :modified_by t.datetime :start_date t.datetime :stop_date t.timestamps end ...
Ruby
class DeleteReferencesWithoutUrLs < ActiveRecord::Migration def up Document.where(:link => nil).concat(Document.where(:link => "")).each {|x| x.destroy} end def down end end
Ruby
class ChangePolymorphicTypesFromProgramToDirective < ActiveRecord::Migration RELATIONSHIP_TYPE_NAME_CHANGES = [ [:program_applies_to_data_asset, :directive_applies_to_data_asset], [:program_applies_to_facility, :directive_applies_to_facility], [:program_applies_to_market, :directive_applies_to_marke...
Ruby
class CreateProducts < ActiveRecord::Migration def up create_table :products do |t| t.string :slug t.string :title t.text :description t.string :url t.string :version t.references :type t.references :modified_by t.timestamps end end def down end end
Ruby
class CreatePopulationSamples < ActiveRecord::Migration def change create_table :population_samples do |t| t.references :response t.references :population_document t.integer :population t.references :sample_worksheet_document t.integer :samples t.references :sample_evidence_doc...
Ruby
class AddNetworkZoneIdToSystems < ActiveRecord::Migration def change add_column :systems, :network_zone_id, :integer end end
Ruby
class CreateRelationships < ActiveRecord::Migration def change create_table :relationships do |t| t.references :source, :polymorphic => true, :null => false t.references :destination, :polymorphic => true, :null => false t.references :modified_by t.string :relationship_type_id t.time...
Ruby
class FixRiskyAttributeSlugs < ActiveRecord::Migration def up RiskyAttribute.all.each do |ra| if ra.slug.match(/^RISKYATTRIBUTE/) ra.slug = ra.slug.sub(/^RISKYATTRIBUTE/, 'RA') ra.save! end end end def down end end
Ruby
class AddResponseDueAtToRequest < ActiveRecord::Migration def change add_column :requests, :response_due_at, :date end end
Ruby
#!/usr/bin/env ruby # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. APP_PATH = File.expand_path('../../config/application', __FILE__) require File.expand_path('../../config/boot', __FILE__) require 'rails/commands'
Ruby
module StateModel def state index = read_attribute(:state) || self.class.columns_hash['state'].default ControlState::VALUES[index] end def state=(value) write_attribute(:state, ControlState::VALUES.index(value)) end def good_state? ControlState::STATE_IS_GOOD[state] end def self.include...
Ruby
# Provides utility functions for doing authorization on CRUD and other operations # to the model, given a standard way of getting the current user and # a list of users and roles for an object. # Note: requires the model to implement the authorizing_objects method # FIXME: Properly deal with anonymous users - or are w...
Ruby
module BusinessObjectModel @business_object_models = nil def self.included(model) model.class_eval do end model.extend(ClassMethods) if model.ancestors.include?(ActiveRecord::Base) @business_object_models = [] if @business_object_models.nil? @business_object_models.push(model) end ...
Ruby
module CommonModel def self.included(model) model.send(:include, AuthoredModel) model.has_many :object_people, :as => :personable, :dependent => :destroy model.has_many :people, :through => :object_people model.has_many :object_documents, :as => :documentable, :dependent => :destroy model.has_many...
Ruby
module AuthoredModel # Typecast form parameters into the right primitive to work around a DataMapper dirty-detection bug. # # If we don't do this, the persistence layer thinks all non-strings params are modifications # where in fact we might just have changed false => 0, which is a no-op. This is important #...
Ruby
# A lot of this is cribbed from how declarative_authorization handles # model-based authorization. module Authorization # Controller-independent method for retrieving the current user. # Needed for model security where the current controller is not available. # Primarily for use by the console and tests, where w...
Ruby
module RoleModel ROLES = [:tech, :business] def role index = read_attribute(:role) || self.class.columns_hash['role'].default ROLES[index] end def role=(value) write_attribute(:role, ROLES.index(value)) end def self.included(model) model.validates :role, :presence => true end end
Ruby
module SearchableModel def self.included(model) model.extend(ClassMethods) end def self.sphinx_servers @@sphinx_servers ||= begin servers = CMS_CONFIG['FULLTEXT'] (servers or '').split(',').map do |host_port| { :host => host_port.split(':')[0], :port => host_port.split(':')[...
Ruby
module DefaultRelationshipTypes RELATIONSHIP_TYPES = { :data_asset_has_process => { :source_type => "DataAsset", :target_type => "Process", :forward_phrase => "has", :reverse_phrase => "is a process for", :forward_description => "This data asset relies upon the following processes."...
Ruby
module ControlState VALUES = [ :green, :yellow, :red, :unknown ] STATE_WEIGHT = { :green => 10, :unknown => 15, :yellow => 20, :red => 30 } STATE_IS_GOOD = { :green => true, :unknown => true } end
Ruby
module SluggedModel def compact_slug return slug unless parent cslug = slug cslug[parent.slug] = '' if cslug[parent.slug] # Substring replacement of parent.slug with '' return cslug end def self.included(model) model.extend(ClassMethods) model.class_eval do validates :slug, :presen...
Ruby
# RelatedModel mixin # # Many mixins that exist for managing relationships, and especially the relationship # traversal functions that are used in the context of authorization. # # Also creates some useful scoping functions that allow you to # create scopes for relationships with very little code. Example usage: # # In...
Ruby
module DatedModel include ActiveSupport::Concern def self.included(model) model.validate :stop_date_later_than_start_date end def stop_date_later_than_start_date if self.has_attribute? :stop_date if self.start_date.present? && self.stop_date.present? errors.add(:stop_date, 'Must be l...
Ruby
# Sanitize attributes before validation. # # Usage in model: # # sanitize_attributes :description, :documentation_description # module SanitizableAttributes # based on defaults from ActionView::Base.sanitized_allowed_tags with table tags added SANITIZED_ALLOWED_TAGS = %w(strong em b i p code pre tt samp kbd var s...
Ruby
# Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. require File.expand_path('../config/application', __FILE__) require 'rake' CmsRails::Application.load_tasks if Rails.env.development? || Rails.env.test? requ...
Ruby