diff --git a/app/controllers/collections/versions_controller.rb b/app/controllers/collections/versions_controller.rb index 7203121de..5d462983f 100644 --- a/app/controllers/collections/versions_controller.rb +++ b/app/controllers/collections/versions_controller.rb @@ -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 @@ -63,7 +63,7 @@ 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') @@ -71,45 +71,6 @@ def branch 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]). @@ -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) diff --git a/app/controllers/concepts/hierarchical_controller.rb b/app/controllers/concepts/hierarchical_controller.rb index 709699f23..8be7b91f1 100644 --- a/app/controllers/concepts/hierarchical_controller.rb +++ b/app/controllers/concepts/hierarchical_controller.rb @@ -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 diff --git a/app/controllers/concepts/versions_controller.rb b/app/controllers/concepts/versions_controller.rb index 0f3d753f3..f3f17bb09 100644 --- a/app/controllers/concepts/versions_controller.rb +++ b/app/controllers/concepts/versions_controller.rb @@ -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 @@ -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 @@ -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]). @@ -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) diff --git a/app/controllers/concepts_controller.rb b/app/controllers/concepts_controller.rb index 9a7a2d017..aed77c994 100644 --- a/app/controllers/concepts_controller.rb +++ b/app/controllers/concepts_controller.rb @@ -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) diff --git a/app/controllers/concepts_movement_controller.rb b/app/controllers/concepts_movement_controller.rb index 186d0e7fd..b4489b16b 100644 --- a/app/controllers/concepts_movement_controller.rb +++ b/app/controllers/concepts_movement_controller.rb @@ -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 diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index 029167c02..97ee6385e 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -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 @@ -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 @@ -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 diff --git a/app/controllers/reverse_matches_controller.rb b/app/controllers/reverse_matches_controller.rb index e506fc49b..43d69b3e9 100644 --- a/app/controllers/reverse_matches_controller.rb +++ b/app/controllers/reverse_matches_controller.rb @@ -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 @@ -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? @@ -32,7 +31,6 @@ def remove_match end ActiveRecord::Base.transaction do match.destroy! - unpublished_concept.unlock unpublished_concept.publish! @published_concept.destroy! end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index b86babdaf..657d55520 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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 ' '.html_safe if items.empty? diff --git a/app/models/ability.rb b/app/models/ability.rb index 298c24d40..7b5b597dc 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -23,11 +23,10 @@ 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], [::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 @@ -35,19 +34,19 @@ def initialize(user = nil) 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, ::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 if user.owns_role?(:administrator) - can [:update, :destroy, :unlock], [::Concept::Base, ::Label::Base], published_at: nil # Mustn't be locked by myself + can [:update, :destroy], [::Concept::Base, ::Label::Base], published_at: nil can :manage, User can :manage, Iqvoc.config diff --git a/app/models/concept/base.rb b/app/models/concept/base.rb index 7d9bfa8d5..ec667c950 100644 --- a/app/models/concept/base.rb +++ b/app/models/concept/base.rb @@ -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 diff --git a/app/models/concept/relation/base.rb b/app/models/concept/relation/base.rb index e37a000f6..5c582783e 100644 --- a/app/models/concept/relation/base.rb +++ b/app/models/concept/relation/base.rb @@ -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 diff --git a/app/models/concerns/versioning.rb b/app/models/concerns/versioning.rb index 3a29ca9c4..2c5c5e5c5 100644 --- a/app/models/concerns/versioning.rb +++ b/app/models/concerns/versioning.rb @@ -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 @@ -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))) @@ -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( @@ -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 @@ -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') @@ -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 diff --git a/app/views/collections/show_unpublished.html.erb b/app/views/collections/show_unpublished.html.erb index 64be7e35b..909f42ac0 100644 --- a/app/views/collections/show_unpublished.html.erb +++ b/app/views/collections/show_unpublished.html.erb @@ -3,9 +3,6 @@ <%= alert :info, :header => t('txt.common.unpublished_version') + "." do %> <%= t("txt.views.versioning.current_revision", :rev => @collection.rev) %> - <% if @collection.locked? %> - <%= t("txt.views.versioning.in_ongoing_editing_by", :user => @collection.locking_user.name) %> - <% end %> <% end %>