code
stringlengths
1
1.73M
language
stringclasses
1 value
class AccountsController < ApplicationController before_filter :require_user def index end def add if params[:account] @account = Account.new(params[:account]) @account.user = current_user end end def show end def delete @account = Account.find(params[:id]) end ...
Ruby
class UserController < ApplicationController before_filter :require_user, :except => [ :login, :logout, :create_admin_account ] def home @new_items = current_user.find_unseen_unpaid_bills @new_items.each do |item| item.seen = true item.save end end def login if request.post? ...
Ruby
class AdminController < ApplicationController before_filter :require_admin def index end def add_user end def create_user @user = User.new(params[:user]) end def delete_user @user = User.find(params[:id]) end end
Ruby
class HistoryController < ApplicationController before_filter :require_user def index end end
Ruby
# Filters added to this controller apply to all controllers in the application. # Likewise, all the methods added will be available for all controllers. class ApplicationController < ActionController::Base # Pick a unique cookie name to distinguish our session data from others' session :session_key => '_bill_track...
Ruby
class BillController < ApplicationController before_filter :require_user, :except => [ :payable_bills_feed ] before_filter :fetch_bill, :only => [ :delete, :show, :hide ] before_filter :fetch_payable_bill, :only => [ :open_pay, :close_pay ] def index end def add if params[:bill] ...
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.join(File.dirname(__FILE__), 'config', 'boot')) require 'rake' require 'rake/testtask' require 'rake/rdoctask' require 'tasks/rails'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/breakpointer'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/console'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/runner'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/performance/benchmarker'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/performance/benchmarker'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/performance/profiler'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/performance/profiler'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/plugin'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/destroy'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/about'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/runner'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/breakpointer'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/server'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/generate'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/console'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/reaper'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/inspector'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/inspector'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/spawner'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/reaper'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/spawner'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/destroy'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/generate'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/server'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/about'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/plugin'
Ruby
class CreateAccounts < ActiveRecord::Migration def self.up create_table :accounts do |t| t.column :user_id, :integer t.column :name, :string t.column :details, :string t.column :created_at, :datetime t.column :updated_at, :datetime t.column :deleted_at, :datetime ...
Ruby
class CreateBills < ActiveRecord::Migration def self.up create_table :bills do |t| t.column :user_id, :integer t.column :account_id, :integer t.column :name, :string t.column :amount, :string t.column :due, :date t.column :created_at, :datetime t.colum...
Ruby
class CreatePayableBills < ActiveRecord::Migration def self.up create_table :payable_bills do |t| t.column :user_id, :integer t.column :bill_id, :integer t.column :amount, :string t.column :paid_at, :datetime t.column :account_id, :integer t.column :receipt, :st...
Ruby
class CreateUsers < ActiveRecord::Migration def self.up create_table :users do |t| t.column :username, :string t.column :password, :string t.column :firstname, :string t.column :lastname, :string t.column :email, :string t.column :role, :string, :default => 'u...
Ruby
#!h:/ruby/bin/ruby require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT) # If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like: # "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impaired...
Ruby
#!h:/ruby/bin/ruby require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT) # If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like: # "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impaired...
Ruby
#!h:/ruby/bin/ruby # # You may specify the path to the FastCGI crash log (a log of unhandled # exceptions which forced the FastCGI instance to exit, great for debugging) # and the number of requests to process before running garbage collection. # # By default, the FastCGI crash log is RAILS_ROOT/log/fastcgi.crash.log #...
Ruby
#!h:/ruby/bin/ruby require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT) # If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like: # "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impaired...
Ruby
#!h:/ruby/bin/ruby require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT) # If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like: # "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impaired...
Ruby
#!h:/ruby/bin/ruby # # You may specify the path to the FastCGI crash log (a log of unhandled # exceptions which forced the FastCGI instance to exit, great for debugging) # and the number of requests to process before running garbage collection. # # By default, the FastCGI crash log is RAILS_ROOT/log/fastcgi.crash.log #...
Ruby
ENV["RAILS_ENV"] = "test" require File.expand_path(File.dirname(__FILE__) + "/../config/environment") require 'test_help' class Test::Unit::TestCase # Transactional fixtures accelerate your tests by wrapping each test method # in a transaction that's rolled back on completion. This ensures that the # test datab...
Ruby
# Helper methods defined here can be accessed in any controller or view in the application module GdataHelper # Transform a list of docs to a map by title def gdocs_by_title(docs) by_title = {} docs.values.each do |doc| by_title[doc.full_title] = doc end by_title end # Check if this is a...
Ruby
module SlugfilterHelper def walk_slug_tree(tree, options=nil, &block) options ||= {} depth = options[:depth] capture_haml do walk_slug_tree_children_helper(tree, nil, true, depth, options, &block) end end def walk_slug_tree_children_helper(tree, step=nil, odd=true, depth=nil, options=nil, ...
Ruby
module ApplicationHelper # Shorthand humanized text for admin pages def pat(sym) sym.to_s.humanize end # Default time display (localize at some point) def display_time(time) time.strftime("%Y-%m-%d %H:%M") rescue "-" end #:nocov: # FIXME: No obvious way to sanely test this. # Use instead of ...
Ruby
# Helper methods defined here can be accessed in any controller or view in the application module DocumentHelper # Transform a document URL for display purposes. # # Currently just transforms a Google Docs url to the editable document # version. def transform_document_url(url) gdoc_url = Gdoc.edit_url_fr...
Ruby
module BusinessObjectsHelper def related_objects(instance) if instance.is_a?(System) && instance.is_biz_process? instance.class.related_models("Process") else instance.class.related_models end end def arranged_related_objects(instance) end end
Ruby
module ImportHelper def trim_array(a) while !a.empty? && a.last.blank? a.pop end a end def validate_import_slug(object, object_name, expected_slug) raise ImportException.new("#{object_name} Code column does not exist") unless object["slug"] raise ImportException.new("#{object_name} Code...
Ruby
module AuthorizationHelper # Roles def access_control_roles [:user, :admin, :risk, :admin_risk, :no_access] end def allowed_objs(objects, ability) objects #Authorization::allowed_objects(ability, @current_user, objects) end def check_model_risk_authorization(models) if current_user.can_man...
Ruby
module MappingHelper end
Ruby
module FormHelper # Simple helper for repetitive form error spans def error_messages_inline(f, field_name) capture_haml do haml_tag :span, :class => 'help-inline' do f.object.errors[field_name].each do |error| haml_tag :span do haml_concat "#{error}" end en...
Ruby
require 'prawn_monkeypatch' module EvidenceHelper include ApplicationHelper # Capture evidence on Google Docs # # Convert the evidence document to PDF and watermark it with: # # * Acceptance date # * Who accepted the evidence # * Which system was the evidence attached to # # The PDF is then upload...
Ruby
module CyclesHelper def generate_default_title_for_cycle(program=nil) default_title = (program.nil? ? "" : program.title + " ") + "Audit" count = Cycle.where(Cycle.arel_table[:title].matches("%#{default_title}%")).count default_title += count > 0 ? " " + (count + 1).to_s : "" return "#{Date.today.ye...
Ruby
module DirectivesHelper # Set up a directive and relevant stats for display def directive_stats(directive) stats = {} stats[:sections_count] = Section.where(:directive_id => directive.id).count() stats[:sections_done_count] = Section.joins(:controls).where(:directive_id => directive.id).count(:distinct ...
Ruby
module DashboardHelper def init_quick_find @quick_find ||= {} @quick_find[:controls] ||= Control.all @quick_find[:systems] ||= System.where(:is_biz_process => false).all @quick_find[:biz_processes] ||= System.where(:is_biz_process => true).all end end
Ruby
module ManyHelper # Many to many AJAX page - show form. # # Example: # if request.put? # post_many2many(:left_class => Control, # :right_class => DocumentDescriptor, # :right_relation => :evidence_descriptors, # :right_ids => :evid...
Ruby
module ProgramsDashHelper end
Ruby
module ControlsHelper def control_params control_params = params[:control] || {} if control_params[:directive_id] # TODO: Validate the user has access to add controls to the directive control_params[:directive] = Directive.where(:id => control_params.delete(:directive_id)).first end %w(typ...
Ruby
module WelcomeHelper end
Ruby
class EmailValidator < ActiveModel::EachValidator EMAIL_RE = /([^@\s]+)(?:@((?:[-a-z0-9]+\.)+[a-z]{2,}))/i EMAILS_RE = /\A\s*#{EMAIL_RE}(?:\s*[, ]\s*#{EMAIL_RE})*\Z/i def validate_each(record, attribute, value) unless value =~ /^#{EMAIL_RE}$/ record.errors[attribute] << (options[:message] || "must be a...
Ruby
class MultiEmailValidator < ActiveModel::EachValidator EMAIL_RE = /([^@\s]+)(?:@((?:[-a-z0-9]+\.)+[a-z]{2,}))/i EMAILS_RE = /\A\s*#{EMAIL_RE}(?:\s*[, ]\s*#{EMAIL_RE})*\Z/i def validate_each(record, attribute, value) unless value =~ EMAILS_RE #/\A([^@\s]+)(?:@((?:[-a-z0-9]+\.)+[a-z]{2,}))?\z/i record.er...
Ruby
class UrlValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) valid = begin URI.parse(value).kind_of?(URI::HTTP) rescue URI::InvalidURIError false end unless valid record.errors[attribute] << (options[:message] || "is an invalid URL") end end e...
Ruby
class OrgGroup < ActiveRecord::Base include AuthoredModel include SluggedModel include SearchableModel include AuthorizedModel include RelatedModel include SanitizableAttributes include BusinessObjectModel include DatedModel attr_accessible :title, :slug, :description, :url, :version, :start_date, ...
Ruby
class Product < ActiveRecord::Base include AuthoredModel include SluggedModel include SearchableModel include AuthorizedModel include RelatedModel include SanitizableAttributes include BusinessObjectModel include DatedModel attr_accessible :title, :slug, :description, :url, :version, :type, :start_da...
Ruby
# A system to be audited class System < ActiveRecord::Base include CommonModel include SluggedModel include SearchableModel include AuthorizedModel include RelatedModel include SanitizableAttributes include DatedModel CATEGORY_TYPE_ID = 101 attr_accessible :title, :slug, :description, :url, :version...
Ruby
class Relationship < ActiveRecord::Base include AuthoredModel # Note: No accessible attributes - you pretty much # never want to allow changes to these without authorization. belongs_to :source, :polymorphic => true belongs_to :destination, :polymorphic => true belongs_to :relationship_type is_versione...
Ruby
# Program to Directive many to many class ProgramDirective < ActiveRecord::Base include CommonModel attr_accessible :program, :directive belongs_to :program belongs_to :directive is_versioned_ext #def self.by_system_control(system_id, control_id, cycle) # sc = SystemControl # .where(:system_id =...
Ruby
# A user session class UserSession < Authlogic::Session::Base extend ActiveModel::Naming authenticate_with Account cookie_key "_cms_cred" end
Ruby
# System to Control many to many class SystemControl < ActiveRecord::Base include CommonModel include StateModel attr_accessible :control, :system, :cycle belongs_to :control belongs_to :system belongs_to :cycle is_versioned_ext def self.by_system_control(system_id, control_id, cycle) sc = Syste...
Ruby
class PopulationSample < ActiveRecord::Base include CommonModel attr_accessible :response, :population_document, :population, :sample_worksheet_document, :samples, :sample_evidence_document belongs_to :response belongs_to :population_document, :class_name => "Document" belongs_to :sample_worksheet_document...
Ruby
# A Document # # Can either be linked by a URL or attached from Google Docs. class Document < ActiveRecord::Base include AuthoredModel include AuthorizedModel include RelatedModel include SanitizableAttributes VALID_SCHEMES = ['http', 'https', 'file'] attr_accessible :link, :title, :description, :type, :k...
Ruby
class Market < ActiveRecord::Base include AuthoredModel include SluggedModel include SearchableModel include AuthorizedModel include RelatedModel include SanitizableAttributes include BusinessObjectModel include DatedModel attr_accessible :title, :slug, :description, :url, :version, :start_date, :sto...
Ruby
class Response < ActiveRecord::Base include AuthoredModel include AuthorizedModel attr_accessible :request, :system, :status, :population, :samples, :population_document, :sample_worksheet_document, :sample_evidence_document belongs_to :request belongs_to :system has_one :population_sample, :dependen...
Ruby
require 'slugged_model' # A company / regulation control # class Control < ActiveRecord::Base include CommonModel include SluggedModel include SearchableModel include AuthorizedModel include RelatedModel include SanitizableAttributes include DatedModel CATEGORY_TYPE_ID = 100 CATEGORY_ASSERTION_TYPE_...
Ruby
# An Audit Cycle # # Used to group evidence for a particular audit of a program # start_at is the audit period start date. If missing, this is a continuous process. class Cycle < ActiveRecord::Base include CommonModel include AuthorizedModel include SanitizableAttributes include DatedModel attr_accessible :...
Ruby
# Control to Risk many to many class ControlRisk < ActiveRecord::Base include CommonModel attr_accessible :control, :risk belongs_to :control belongs_to :risk is_versioned_ext #def self.by_control_risk(risk_id, control_id, cycle) # sc = ControlRisk # .where(:risk_id => risk_id, # :co...
Ruby
class Risk < ActiveRecord::Base include AuthoredModel include SluggedModel include SearchableModel include AuthorizedModel include RelatedModel include SanitizableAttributes include DatedModel RATINGS = { 1 => "Minimal", 2 => "Moderate", 3 => "Significant", 4 => "Major", 5 => "Extre...
Ruby
class ControlSection < ActiveRecord::Base include AuthoredModel attr_accessible :control, :section belongs_to :control belongs_to :section is_versioned_ext end
Ruby
require 'slugged_model' # A control objective (inverse of risk) # # The slug of a Section has to have the slug of the parent as prefix. class Section < ActiveRecord::Base include CommonModel include SluggedModel include SearchableModel include AuthorizedModel include RelatedModel include SanitizableAttribu...
Ruby
class DataAsset < ActiveRecord::Base include AuthoredModel include SluggedModel include SearchableModel include AuthorizedModel include RelatedModel include SanitizableAttributes include BusinessObjectModel include DatedModel attr_accessible :title, :slug, :description, :url, :version, :start_date, :...
Ruby
# A link between systems class SystemSystem < ActiveRecord::Base include AuthoredModel attr_accessible :parent, :child, :type, :order belongs_to :parent, :foreign_key => 'parent_id', :class_name => 'System' belongs_to :child, :foreign_key => 'child_id', :class_name => 'System' is_versioned_ext ...
Ruby
class Request < ActiveRecord::Base include AuthoredModel include AuthorizedModel include SanitizableAttributes include DatedModel TYPES = { 1 => "Documentation", 2 => "Population Sample", 3 => "Interview" } STATUSES = [ "Draft", "Requested", "Responded", "Amended/Updated Requ...
Ruby
class PbcList < ActiveRecord::Base include AuthoredModel include AuthorizedModel include SanitizableAttributes attr_accessible :audit_cycle belongs_to :audit_cycle, :class_name => 'Cycle' has_many :requests, :dependent => :destroy has_many :control_assessments, :dependent => :destroy is_versioned_ex...
Ruby
# A Regulation, Policy, or Contract class Directive < ActiveRecord::Base include CommonModel include SluggedModel include SearchableModel include AuthorizedModel include RelatedModel include SanitizableAttributes include DatedModel KINDS = [ "Regulation", "Company Controls Policy", "Compan...
Ruby
class SectionSweeper < ActionController::Caching::Sweeper observe Section, ControlSection # TODO: monitor implementing_controls def after_create(section) expire_cache_for(section) end def after_update(section) expire_cache_for(section) end def after_destroy(section) expire_cache_for(sectio...
Ruby
# System to CO many to many relationship # `state` is the rolled up state from the System to Control association class SystemSection < ActiveRecord::Base include AuthoredModel include StateModel attr_accessible :section, :system belongs_to :section belongs_to :system is_versioned_ext end
Ruby
class RiskyAttribute < ActiveRecord::Base include AuthoredModel include SluggedModel include SearchableModel include AuthorizedModel include RelatedModel include SanitizableAttributes include DatedModel TYPE_STRINGS = %w(OrgGroup Product Facility Market Project DataAsset Process System) attr_accessi...
Ruby
class ControlAssessment < ActiveRecord::Base include AuthoredModel include AuthorizedModel include SanitizableAttributes has_many :requests, :dependent => :nullify belongs_to :pbc_list belongs_to :control attr_accessible :control_version, :external_tod, :external_toe, :internal_tod, :internal_toe, :not...
Ruby
class Category < ActiveRecord::Base include AuthoredModel attr_accessible :name, :scope_id, :parent, :required scope :ctype, lambda { |sid| where(:scope_id => sid) } acts_as_nested_set :scope => :scope_id, :dependent => :destroy has_many :categorizations, :dependent => :destroy has_many :controls, :throu...
Ruby
class ObjectPerson < ActiveRecord::Base include AuthoredModel include AuthorizedModel include RelatedModel include DatedModel attr_accessible :person, :personable, :notes, :start_date, :stop_date belongs_to :person belongs_to :personable, :polymorphic => true is_versioned_ext validates :role, :pre...
Ruby
require 'authorization' # class to manage user accounts on CMS. Note that this class is different # than the Person class, because not all people responsible for compliance will # have an account. class Account < ActiveRecord::Base include AuthoredModel attr_accessor :password, :password_confirmation attr_acc...
Ruby
# A Person # # Normally an owner or otherwise responsbile for an audit function. class Person < ActiveRecord::Base include AuthoredModel include AuthorizedModel include RelatedModel attr_accessible :email, :name, :company, :language has_one :account has_many :object_people, :dependent => :destroy belo...
Ruby
class ControlSweeper < ActionController::Caching::Sweeper observe Control def after_create(control) expire_cache_for(control) end def after_update(control) expire_cache_for(control) end def after_destroy(control) expire_cache_for(control) end private def expire_cache_for(control) #...
Ruby
class Project < ActiveRecord::Base include AuthoredModel include SluggedModel include SearchableModel include AuthorizedModel include RelatedModel include SanitizableAttributes include BusinessObjectModel include DatedModel attr_accessible :title, :slug, :description, :url, :version, :start_date, :st...
Ruby
class Facility < ActiveRecord::Base include AuthoredModel include SluggedModel include SearchableModel include AuthorizedModel include RelatedModel include SanitizableAttributes include BusinessObjectModel include DatedModel attr_accessible :title, :slug, :description, :url, :version, :start_date, :s...
Ruby
class Transaction < ActiveRecord::Base include CommonModel include SanitizableAttributes attr_accessible :system, :title, :description belongs_to :system is_versioned_ext sanitize_attributes :description def display_name title end end
Ruby
class ControlControl < ActiveRecord::Base include AuthoredModel attr_accessible :control, :implemented_control belongs_to :control belongs_to :implemented_control, :class_name => 'Control' is_versioned_ext end
Ruby
class Help < ActiveRecord::Base include AuthoredModel include SearchableModel include AuthorizedModel include SanitizableAttributes is_versioned_ext sanitize_attributes :content attr_accessible :title, :content, :slug end
Ruby