Skip to content

Commit

Permalink
Removed the locking of concepts and collections when creating/editing…
Browse files Browse the repository at this point in the history
… a new version.
  • Loading branch information
pschijven committed Oct 12, 2023
1 parent 37eacbf commit 01bea39
Show file tree
Hide file tree
Showing 25 changed files with 43 additions and 211 deletions.
46 changes: 2 additions & 44 deletions app/controllers/collections/versions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def merge
ActiveRecord::Base.transaction do
new_version.rdf_updated_at = nil
new_version.publish
new_version.unlock

if new_version.publishable?
new_version.save

Expand Down Expand Up @@ -63,53 +63,14 @@ def branch

new_version = nil
ActiveRecord::Base.transaction do
new_version = current_collection.branch(current_user)
new_version = current_collection.branch
new_version.save!
end
flash[:success] = t('txt.controllers.versioning.branched')
redirect_to edit_collection_path(new_version, published: 0)
end
end

def lock
new_version = Iqvoc::Collection.base_class.
by_origin(params[:origin]).
unpublished.
last!

if new_version.locked?
raise "Collection '#{new_version.origin}' is already locked."
end

authorize! :lock, new_version

new_version.lock_by_user(current_user.id)
new_version.save validate: false

flash[:success] = t('txt.controllers.versioning.locked')
redirect_to edit_collection_path(new_version, published: 0)
end

def unlock
new_version = Iqvoc::Collection.base_class.
by_origin(params[:origin]).
unpublished.
last!

unless new_version.locked?
raise "Collection '#{new_version.origin}' is not locked."
end

authorize! :unlock, new_version

new_version.unlock
new_version.save validate: false

flash[:success] = t('txt.controllers.versioning.unlocked')

redirect_to collection_path(new_version, published: 0)
end

def consistency_check
collection = Iqvoc::Collection.base_class.
by_origin(params[:origin]).
Expand All @@ -136,9 +97,6 @@ def to_review
authorize! :send_to_review, collection
collection.to_review

authorize! :unlock, collection
collection.unlock

collection.save!
flash[:success] = t('txt.controllers.versioning.to_review_success')
redirect_to collection_path(collection, published: 0)
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/concepts/hierarchical_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ def index
url: url,
update_url: move_concept_url(c),
glance_url: glance_concept_url(c, format: :html),
published: (c.published?) ? true : false,
locked: (can?(:branch, c) || can?(:update, c) ? false : true)
published: (c.published?) ? true : false
}
end
render json: concepts
Expand Down
46 changes: 2 additions & 44 deletions app/controllers/concepts/versions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def merge
ActiveRecord::Base.transaction do
new_version.rdf_updated_at = nil
new_version.publish
new_version.unlock

if new_version.publishable?
new_version.save

Expand Down Expand Up @@ -68,7 +68,7 @@ def branch

new_version = nil
ActiveRecord::Base.transaction do
new_version = current_concept.branch(current_user)
new_version = current_concept.branch
new_version.save!
Iqvoc.change_note_class.create! do |note|
note.owner = new_version
Expand All @@ -85,45 +85,6 @@ def branch
end
end

def lock
new_version = Iqvoc::Concept.base_class.
by_origin(params[:origin]).
unpublished.
last!

if new_version.locked?
raise "Concept with origin '#{new_version.origin}' is already locked."
end

authorize! :lock, new_version

new_version.lock_by_user(current_user.id)
new_version.save validate: false

flash[:success] = t('txt.controllers.versioning.locked')
redirect_to edit_concept_path(published: 0, id: new_version)
end

def unlock
new_version = Iqvoc::Concept.base_class.
by_origin(params[:origin]).
unpublished.
last!

unless new_version.locked?
raise "Concept with origin '#{new_version.origin}' is not locked."
end

authorize! :unlock, new_version

new_version.unlock
new_version.save validate: false

flash[:success] = t('txt.controllers.versioning.unlocked')

redirect_to concept_path(published: 0, id: new_version)
end

def consistency_check
concept = Iqvoc::Concept.base_class.
by_origin(params[:origin]).
Expand All @@ -150,9 +111,6 @@ def to_review
authorize! :send_to_review, concept
concept.to_review

authorize! :unlock, concept
concept.unlock

