mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-09-20 23:16:15 +08:00
Merge branch 'ur-SCI-2952-SN-data-model-changes' into features/system-notifications
This commit is contained in:
commit
3e4cf7ae3c
10
app/models/system_notification.rb
Normal file
10
app/models/system_notification.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class SystemNotification < ApplicationRecord
|
||||
has_many :user_system_notifications
|
||||
has_many :users, through: :user_system_notifications
|
||||
|
||||
validates :title, :modal_title, :modal_body, :description,
|
||||
:source_created_at, :source_id, :last_time_changed_at,
|
||||
presence: true
|
||||
end
|
|
@ -209,6 +209,8 @@ class User < ApplicationRecord
|
|||
|
||||
has_many :user_notifications, inverse_of: :user
|
||||
has_many :notifications, through: :user_notifications
|
||||
has_many :user_system_notifications
|
||||
has_many :system_notifications, through: :user_system_notifications
|
||||
has_many :zip_exports, inverse_of: :user, dependent: :destroy
|
||||
has_many :datatables_teams, class_name: '::Views::Datatables::DatatablesTeam'
|
||||
has_many :view_states, dependent: :destroy
|
||||
|
|
6
app/models/user_system_notification.rb
Normal file
6
app/models/user_system_notification.rb
Normal file
|
@ -0,0 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class UserSystemNotification < ApplicationRecord
|
||||
belongs_to :user
|
||||
belongs_to :system_notification
|
||||
end
|
|
@ -12,9 +12,10 @@ class Extends
|
|||
|
||||
# Extends enum types. Should not be freezed, as modules might append to this.
|
||||
# !!!Check all addons for the correct order!!!
|
||||
# DEPRECATED 'system_message' in (SCI-2952, kept b/c of integer enums)
|
||||
NOTIFICATIONS_TYPES = { assignment: 0,
|
||||
recent_changes: 1,
|
||||
system_message: 2,
|
||||
system_message: 2, # DEPRECATED
|
||||
deliver: 5 }
|
||||
|
||||
TASKS_STATES = { uncompleted: 0,
|
||||
|
|
18
db/migrate/20190125122852_create_system_notifications.rb
Normal file
18
db/migrate/20190125122852_create_system_notifications.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class CreateSystemNotifications < ActiveRecord::Migration[5.1]
|
||||
def change
|
||||
create_table :system_notifications do |t|
|
||||
t.string :title
|
||||
t.text :description
|
||||
t.string :modal_title
|
||||
t.text :modal_body
|
||||
t.boolean :show_on_login, default: false
|
||||
t.datetime :source_created_at, index: true
|
||||
t.bigint :source_id, index: true, unique: true
|
||||
t.datetime :last_time_changed_at, index: true, null: false
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,14 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class CreateUserSystemNotifications < ActiveRecord::Migration[5.1]
|
||||
def change
|
||||
create_table :user_system_notifications do |t|
|
||||
t.references :user, foreign_key: true
|
||||
t.references :system_notification, foreign_key: true
|
||||
t.datetime :seen_at, index: true
|
||||
t.datetime :read_at, index: true
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
33
db/schema.rb
33
db/schema.rb
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20190117155006) do
|
||||
ActiveRecord::Schema.define(version: 20190125123107) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
@ -660,6 +660,22 @@ ActiveRecord::Schema.define(version: 20190117155006) do
|
|||
t.index ["user_id"], name: "index_steps_on_user_id"
|
||||
end
|
||||
|
||||
create_table "system_notifications", force: :cascade do |t|
|
||||
t.string "title"
|
||||
t.text "description"
|
||||
t.string "modal_title"
|
||||
t.text "modal_body"
|
||||
t.boolean "show_on_login", default: false
|
||||
t.datetime "source_created_at"
|
||||
t.bigint "source_id"
|
||||
t.datetime "last_time_changed_at", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["last_time_changed_at"], name: "index_system_notifications_on_last_time_changed_at"
|
||||
t.index ["source_created_at"], name: "index_system_notifications_on_source_created_at"
|
||||
t.index ["source_id"], name: "index_system_notifications_on_source_id"
|
||||
end
|
||||
|
||||
create_table "tables", force: :cascade do |t|
|
||||
t.binary "contents", null: false
|
||||
t.datetime "created_at", null: false
|
||||
|
@ -781,6 +797,19 @@ ActiveRecord::Schema.define(version: 20190117155006) do
|
|||
t.index ["user_id"], name: "index_user_projects_on_user_id"
|
||||
end
|
||||
|
||||
create_table "user_system_notifications", force: :cascade do |t|
|
||||
t.bigint "user_id"
|
||||
t.bigint "system_notification_id"
|
||||
t.datetime "seen_at"
|
||||
t.datetime "read_at"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["read_at"], name: "index_user_system_notifications_on_read_at"
|
||||
t.index ["seen_at"], name: "index_user_system_notifications_on_seen_at"
|
||||
t.index ["system_notification_id"], name: "index_user_system_notifications_on_system_notification_id"
|
||||
t.index ["user_id"], name: "index_user_system_notifications_on_user_id"
|
||||
end
|
||||
|
||||
create_table "user_teams", force: :cascade do |t|
|
||||
t.integer "role", default: 1, null: false
|
||||
t.bigint "user_id", null: false
|
||||
|
@ -1012,6 +1041,8 @@ ActiveRecord::Schema.define(version: 20190117155006) do
|
|||
add_foreign_key "user_projects", "projects"
|
||||
add_foreign_key "user_projects", "users"
|
||||
add_foreign_key "user_projects", "users", column: "assigned_by_id"
|
||||
add_foreign_key "user_system_notifications", "system_notifications"
|
||||
add_foreign_key "user_system_notifications", "users"
|
||||
add_foreign_key "user_teams", "teams"
|
||||
add_foreign_key "user_teams", "users"
|
||||
add_foreign_key "user_teams", "users", column: "assigned_by_id"
|
||||
|
|
16
spec/factories/system_notifications.rb
Normal file
16
spec/factories/system_notifications.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
FactoryBot.define do
|
||||
factory :system_notification do
|
||||
sequence(:title) { |n| "System notification #{n}" }
|
||||
description { Faker::ChuckNorris.fact }
|
||||
modal_title { Faker::Name.first_name }
|
||||
modal_body { Faker::Lorem.paragraphs(4).map { |pr| "<p>#{pr}</p>" }.join }
|
||||
source_created_at { Faker::Time.between(3.days.ago, Date.today) }
|
||||
source_id { Faker::Number.between(1, 1000) }
|
||||
last_time_changed_at { Time.now }
|
||||
trait :show_on_login do
|
||||
show_on_login { true }
|
||||
end
|
||||
end
|
||||
end
|
18
spec/factories/user_system_notifications.rb
Normal file
18
spec/factories/user_system_notifications.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
FactoryBot.define do
|
||||
factory :user_system_notification do
|
||||
user
|
||||
system_notification
|
||||
trait :seen do
|
||||
seen { Faker::Time.between(3.days.ago, Date.today) }
|
||||
end
|
||||
trait :read do
|
||||
read { Faker::Time.between(3.days.ago, Date.today) }
|
||||
end
|
||||
trait :seen_and_read do
|
||||
seen { Faker::Time.between(3.days.ago, Date.today) }
|
||||
read { Faker::Time.between(seen, Date.today) }
|
||||
end
|
||||
end
|
||||
end
|
45
spec/models/system_notification_spec.rb
Normal file
45
spec/models/system_notification_spec.rb
Normal file
|
@ -0,0 +1,45 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe SystemNotification do
|
||||
subject(:system_notification) { build :system_notification }
|
||||
|
||||
it 'is valid' do
|
||||
expect(system_notification).to be_valid
|
||||
end
|
||||
|
||||
describe 'Validations' do
|
||||
describe '#title' do
|
||||
it { is_expected.to validate_presence_of(:title) }
|
||||
end
|
||||
|
||||
describe '#modal_title' do
|
||||
it { is_expected.to validate_presence_of(:modal_title) }
|
||||
end
|
||||
|
||||
describe '#modal_body' do
|
||||
it { is_expected.to validate_presence_of(:modal_body) }
|
||||
end
|
||||
|
||||
describe '#description' do
|
||||
it { is_expected.to validate_presence_of(:description) }
|
||||
end
|
||||
|
||||
describe '#source_id' do
|
||||
it { is_expected.to validate_presence_of(:source_id) }
|
||||
end
|
||||
|
||||
describe '#source_created_at' do
|
||||
it { is_expected.to validate_presence_of(:source_created_at) }
|
||||
end
|
||||
|
||||
describe '#last_time_changed_at' do
|
||||
it { is_expected.to validate_presence_of(:last_time_changed_at) }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Associations' do
|
||||
it { is_expected.to have_many(:users) }
|
||||
end
|
||||
end
|
|
@ -258,4 +258,8 @@ describe User, type: :model do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Associations' do
|
||||
it { is_expected.to have_many(:system_notifications) }
|
||||
end
|
||||
end
|
||||
|
|
16
spec/models/user_system_notification_spec.rb
Normal file
16
spec/models/user_system_notification_spec.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe UserSystemNotification do
|
||||
subject(:user_system_notification) { build :user_system_notification }
|
||||
|
||||
it 'is valid' do
|
||||
expect(user_system_notification).to be_valid
|
||||
end
|
||||
|
||||
describe 'Associations' do
|
||||
it { is_expected.to belong_to(:user) }
|
||||
it { is_expected.to belong_to(:system_notification) }
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue