chore: init commit

in worker.../repo/GITFOLDER.zip is the .git folder.
This commit is contained in:
2026-08-11 14:44:09 -04:00
parent 0012380fd3
commit 392781f7aa
781 changed files with 65944 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
# frozen_string_literal: true
class ApplicationPolicy
attr_reader :user, :record
def initialize(user, record)
@user = user
@record = record
end
def index?
false
end
def show?
false
end
def create?
false
end
def new?
create?
end
def update?
false
end
def edit?
update?
end
def destroy?
false
end
def admin_required?
user&.admin?
end
def teacher_required?
user&.teacher?
end
def student_required?
user&.student?
end
def teacher_or_admin_required?
admin_required? || teacher_required?
end
class Scope
def initialize(user, scope)
@user = user
@scope = scope
end
def resolve
raise NoMethodError, "You must define #resolve in #{self.class}"
end
private
attr_reader :user, :scope
end
end

View File

@@ -0,0 +1,58 @@
# frozen_string_literal: true
class ClassroomPolicy < ApplicationPolicy
def index?
user&.teacher_or_admin?
end
def show?
user&.teacher_or_admin?
end
def new?
user.admin?
end
def edit?
user.admin?
end
def create?
user.admin?
end
def update?
user.admin?
end
def toggle_archive?
user.admin?
end
def toggle_trading?
return true if user.admin?
return false unless user.teacher?
user.classroom_ids.include?(record.id)
end
# there has to be a scope class associated here
class Scope
attr_reader :user, :scope
def initialize(user, scope)
@user = user
@scope = scope
end
def resolve
if user.admin?
scope.all
elsif user.teacher?
scope.active.joins(:teacher_classrooms).where(teacher_classrooms: { teacher_id: user.id })
else
[]
end
end
end
end

View File

@@ -0,0 +1,21 @@
# frozen_string_literal: true
class GradeBookPolicy < ApplicationPolicy
def update?
user_is_teacher_of_classroom? || user.admin?
end
def show?
user_is_teacher_of_classroom? || user.admin?
end
def finalize?
user.admin?
end
private
def user_is_teacher_of_classroom?
user.teacher? && record.classroom.teachers.include?(user)
end
end

View File

@@ -0,0 +1,35 @@
# frozen_string_literal: true
class OrderPolicy < ApplicationPolicy
def index?
user.present?
end
def create?
user.portfolio == record.portfolio
end
def update?
user.portfolio == record.portfolio
end
def cancel?
user.portfolio == record.portfolio
end
class Scope < ApplicationPolicy::Scope
def resolve
return scope.none unless user
if user.admin?
scope.all
elsif user.teacher?
scope.for_teacher(user)
elsif user.student?
scope.for_student(user)
else
scope.none
end
end
end
end

View File

@@ -0,0 +1,18 @@
# frozen_string_literal: true
class PortfolioPolicy < ApplicationPolicy
def show?
return false if user.blank?
return true if user.admin?
return true if record.user_id == user.id
user.teacher? && teacher_access?
end
private
def teacher_access?
teacher_ids = record.user&.classroom&.teacher_ids
teacher_ids&.include?(user.id)
end
end

View File

@@ -0,0 +1,57 @@
# frozen_string_literal: true
class StockPolicy < ApplicationPolicy
# Show trading-related links (buy/sell/trade) when the user is a student
# and has a portfolio (safeguard for nil portfolio) and the stock is not archived
# (or if archived, user is holding it) and trading is enabled for their classroom.
def show_trading_link?
show_holdings? && (!record.archived? || user.holding?(record)) && user.classroom&.trading_enabled?
end
# Show holdings column / counts for students with a portfolio
def show_holdings?
user.present? && user.student? && portfolio_present?
end
def index?
user.present?
end
def show?
user.present?
end
def new?
create?
end
def create?
admin_required?
end
def edit?
update?
end
def update?
admin_required?
end
def destroy?
admin_required?
end
private
def portfolio_present?
# Student must actually have a persisted portfolio. Nil-safe, avoids relying on cached association state.
user&.portfolio&.persisted?
end
# Scope to control which stocks are visible in listings
class Scope < ApplicationPolicy::Scope
def resolve
scope.all
end
end
end