concept.save!
flash[:success] = t('txt.controllers.versioning.to_review_success')
redirect_to concept_path(published: 0, id: concept)
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/concepts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,6 @@ def create
@concept.assign_attributes(concept_params)
@datasets = datasets_as_json

@concept.lock_by_user(current_user.id)

if @concept.save
flash[:success] = I18n.t('txt.controllers.versioned_concept.success')
redirect_to concept_path(published: 0, id: @concept.origin)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/concepts_movement_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def concept_version(concept)
result = draft.first
else
# create a new version
result = concept.branch(current_user)
result = concept.branch
result.save!
end

Expand Down
10 changes: 5 additions & 5 deletions app/controllers/dashboard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ def concept_index
order_params = params[:sort]
#FIXME: how to order by state in database?
order_params = sanatize_order order_params
order_params = order_params.gsub('value', 'labels.value').gsub('locking_user', 'users.surname').gsub('follow_up', 'concepts.follow_up').gsub('updated_at', 'concepts.updated_at')
order_params = order_params.gsub('value', 'labels.value').gsub('follow_up', 'concepts.follow_up').gsub('updated_at', 'concepts.updated_at')

concepts = concepts.includes(:pref_labels, :locking_user).references(:pref_labels).references(:locking_user).order(order_params)
concepts = concepts.includes(:pref_labels).references(:pref_labels).order(order_params)
else
concepts = concepts.includes(:pref_labels).order('labels.value')
end
Expand All @@ -51,9 +51,9 @@ def collection_index
collections = sort == 'DESC' ? collections.reverse : collections
elsif params[:sort]
order_params = sanatize_order params[:sort]
order_params = order_params.gsub('value', 'labels.value').gsub('locking_user', 'users.surname').gsub('updated_at', 'concepts.updated_at')
order_params = order_params.gsub('value', 'labels.value').gsub('updated_at', 'concepts.updated_at')

collections = collections.includes(:pref_labels, :locking_user).references(:pref_labels).references(:locking_user).order(order_params)
collections = collections.includes(:pref_labels).references(:pref_labels).order(order_params)
else
collections = collections.includes(:pref_labels).order('labels.value')
end
Expand Down Expand Up @@ -102,7 +102,7 @@ def sanatize_order search_params
return '' if search_params.include?(';')
param_array = search_params.split(',').compact.select do |order_column|
column_and_order = order_column.split(' ')
column_and_order.count == 2 && ['value', 'locking_user', 'follow_up', 'updated_at'].include?(column_and_order[0]) && ['ASC', 'DESC'].include?(column_and_order[1])
column_and_order.count == 2 && ['value', 'follow_up', 'updated_at'].include?(column_and_order[0]) && ['ASC', 'DESC'].include?(column_and_order[1])
end
param_array.join(',')
end
Expand Down
6 changes: 2 additions & 4 deletions app/controllers/reverse_matches_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ def add_match
render_response :mapping_exists and return if matches

ActiveRecord::Base.transaction do
unpublished_concept = @published_concept.branch(@botuser)
unpublished_concept = @published_concept.branch
unpublished_concept.save!
@target_match_class.constantize.create(concept_id: unpublished_concept.id, value: @uri)
unpublished_concept.unlock
unpublished_concept.publish!
@published_concept.destroy!
end
Expand All @@ -23,7 +22,7 @@ def add_match
end

def remove_match
unpublished_concept = @published_concept.branch(@botuser)
unpublished_concept = @published_concept.branch
unpublished_concept.save!
match = @target_match_class.constantize.find_by(concept_id: unpublished_concept.id, value: @uri)
if match.nil?
Expand All @@ -32,7 +31,6 @@ def remove_match
end
ActiveRecord::Base.transaction do
match.destroy!
unpublished_concept.unlock
unpublished_concept.publish!
@published_concept.destroy!
end
Expand Down
8 changes: 0 additions & 8 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,6 @@ module ApplicationHelper
no: '✗'
}

def user_details(user)
details = mail_to(user.email, user.name)
if user.telephone_number?
details << ' ' << user.telephone_number
end
details
end

