Skip to content

Commit

Permalink
Add Contributor and ContributorCreation
Browse files Browse the repository at this point in the history
  • Loading branch information
kiragrammel committed Jul 27, 2023
1 parent 5940934 commit 6cbc1f9
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
9 changes: 9 additions & 0 deletions app/models/concerns/contributor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

module Contributor
extend ActiveSupport::Concern

included do
has_many :submissions, as: :contributor
end
end
13 changes: 13 additions & 0 deletions app/models/concerns/contributor_creation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module ContributorCreation
extend ActiveSupport::Concern
include Contributor

included do
belongs_to :contributor, polymorphic: true
alias_method :user, :contributor
alias_method :author, :user
alias_method :creator, :user
end
end
2 changes: 2 additions & 0 deletions app/models/programming_group.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

class ProgrammingGroup < ApplicationRecord
include Contributor

has_many :programming_group_memberships, dependent: :destroy
has_many :external_users, through: :programming_group_memberships, source_type: 'ExternalUser', source: :user
has_many :internal_users, through: :programming_group_memberships, source_type: 'InternalUser', source: :user
Expand Down
6 changes: 3 additions & 3 deletions app/models/submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Submission < ApplicationRecord
include Context
include Creation
include ContributorCreation
include ActionCableHelper

CAUSES = %w[assess download file render run save submit test autosave requestComments remoteAssess
Expand All @@ -26,8 +26,8 @@ class Submission < ApplicationRecord
}, foreign_key: :contributor_id, class_name: 'InternalUser', optional: true

belongs_to :programming_groups, lambda {
where(submissions: {contributor_type: 'ProgrammingGroup'}).includes(:submissions)
}, foreign_key: :contributor_id, class_name: 'ProgrammingGroup', optional: true
where(submissions: {contributor_type: 'ProgrammingGroup'}).includes(:submissions)
}, foreign_key: :contributor_id, class_name: 'ProgrammingGroup', optional: true

delegate :execution_environment, to: :exercise

Expand Down

0 comments on commit 6cbc1f9

Please sign in to comment.