code
stringlengths
1
1.73M
language
stringclasses
1 value
class FridgeModelsController < ApplicationController # GET /fridge_models # GET /fridge_models.json load_and_authorize_resource def index @fridge_models = FridgeModel.all respond_to do |format| format.html # index.html.erb format.json { render json: @fridge_models } end end # GET /...
Ruby
class RegionsController < ApplicationController # GET /regions # GET /regions.json load_and_authorize_resource def index @regions = Region.all respond_to do |format| format.html # index.html.erb format.json { render json: @regions } end end # GET /regions/1 # GET /r...
Ruby
class FridgesController < ApplicationController # GET /fridges # GET /fridges.json load_and_authorize_resource def index @fridges = Fridge.all respond_to do |format| format.html # index.html.erb format.json { render json: @fridges } end end # GET /fridges/1 # GET /fridges/1.json ...
Ruby
class FacilityTypesController < ApplicationController # GET /facility_types # GET /facility_types.json load_and_authorize_resource def index @facility_types = FacilityType.all respond_to do |format| format.html # index.html.erb format.json { render json: @facility_types } end ...
Ruby
class StaticPagesController < ApplicationController skip_authorization_check :only => [:home, :help, :about, :map, :inventory] def home end def help end def about end def layers render layout: false end def map render layout: false end end
Ruby
class SessionsController < ApplicationController skip_authorization_check :only => [:new, :create, :destroy ] def new end def create user = User.find_by_email(params[:session][:email]) if user && user.authenticate(params[:session][:password]) authorize! :manage, :all sign_in user redirect_t...
Ruby
class RequestsController < ApplicationController def locations render :json => [{:name => "Facility A", :latitude => 47.696071, :longitude => -122.329497}, {:name => "Facility B", :latitude => 47.676071, :longitude => -122.329497}, {:name => "Facility C", :latitude => 47.656071, :longitude => -122....
Ruby
class ZonesController < ApplicationController # GET /zones # GET /zones.json load_and_authorize_resource def index @zones = Zone.all respond_to do |format| format.html # index.html.erb format.json { render json: @zones } end end # GET /zones/1 # GET /zones/1.json ...
Ruby
class ApplicationController < ActionController::Base #protect_from_forgery include SessionsHelper rescue_from CanCan::AccessDenied do |exception| flash[:alert] = exception.message redirect_to root_url end check_authorization end
Ruby
# @author Alex, Ben and Joseph # controllers that checks your log in information # redirects if incorrect # if correct sends you to index page # also it has definition for language Engl/French class UsersController < ApplicationController load_and_authorize_resource skip_authorization_check :only => [:new, :cr...
Ruby
#!/usr/bin/env rake # 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__) SampleApp::Application.load_tasks
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
source 'https://rubygems.org' gem 'rails', '3.2.3' gem 'bootstrap-sass', '2.0.0' gem 'bcrypt-ruby', '3.0.1' gem 'cancan' group :development, :test do gem 'taps' gem 'sqlite3', '1.3.5' gem 'rspec-rails', '2.9.0' end # Gems used only for assets and not required # in production environments by defaul...
Ruby
class AddPasswordDigestToUsers < ActiveRecord::Migration def change add_column :users, :password_digest, :string end end
Ruby
class CreatePhrases < ActiveRecord::Migration def change create_table :phrases do |t| t.integer :num t.string :lang t.text :content t.timestamps end end end
Ruby
class CreateFunds < ActiveRecord::Migration def change create_table :funds do |t| t.integer :user_id t.integer :amount t.timestamps end end end
Ruby
class AddIndexToUsersEmail < ActiveRecord::Migration def change add_index :users, :email, unique: true end end
Ruby
class CreateFacilityTypes < ActiveRecord::Migration def change create_table :facility_types do |t| t.integer :id t.string :description t.timestamps end end end
Ruby
class CreateUsers < ActiveRecord::Migration def change create_table :users do |t| t.string :name t.string :email t.timestamps end end end
Ruby
class AddAdminToUsers < ActiveRecord::Migration def change add_column :users, :admin, :boolean, default: false end end
Ruby
class CreateFacilities < ActiveRecord::Migration def change create_table :facilities do |t| t.integer :id t.integer :lat t.integer :lon t.integer :subdistrict_id t.string :name t.integer :fac_type t.integer :target_births t.integer :target_pw t.integer :pop ...
Ruby
class AddEquipmentTypeToUsers < ActiveRecord::Migration def change add_column :users, :equipment_type, :integer, default: 0 end end
Ruby
class AddCapacityToFacilities < ActiveRecord::Migration def change add_column :facilities, :capacity, :integer, default:0 end end
Ruby
class CreateOwners < ActiveRecord::Migration def change create_table :owners do |t| t.string :owner_id t.integer :level t.integer :admin_id t.timestamps end end end
Ruby
class AddRememberTokenToUsers < ActiveRecord::Migration def change add_column :users, :remember_token, :string add_index :users, :remember_token end end
Ruby
class CreateZones < ActiveRecord::Migration def change create_table :zones do |t| t.integer :id t.string :name t.integer :region_id t.timestamps end end end
Ruby
class CreateRegions < ActiveRecord::Migration def change create_table :regions do |t| t.integer :id t.string :name t.timestamps end end end
Ruby
class AddFundsToUsers < ActiveRecord::Migration def change add_column :users, :funds, :integer, default: 0 end end
Ruby
class CreateSubdistricts < ActiveRecord::Migration def change create_table :subdistricts do |t| t.integer :id t.string :name t.integer :district_id t.integer :population t.integer :live_births t.integer :under_five t.integer :under_eight t.integer :child_bearing ...
Ruby
class AddEquipmentCountToUsers < ActiveRecord::Migration def change add_column :users, :equipment_count, :integer, default:0 end end
Ruby
class CreateDistricts < ActiveRecord::Migration def change create_table :districts do |t| t.integer :id t.string :name t.integer :zone_id t.timestamps end end end
Ruby
# This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). # # Examples: # # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) # Mayor.create(name: 'Emanuel...
Ruby
# This file is copied to spec/ when you run 'rails generate rspec:install' ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' require 'rspec/autorun' # Requires supporting ruby files with custom matchers and macros, etc, # in spec/support/ and its subdirect...
Ruby
# This file is used by Rack-based servers to start the application. require ::File.expand_path('../config/environment', __FILE__) run SampleApp::Application
Ruby
module FileBrowser def browse(root) queue = Array.new.push(root) while !queue.empty? filename = queue.pop if File.file?(filename) yield(filename) else Dir.new(filename).each do |child| unless ['..', '.','.svn'].include? child queue.push(filename + "/" + child) ...
Ruby
# This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). ActiveRecord::Base.transaction do # Categories # Control categories control_categories = [ ["Access Contr...
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 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 AddKindToPrograms < ActiveRecord::Migration def change add_column :programs, :kind, :string end end
Ruby
class RemoveControlIdFromRequests < ActiveRecord::Migration def up # replace all controls with adequate control assessments Request.all.each do |request| if request.control_id.present? control_assessment = ControlAssessment.where(:control_id => request.control_id, :pbc_list_id => request.pbc_lis...
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 CreateProjects < ActiveRecord::Migration def change create_table :projects 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 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 AddNotesToSystems < ActiveRecord::Migration def change add_column :systems, :notes, :text 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 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 AddPopulationSampleFieldsToResponses < ActiveRecord::Migration def change add_column :responses, :population_document_id, :integer add_column :responses, :population, :integer add_column :responses, :sample_worksheet_document_id, :integer add_column :responses, :samples, :integer add_column ...
Ruby
class AddProgramIdToCycles < ActiveRecord::Migration def change add_column :cycles, :program_id, :integer 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 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 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 AddReportDueAtToAuditCycle < ActiveRecord::Migration def change add_column :cycles, :report_due_at, :date end end
Ruby
class MoveImportHelpPaths < ActiveRecord::Migration def up help = Help.where(:slug => 'import').first help.update_attribute(:slug, 'systems_import') if help help = Help.where(:slug => 'import_controls').first help.update_attribute(:slug, 'controls_import') if help end def down end end
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 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 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 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 UniqueSlug < ActiveRecord::Migration def up add_index :sections, :slug, :unique => true add_index :controls, :slug, :unique => true add_index :biz_processes, :slug, :unique => true add_index :systems, :slug, :unique => true add_index :programs, :slug, :unique => true end def down re...
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 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 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 AddNotesToControls < ActiveRecord::Migration def change add_column :controls, :notes, :text end end
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 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 MovePbcListsColumnsToCycles < ActiveRecord::Migration def up change_table :cycles do |t| t.string :title t.string :audit_firm t.string :audit_lead t.text :description t.string :status t.text :notes end Cycle.reset_column_information Cycle.all.each do |cycle|...
Ruby
class ChangePolymorphicTypesToProgramFromDirective < ActiveRecord::Migration RELATIONSHIP_TYPE_NAME_CHANGES = [ [:directive_applies_to_data_asset, :program_applies_to_data_asset], [:directive_applies_to_facility, :program_applies_to_facility], [:directive_applies_to_market, :program_applies_to_marke...
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 AddBaseProgramKinds < ActiveRecord::Migration def up Option.where(:role => 'program_type').destroy_all role = 'program_kind' Option.where(:role => role, :title => 'Not Applicable').destroy_all [ 'Regulation', 'Company Policy', 'Operational Group Policy', 'Data Asset Policy' ].each d...
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 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 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 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 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 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 FixResponsesWithoutPopSamples < ActiveRecord::Migration def up end def down end end
Ruby
class AddTypeToRiskyAttributes < ActiveRecord::Migration def change change_table :risky_attributes do |t| t.string :type_string end end end
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 DeleteReferencesWithoutUrLs < ActiveRecord::Migration def up Document.where(:link => nil).concat(Document.where(:link => "")).each {|x| x.destroy} end def down end end
Ruby
class AddNetworkZoneIdToSystems < ActiveRecord::Migration def change add_column :systems, :network_zone_id, :integer end end
Ruby
class AddUrlToSections < ActiveRecord::Migration def change add_column :sections, :url, :string end end
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 AddNaToSection < ActiveRecord::Migration def change add_column :sections, :na, :boolean, :null => false, :default => false add_column :sections, :notes, :text end end
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 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 UpdateLanguagesAndControlKinds < ActiveRecord::Migration def up o = Option.where(:role => 'control_kind', :title => 'Directive').first if o o.title = 'Administrative' o.save end o = Option.where(:role => 'control_means', :title => 'Manual with Segregation of Duties').first if o ...
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 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 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 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 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 FixCategories < ActiveRecord::Migration def change change_table :categorizations do |t| t.belongs_to :modified_by end rename_column :categorizations, :stuff_id, :categorizable_id rename_column :categorizations, :stuff_type, :categorizable_type change_table :categories do |t| t.b...
Ruby
class SetProgramIdOnCycles < ActiveRecord::Migration def up transaction do Cycle.all.each do |cycle| directive = Directive.find(cycle.directive_id) program = directive.programs.first cycle.update_attribute(:program_id, program.id) end end end def down end end
Ruby
class CreateMeetings < ActiveRecord::Migration def change create_table :meetings do |t| t.references :response t.datetime :start_at t.string :calendar_url t.references :modified_by t.timestamps end end end
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 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 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 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 AddRequiredToOptions < ActiveRecord::Migration def change add_column :options, :required, :boolean 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