# Formats a list of items or returns a remark if no items where given
def item_listing(items, &block)
return '&nbsp;'.html_safe if items.empty?
Expand Down
12 changes: 6 additions & 6 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,26 @@ def initialize(user = nil)
if user.owns_role?(:editor) || user.owns_role?(:publisher) || user.owns_role?(:administrator) # Editors and above ...
can :read, [::Concept::Base, ::Collection::Base, ::Label::Base]
can :create, [::Concept::Base, ::Collection::Base, ::Label::Base]
can [:update, :destroy, :unlock], [::Concept::Base, ::Collection::Base, ::Label::Base], locked_by: user.id, published_at: nil
can :lock, [::Concept::Base, ::Collection::Base, ::Label::Base], locked_by: nil, published_at: nil
can [:update, :destroy, :unlock], [::Concept::Base, ::Collection::Base, ::Label::Base], published_at: nil
can :lock, [::Concept::Base, ::Collection::Base, ::Label::Base], published_at: nil
can :check_consistency, [::Concept::Base, ::Collection::Base, ::Label::Base], published_at: nil
can :send_to_review, [::Concept::Base, ::Collection::Base, ::Label::Base] do |object|
!object.in_review? && object.locked_by == user.id
!object.in_review?
end
can :branch, [::Concept::Base, ::Collection::Base, ::Label::Base], &@@if_published
end

if user.owns_role?(:match_editor)
can :read, ::Concept::Base
can :create, ::Concept::Base
can [:update, :lock], ::Concept::Base, locked_by: user.id, published_at: nil
can :lock, ::Concept::Base, locked_by: nil, published_at: nil
can [:update, :lock], ::Concept::Base, published_at: nil
can :lock, ::Concept::Base, published_at: nil
can :branch, ::Concept::Base, &@@if_published
end

if user.owns_role?(:publisher) || user.owns_role?(:administrator) # Publishers and above ...
can :merge, [::Concept::Base, ::Collection::Base, ::Label::Base] do |object|
!object.published? && (!object.locked? || object.locked_by == user.id)
!object.published?
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/concept/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ def self.with_pref_labels
end

def self.for_dashboard
unpublished_or_follow_up.includes(:pref_labels, :locking_user)
unpublished_or_follow_up.includes(:pref_labels)
end

def self.parentless
Expand Down
2 changes: 1 addition & 1 deletion app/models/concept/relation/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def self.unpublished
end

def self.target_in_edit_mode
joins(:target).merge(Concept::Base.in_edit_mode).references(:concepts)
joins(:target).merge(Concept::Base.unpublished).references(:concepts)
end

# ********* Methods
Expand Down
32 changes: 1 addition & 31 deletions app/models/concerns/versioning.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ module Versioning
class_name: name,
optional: true

belongs_to :locking_user,
foreign_key: 'locked_by',
class_name: 'AbstractUser',
optional: true

after_initialize do
disable_validations_for_publishing
end
Expand All @@ -48,10 +43,6 @@ def unpublished
where(published_at: nil)
end

def locked
where(arel_table[:locked_by].not_eq(nil))
end

def published_with_newer_versions
# published objects without objects which have a new one in editing
published_objects = arel_table[:published_at].not_eq(nil).and(arel_table[:origin].not_in(unpublished.map(&:origin)))
Expand All @@ -70,10 +61,6 @@ def editor_selectable
)
end

def in_edit_mode
where(arel_table[:locked_by].not_eq(nil))
end

def unpublished_or_follow_up
where(
arel_table[:published_at].eq(nil).or(
Expand All @@ -99,9 +86,8 @@ def includes_to_deep_cloning
end
end # module ClassMethods

def branch(user)
def branch
new_version = self.deep_clone(include: self.class.includes_to_deep_cloning)
new_version.lock_by_user(user.id)
new_version.increment(:rev)
new_version.published_version_id = self.id
new_version.unpublish
Expand All @@ -114,20 +100,10 @@ def editor_selectable?
published? || read_attribute(:published_version_id).blank?
end

def lock_by_user(user_id)
tap do
write_attribute(:locked_by, user_id)
end
end

def never_published?
unpublished? && rev == 1
end

def locked?
locked_by?
end

def state
if published?
I18n.t('txt.common.state.published')
Expand All @@ -138,12 +114,6 @@ def state
end
end

def unlock
tap do
write_attribute(:locked_by, nil)
end
end

def in_review?
read_attribute(:to_review).present?
end
Expand Down

0 comments on commit 01bea39

Please sign in to comment.