-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
124 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,20 @@ | ||
require_relative 'doorkeeper' | ||
|
||
# User | ||
OSU::AccessPolicy.register(User, UserAccessPolicy) | ||
OSU::AccessPolicy.register(Delegation, DelegationAccessPolicy) | ||
Rails.application.config.after_initialize do | ||
# User | ||
OSU::AccessPolicy.register(User, UserAccessPolicy) | ||
OSU::AccessPolicy.register(Delegation, DelegationAccessPolicy) | ||
|
||
# API | ||
OSU::AccessPolicy.register(Exercise, ExerciseAccessPolicy) | ||
OSU::AccessPolicy.register(VocabTerm, VocabTermAccessPolicy) | ||
OSU::AccessPolicy.register(Attachment, AttachmentAccessPolicy) | ||
OSU::AccessPolicy.register(List, ListAccessPolicy) | ||
OSU::AccessPolicy.register(ListPublicationGroup, ListPublicationGroupAccessPolicy) | ||
OSU::AccessPolicy.register(Publication, PublicationAccessPolicy) | ||
OSU::AccessPolicy.register(CommunitySolution, CommunitySolutionAccessPolicy) | ||
OSU::AccessPolicy.register(OpenStax::Content::Book, BookAccessPolicy) | ||
# API | ||
OSU::AccessPolicy.register(Exercise, ExerciseAccessPolicy) | ||
OSU::AccessPolicy.register(VocabTerm, VocabTermAccessPolicy) | ||
OSU::AccessPolicy.register(Attachment, AttachmentAccessPolicy) | ||
OSU::AccessPolicy.register(List, ListAccessPolicy) | ||
OSU::AccessPolicy.register(ListPublicationGroup, ListPublicationGroupAccessPolicy) | ||
OSU::AccessPolicy.register(Publication, PublicationAccessPolicy) | ||
OSU::AccessPolicy.register(CommunitySolution, CommunitySolutionAccessPolicy) | ||
OSU::AccessPolicy.register(OpenStax::Content::Book, BookAccessPolicy) | ||
|
||
# Doorkeeper | ||
OSU::AccessPolicy.register(Doorkeeper::Application, Doorkeeper::ApplicationAccessPolicy) | ||
# Doorkeeper | ||
OSU::AccessPolicy.register(Doorkeeper::Application, Doorkeeper::ApplicationAccessPolicy) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,22 @@ | ||
ActionController::Base.class_exec do | ||
protect_from_forgery | ||
ActiveSupport.on_load(:action_controller_base) do | ||
ActionController::Base.class_exec do | ||
protect_from_forgery | ||
|
||
layout "layouts/application_body_only" | ||
layout "layouts/application_body_only" | ||
|
||
helper ApplicationHelper | ||
helper OpenStax::Utilities::OsuHelper | ||
helper ApplicationHelper | ||
helper OpenStax::Utilities::OsuHelper | ||
|
||
helper_method :current_account | ||
helper_method :current_account | ||
|
||
protected | ||
protected | ||
|
||
def current_administrator | ||
Administrator.where(:account_id => current_account.id).first | ||
end | ||
def current_administrator | ||
Administrator.where(:account_id => current_account.id).first | ||
end | ||
|
||
def authenticate_administrator! | ||
current_administrator || raise(SecurityTransgression) | ||
def authenticate_administrator! | ||
current_administrator || raise(SecurityTransgression) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,23 @@ | ||
require_relative 'doorkeeper' | ||
|
||
Doorkeeper::Application.class_exec do | ||
belongs_to :owner, polymorphic: true | ||
Rails.application.config.to_prepare do | ||
Doorkeeper::Application.class_exec do | ||
belongs_to :owner, polymorphic: true | ||
|
||
def is_human? | ||
false | ||
end | ||
def is_human? | ||
false | ||
end | ||
|
||
def is_application? | ||
true | ||
end | ||
def is_application? | ||
true | ||
end | ||
|
||
def is_anonymous? | ||
false | ||
end | ||
def is_anonymous? | ||
false | ||
end | ||
|
||
def is_administrator? | ||
false | ||
def is_administrator? | ||
false | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,52 @@ | ||
ActiveRecord::Base.class_exec do | ||
ActiveSupport.on_load(:active_record) do | ||
ActiveRecord::Base.class_exec do | ||
def association_attributes(associations = [], | ||
slice: nil, | ||
except: nil, | ||
exclude_foreign_keys: false, | ||
transform_arrays_into_sets: false) | ||
attrs = attributes | ||
attrs = attrs.slice(*slice) unless slice.blank? | ||
attrs = attrs.except(*except) unless except.blank? | ||
|
||
def association_attributes(associations = [], | ||
slice: nil, | ||
except: nil, | ||
exclude_foreign_keys: false, | ||
transform_arrays_into_sets: false) | ||
attrs = attributes | ||
attrs = attrs.slice(*slice) unless slice.blank? | ||
attrs = attrs.except(*except) unless except.blank? | ||
|
||
if exclude_foreign_keys | ||
foreign_keys = self.class.reflect_on_all_associations(:belongs_to).map do |ar| | ||
ar.foreign_key | ||
if exclude_foreign_keys | ||
foreign_keys = self.class.reflect_on_all_associations(:belongs_to).map do |ar| | ||
ar.foreign_key | ||
end | ||
attrs = attrs.except(*foreign_keys) | ||
end | ||
attrs = attrs.except(*foreign_keys) | ||
end | ||
|
||
[associations].flatten.compact.each_with_object(attrs) do |association, hash| | ||
association = [association].flatten.compact unless association.respond_to?(:each) | ||
[associations].flatten.compact.each_with_object(attrs) do |association, hash| | ||
association = [association].flatten.compact unless association.respond_to?(:each) | ||
|
||
association.each do |name, subtree| | ||
objects = send(name) | ||
next if objects.nil? | ||
|
||
association.each do |name, subtree| | ||
objects = send(name) | ||
next if objects.nil? | ||
if objects.respond_to?(:collect) | ||
hash[name.to_s] = objects.collect do |object| | ||
object.association_attributes( | ||
subtree, | ||
slice: slice, | ||
except: except, | ||
exclude_foreign_keys: exclude_foreign_keys, | ||
transform_arrays_into_sets: transform_arrays_into_sets | ||
) | ||
end | ||
|
||
if objects.respond_to?(:collect) | ||
hash[name.to_s] = objects.collect do |object| | ||
object.association_attributes( | ||
hash[name.to_s] = Set.new(hash[name.to_s]) if transform_arrays_into_sets | ||
else | ||
hash[name.to_s] = objects.association_attributes( | ||
subtree, | ||
slice: slice, | ||
except: except, | ||
exclude_foreign_keys: exclude_foreign_keys, | ||
transform_arrays_into_sets: transform_arrays_into_sets | ||
) | ||
end | ||
|
||
hash[name.to_s] = Set.new(hash[name.to_s]) if transform_arrays_into_sets | ||
else | ||
hash[name.to_s] = objects.association_attributes( | ||
subtree, | ||
slice: slice, | ||
except: except, | ||
exclude_foreign_keys: exclude_foreign_keys, | ||
transform_arrays_into_sets: transform_arrays_into_sets | ||
) | ||
end | ||
end | ||
end | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,19 @@ | ||
Raven.configure do |config| | ||
sentry_secrets = Rails.application.secrets.sentry | ||
Sentry.init do |config| | ||
secrets = Rails.application.secrets | ||
|
||
config.dsn = sentry_secrets[:dsn] | ||
config.current_environment = Rails.application.secrets.environment_name | ||
config.dsn = secrets.sentry[:dsn] | ||
config.environment = secrets.environment_name | ||
config.release = secrets.release_version | ||
|
||
config.breadcrumbs_logger = %i[sentry_logger active_support_logger http_logger] | ||
|
||
# Send POST data and cookies to Sentry | ||
config.processors -= [ Raven::Processor::Cookies, Raven::Processor::PostData ] | ||
config.release = sentry_secrets[:release] | ||
config.send_default_pii = true | ||
|
||
# Don't send transaction data to Sentry | ||
config.traces_sample_rate = 0.0 | ||
|
||
# Don't log "Sentry is ready" message | ||
config.silence_ready = true | ||
# Reduce the amount of logging from Sentry | ||
config.logger = Sentry::Logger.new(STDOUT) | ||
config.logger.level = Logger::ERROR | ||
end if Rails.env.production? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters