From a879297a0f7da5dcab992a8363d86fa835e9d10d Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Mon, 17 Jul 2023 12:53:29 +0200 Subject: [PATCH] WIP: Allow contributors for submissions --- app/models/concerns/contributor.rb | 9 +++++++++ app/models/concerns/contributor_creation.rb | 13 +++++++++++++ app/models/programming_group.rb | 5 +++++ app/models/submission.rb | 2 +- db/migrate/20230717103719_add_contributors.rb | 13 +++++++++++++ db/schema.rb | 14 ++++++++++---- 6 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 app/models/concerns/contributor.rb create mode 100644 app/models/concerns/contributor_creation.rb create mode 100644 app/models/programming_group.rb create mode 100644 db/migrate/20230717103719_add_contributors.rb diff --git a/app/models/concerns/contributor.rb b/app/models/concerns/contributor.rb new file mode 100644 index 000000000..624818eaf --- /dev/null +++ b/app/models/concerns/contributor.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +module Contributor + extend ActiveSupport::Concern + + included do + has_many :submissions, as: :contributor + end +end diff --git a/app/models/concerns/contributor_creation.rb b/app/models/concerns/contributor_creation.rb new file mode 100644 index 000000000..52d47b01d --- /dev/null +++ b/app/models/concerns/contributor_creation.rb @@ -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 diff --git a/app/models/programming_group.rb b/app/models/programming_group.rb new file mode 100644 index 000000000..1ce926562 --- /dev/null +++ b/app/models/programming_group.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class ProgrammingGroup < ApplicationRecord + include Contributor +end diff --git a/app/models/submission.rb b/app/models/submission.rb index 7af947cc2..20eaedc95 100644 --- a/app/models/submission.rb +++ b/app/models/submission.rb @@ -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 diff --git a/db/migrate/20230717103719_add_contributors.rb b/db/migrate/20230717103719_add_contributors.rb new file mode 100644 index 000000000..3923ff4b6 --- /dev/null +++ b/db/migrate/20230717103719_add_contributors.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class AddContributors < ActiveRecord::Migration[7.0] + def change + create_table :programming_groups, id: :uuid do |t| + t.string :name + t.timestamps + end + + rename_column :submissions, :user_id, :contributor_id + rename_column :submissions, :user_type, :contributor_type + end +end diff --git a/db/schema.rb b/db/schema.rb index a7acc27f0..9b6731bf3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_03_20_220012) do +ActiveRecord::Schema[7.0].define(version: 2023_07_17_103719) do # These are extensions that must be enabled in order to support this database enable_extension "pg_trgm" enable_extension "pgcrypto" @@ -350,6 +350,12 @@ t.index ["external_users_id"], name: "index_lti_parameters_on_external_users_id" end + create_table "programming_groups", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.string "name" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "proxy_exercises", id: :serial, force: :cascade do |t| t.string "title" t.string "description" @@ -453,15 +459,15 @@ create_table "submissions", id: :serial, force: :cascade do |t| t.integer "exercise_id" t.float "score" - t.integer "user_id" + t.integer "contributor_id" t.datetime "created_at" t.datetime "updated_at" t.string "cause" - t.string "user_type" + t.string "contributor_type" t.bigint "study_group_id" + t.index ["contributor_id"], name: "index_submissions_on_contributor_id" t.index ["exercise_id"], name: "index_submissions_on_exercise_id" t.index ["study_group_id"], name: "index_submissions_on_study_group_id" - t.index ["user_id"], name: "index_submissions_on_user_id" end create_table "subscriptions", id: :serial, force: :cascade do |t|