Deconflate organization/conference IDs in role versions
Resolves failing test spec/features/versions_spec.rb:321
Partially reverts 81853d1ef9
This commit is contained in:
parent
150bbef61f
commit
3f6a9e91bd
6 changed files with 69 additions and 37 deletions
|
|
@ -5,7 +5,9 @@ class Role < ApplicationRecord
|
||||||
has_many :users_roles
|
has_many :users_roles
|
||||||
has_many :users, through: :users_roles
|
has_many :users, through: :users_roles
|
||||||
|
|
||||||
has_paper_trail on: [:create, :update], only: [:name, :description], meta: { conference_id: :resource_id }
|
has_paper_trail on: [:create, :update],
|
||||||
|
only: [:name, :description],
|
||||||
|
meta: { conference_id: :conference_id, organization_id: :organization_id }
|
||||||
|
|
||||||
before_destroy :cancel
|
before_destroy :cancel
|
||||||
scopify
|
scopify
|
||||||
|
|
@ -14,6 +16,14 @@ class Role < ApplicationRecord
|
||||||
|
|
||||||
validates :name, uniqueness: { scope: :resource }
|
validates :name, uniqueness: { scope: :resource }
|
||||||
|
|
||||||
|
def conference_id
|
||||||
|
resource_type == 'Conference' ? resource_id : nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def organization_id
|
||||||
|
resource_type == 'Organization' ? resource_id : nil
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# Needed to ensure that removing all user from role doesn't remove role.
|
# Needed to ensure that removing all user from role doesn't remove role.
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,8 @@ class UsersRole < ApplicationRecord
|
||||||
belongs_to :role
|
belongs_to :role
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
|
|
||||||
has_paper_trail on: [:create, :destroy], meta: { conference_id: :conference_id }
|
delegate :conference_id, :organization_id, to: :role
|
||||||
|
|
||||||
private
|
has_paper_trail on: [:create, :destroy],
|
||||||
|
meta: { conference_id: :conference_id, organization_id: :organization_id }
|
||||||
def conference_id
|
|
||||||
role.resource_id
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -15,18 +15,14 @@
|
||||||
- role = current_or_last_object_state('Role', object.role_id)
|
- role = current_or_last_object_state('Role', object.role_id)
|
||||||
- role_name = role.try(:name) || PaperTrail::Version.where(item_type: 'Role', item_id: object.role_id).last.changeset[:name].second
|
- role_name = role.try(:name) || PaperTrail::Version.where(item_type: 'Role', item_id: object.role_id).last.changeset[:name].second
|
||||||
role
|
role
|
||||||
- if role_name == 'organization_admin'
|
- if version.conference_id
|
||||||
- if Organization.find_by(id: version.conference_id)
|
|
||||||
-# organization_admin belongs to organization and not conferences
|
|
||||||
- organization = Organization.find_by(id: version.conference_id)
|
|
||||||
= link_if_alive version, role_name,
|
|
||||||
admins_admin_organization_path(organization), organization
|
|
||||||
- else
|
|
||||||
(Deleted Organization)
|
|
||||||
- else
|
|
||||||
- conference = Conference.find_by(id: version.conference_id)
|
- conference = Conference.find_by(id: version.conference_id)
|
||||||
- conference_short_title = conference.try(:short_title) || current_or_last_object_state('Conference', version.conference_id).try(:short_title) || ' '
|
- conference_short_title = conference.try(:short_title) || current_or_last_object_state('Conference', version.conference_id).try(:short_title) || ' '
|
||||||
= link_if_alive version, role.try(:name), admin_conference_role_path(conference_short_title,role.try(:name) || ' '), conference
|
= link_if_alive version, role.try(:name), admin_conference_role_path(conference_short_title,role.try(:name) || ' '), conference
|
||||||
|
- elsif version.organization_id
|
||||||
|
- organization = Organization.find(version.organization_id)
|
||||||
|
= link_if_alive version, role_name,
|
||||||
|
admins_admin_organization_path(organization), organization
|
||||||
|
|
||||||
= version.event == 'create' ? 'to' : 'from'
|
= version.event == 'create' ? 'to' : 'from'
|
||||||
user
|
user
|
||||||
|
|
@ -133,19 +129,15 @@
|
||||||
- when 'Role'
|
- when 'Role'
|
||||||
role
|
role
|
||||||
- role_name = object.try(:name) || PaperTrail::Version.where(item_type: 'Role', item_id: version.item_id).last.changeset[:name].second
|
- role_name = object.try(:name) || PaperTrail::Version.where(item_type: 'Role', item_id: version.item_id).last.changeset[:name].second
|
||||||
- if role_name == 'organization_admin'
|
- if version.conference_id
|
||||||
- if Organization.find_by(id: version.conference_id)
|
|
||||||
-# organization_admin belongs to organization and not conferences
|
|
||||||
- organization = Organization.find_by(id: version.conference_id)
|
|
||||||
= link_if_alive version, role_name,
|
|
||||||
admins_admin_organization_path(organization), organization
|
|
||||||
- else
|
|
||||||
(Role Deleted)
|
|
||||||
- else
|
|
||||||
- conference = Conference.find_by(id: version.conference_id)
|
- conference = Conference.find_by(id: version.conference_id)
|
||||||
- conference_short_title = conference.try(:short_title) || current_or_last_object_state('Conference', version.conference_id).try(:short_title) || ' '
|
- conference_short_title = conference.try(:short_title) || current_or_last_object_state('Conference', version.conference_id).try(:short_title) || ' '
|
||||||
= link_if_alive version, role_name,
|
= link_if_alive version, role_name,
|
||||||
admin_conference_role_path(conference_short_title, role_name), conference
|
admin_conference_role_path(conference_short_title, role_name), conference
|
||||||
|
- elsif version.organization_id
|
||||||
|
- organization = Organization.find(version.organization_id)
|
||||||
|
= link_if_alive version, role_name,
|
||||||
|
admins_admin_organization_path(organization), organization
|
||||||
|
|
||||||
- when 'Venue'
|
- when 'Venue'
|
||||||
venue
|
venue
|
||||||
|
|
@ -203,20 +195,16 @@
|
||||||
= link_to_user(version.item_id)
|
= link_to_user(version.item_id)
|
||||||
|
|
||||||
- unless %w(Conference Subscription Registration User Organization).include?(version.item_type)
|
- unless %w(Conference Subscription Registration User Organization).include?(version.item_type)
|
||||||
- if (version.item_type == 'Role' && role_name == 'organization_admin') || (version.item_type == 'UsersRole' && role_name == 'organization_admin')
|
- if version.item_type == 'Commercial'
|
||||||
in organization
|
|
||||||
- if Organization.find_by(id: version.conference_id)
|
|
||||||
-# organization_admin belongs to organization and not conferences
|
|
||||||
- organization = Organization.find_by(id: version.conference_id)
|
|
||||||
= link_to_organization(version.conference_id)
|
|
||||||
- else
|
|
||||||
(Organization Deleted)
|
|
||||||
- elsif version.item_type == 'Commercial'
|
|
||||||
- commercial = current_or_last_object_state(version.item_type, version.item_id)
|
- commercial = current_or_last_object_state(version.item_type, version.item_id)
|
||||||
- commercialable = current_or_last_object_state(commercial.commercialable_type, commercial.commercialable_id)
|
- commercialable = current_or_last_object_state(commercial.commercialable_type, commercial.commercialable_id)
|
||||||
- unless commercial.commercialable_type == 'Conference'
|
- unless commercial.commercialable_type == 'Conference'
|
||||||
in conference
|
in conference
|
||||||
= link_to_conference(version.conference_id)
|
= link_to_conference(version.conference_id)
|
||||||
|
- elsif version.organization_id
|
||||||
|
- organization = Organization.find(version.organization_id)
|
||||||
|
in organization
|
||||||
|
= link_to_organization(version.organization_id)
|
||||||
- else
|
- else
|
||||||
in conference
|
in conference
|
||||||
= link_to_conference(version.conference_id)
|
= link_to_conference(version.conference_id)
|
||||||
|
|
|
||||||
37
db/migrate/20200331214534_add_organization_to_versions.rb
Normal file
37
db/migrate/20200331214534_add_organization_to_versions.rb
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
class AddOrganizationToVersions < ActiveRecord::Migration[5.2]
|
||||||
|
def up
|
||||||
|
add_reference :versions, :organization
|
||||||
|
deconflate
|
||||||
|
PaperTrail::Version.reset_column_information
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
conflate
|
||||||
|
remove_reference :versions, :organization
|
||||||
|
PaperTrail::Version.reset_column_information
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def conflate
|
||||||
|
say 'conflate'
|
||||||
|
|
||||||
|
PaperTrail::Version.where.not(organization_id: nil).each do |version|
|
||||||
|
version.update conference_id: version.organization_id
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def deconflate
|
||||||
|
say 'deconflate'
|
||||||
|
|
||||||
|
PaperTrail::Version.where.not(conference_id: nil).where(item_type: %(Role UsersRole)).each do |version|
|
||||||
|
id = version.conference_id
|
||||||
|
|
||||||
|
if Organization.exists?(id)
|
||||||
|
raise "version #{version.id} conflates organization #{id} with conference #{id}" if Conference.exists?(id)
|
||||||
|
|
||||||
|
version.update conference_id: nil, organization_id: id
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20181229233811) do
|
ActiveRecord::Schema.define(version: 2020_03_31_214534) do
|
||||||
|
|
||||||
create_table "answers", force: :cascade do |t|
|
create_table "answers", force: :cascade do |t|
|
||||||
t.string "title"
|
t.string "title"
|
||||||
|
|
@ -637,7 +637,9 @@ ActiveRecord::Schema.define(version: 20181229233811) do
|
||||||
t.text "object_changes"
|
t.text "object_changes"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.integer "conference_id"
|
t.integer "conference_id"
|
||||||
|
t.integer "organization_id"
|
||||||
t.index ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id"
|
t.index ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id"
|
||||||
|
t.index ["organization_id"], name: "index_versions_on_organization_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "votes", force: :cascade do |t|
|
create_table "votes", force: :cascade do |t|
|
||||||
|
|
|
||||||
|
|
@ -331,12 +331,10 @@ feature 'Version' do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'is recorded to history when user is added' do
|
it 'is recorded to history when user is added' do
|
||||||
skip('fails since paper_trail 12.2.0')
|
|
||||||
expect(page).to have_text(/added role organization_admin with ID \d+ to user #{user.name} in organization #{conference.organization.name}/)
|
expect(page).to have_text(/added role organization_admin with ID \d+ to user #{user.name} in organization #{conference.organization.name}/)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'is recorded to history when user is removed' do
|
it 'is recorded to history when user is removed' do
|
||||||
skip('fails since paper_trail 12.2.0')
|
|
||||||
expect(page).to have_text(/removed role organization_admin with ID \d+ from user #{user.name} in organization #{conference.organization.name}/)
|
expect(page).to have_text(/removed role organization_admin with ID \d+ from user #{user.name} in organization #{conference.organization.name}/)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue