Skip to content

Commit

Permalink
Remove the functionality to lock/unlock labels (similar to concepts/c…
Browse files Browse the repository at this point in the history
…ollections).
  • Loading branch information
pschijven committed Oct 13, 2023
1 parent 7067a40 commit e661893
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 88 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source 'https://rubygems.org'

gem 'iqvoc', '~> 4.14.1', github: 'innoq/iqvoc', branch: 'master'
gem 'iqvoc', '~> 4.14.1', github: 'innoq/iqvoc', branch: 'remove-locking'

platforms :ruby do
gem 'pg'
Expand Down
26 changes: 13 additions & 13 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GIT
remote: https://github.com/innoq/iqvoc.git
revision: 045b089839b93acce8c15ace6d23adf197ebf3aa
branch: master
revision: 2bd2118c3e34fc558bd3b96b49903cc3592628a6
branch: remove-locking
specs:
iqvoc (4.14.1)
apipie-rails
Expand Down Expand Up @@ -103,7 +103,7 @@ GEM
tzinfo (~> 2.0)
addressable (2.8.5)
public_suffix (>= 2.0.2, < 6.0)
apipie-rails (1.2.2)
apipie-rails (1.2.3)
actionpack (>= 5.0)
activesupport (>= 5.0)
authlogic (6.4.2)
Expand Down Expand Up @@ -132,7 +132,7 @@ GEM
rack-test (>= 0.6.3)
regexp_parser (~> 1.5)
xpath (~> 3.2)
carrierwave (3.0.3)
carrierwave (3.0.4)
activemodel (>= 6.0.0)
activesupport (>= 6.0.0)
addressable (~> 2.6)
Expand Down Expand Up @@ -197,13 +197,13 @@ GEM
cliver (~> 0.3)
concurrent-ruby (~> 1.1)
websocket-driver (>= 0.6, < 0.8)
ffi (1.15.5)
ffi (1.16.3)
ffi-compiler (1.0.1)
ffi (>= 1.0.0)
rake
globalid (1.2.1)
activesupport (>= 6.1)
haml (6.2.0)
haml (6.2.3)
temple (>= 0.8.2)
thor
tilt
Expand Down Expand Up @@ -283,7 +283,7 @@ GEM
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
logger (1.5.3)
loofah (2.21.3)
loofah (2.21.4)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
mail (2.8.1)
Expand All @@ -298,15 +298,15 @@ GEM
mini_magick (4.12.0)
mini_mime (1.1.5)
mini_portile2 (2.8.4)
minitest (5.19.0)
minitest (5.20.0)
msgpack (1.7.2)
multi_json (1.15.0)
multipart-post (2.3.0)
net-http (0.3.2)
uri
net-http-persistent (4.0.2)
connection_pool (~> 2.2)
net-imap (0.3.7)
net-imap (0.4.1)
date
net-protocol
net-pop (0.1.2)
Expand All @@ -325,7 +325,7 @@ GEM
method_source (~> 1.0)
pry-rails (0.3.9)
pry (>= 0.10.4)
psych (5.1.0)
psych (5.1.1)
stringio
public_suffix (5.0.3)
puma (6.4.0)
Expand Down Expand Up @@ -477,13 +477,13 @@ GEM
sxp (1.3.0)
matrix (~> 0.4)
rdf (~> 3.3)
temple (0.10.2)
temple (0.10.3)
thor (1.2.2)
tilt (2.3.0)
timeout (0.4.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-types (1.8.0)
unicode-types (1.9.0)
uri (0.12.2)
web-console (3.7.0)
actionview (>= 5.0)
Expand All @@ -500,7 +500,7 @@ GEM
psych (>= 3.3)
rdf (~> 3.2, >= 3.2.9)
rdf-xsd (~> 3.2)
zeitwerk (2.6.11)
zeitwerk (2.6.12)

PLATFORMS
ruby
Expand Down
33 changes: 2 additions & 31 deletions app/controllers/labels/versions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def merge

ActiveRecord::Base.transaction do
new_version.publish
new_version.unlock

if new_version.publishable?
new_version.save
begin
Expand Down Expand Up @@ -48,7 +48,7 @@ def branch
authorize! :branch, current_label
new_version = nil
ActiveRecord::Base.transaction do
new_version = current_label.branch(current_user)
new_version = current_label.branch
new_version.save!
Iqvoc.change_note_class.create! do |note|
note.owner = new_version
Expand All @@ -65,32 +65,6 @@ def branch
end
end

def lock
new_version = Iqvoc::XLLabel.base_class.by_origin(params[:origin]).unpublished.last!
raise "Label with origin '#{params[:origin]}' has already been locked." if new_version.locked?

authorize! :lock, new_version

new_version.lock_by_user(current_user.id)
new_version.save!

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

def unlock
new_version = Iqvoc::XLLabel.base_class.by_origin(params[:origin]).unpublished.last!
raise "Label with origin '#{params[:origin]}' wasn't locked." unless new_version.locked?

authorize! :unlock, new_version

new_version.unlock
new_version.save!

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

def consistency_check
label = Iqvoc::XLLabel.base_class.by_origin(params[:origin]).unpublished.last!

Expand All @@ -111,9 +85,6 @@ def to_review
authorize! :send_to_review, label
label.to_review

authorize! :unlock, label
label.unlock

label.save!
flash[:success] = t('txt.controllers.versioning.to_review_success')
redirect_to label_path(published: 0, id: label)
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/labels_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ def create
authorize! :create, Iqvoc::XLLabel.base_class

@label = Iqvoc::XLLabel.base_class.new(label_params)
@label.lock_by_user(current_user.id)

if @label.valid?
if @label.save
Expand Down Expand Up @@ -165,7 +164,6 @@ def create_from_concept

@label = Iqvoc::XLLabel.base_class.new(label_params)
@label.build_initial_change_note(current_user)
@label.lock_by_user(current_user.id)

if @label.save
#TODO: idea for solving this
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/xl_dashboard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ def label_index
elsif params[:sort]
#FIXME: how to order by state in database?
order_params = sanatize_order params[:sort]
order_params = order_params.gsub('locking_user', 'users.surname').gsub('updated_at', 'labels.updated_at')
order_params = order_params.gsub('updated_at', 'labels.updated_at')

labels = labels.includes(:locking_user).references(:locking_user).order(order_params)
labels = labels.order(order_params)
else
labels = labels.order('value')
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/label/relation/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def self.range_editor_selectable
end

def self.range_in_edit_mode
joins(:range).references(:labels).merge(Iqvoc::XLLabel.base_class.in_edit_mode)
joins(:range).references(:labels).merge(Iqvoc::XLLabel.base_class.unpublished)
end

def self.view_section(obj)
Expand Down
3 changes: 1 addition & 2 deletions app/models/label/skosxl/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def self.with_associations
end

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

# ********** Class Methods
Expand Down Expand Up @@ -331,7 +331,6 @@ def duplicate(user)
clone = deep_clone(except: [:origin, :rev, :published_version_id, :published_at, :expired_at, :to_review], include: [:labelings])

clone.origin = Origin.new.to_s
clone.locked_by = user.id
clone.value += " [#{I18n.t('txt.models.label.copy')}]"

clone.labelings.select { |l| l.type == "Labeling::SKOSXL::PrefLabel" }.each do |l|
Expand Down
2 changes: 1 addition & 1 deletion app/models/labeling/skosxl/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Labeling::SKOSXL::Base < Labeling::Base
self.rdf_predicate = nil

def self.target_in_edit_mode
includes(:target).references(:labels).merge(Iqvoc::XLLabel.base_class.in_edit_mode)
includes(:target).references(:labels).merge(Iqvoc::XLLabel.base_class.unpublished)
end

def self.by_label_origin(origin)
Expand Down
1 change: 0 additions & 1 deletion app/views/labels/notifications/_referenced_labels.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<%= label_relation.class.model_name.human %>
<%= link_to(label_relation.range.value,
label_path(:published => 0, :id => label_relation.range)) %>
<%= t("txt.common.editor") %> <%= user_details(label_relation.range.locking_user) %>
</li>
<% end %>
</ul>
Expand Down
30 changes: 12 additions & 18 deletions app/views/labels/show_unpublished.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,30 @@
<%= alert :info, :header => t('txt.common.unpublished_version') + "." do %>
<%= t("txt.views.versioning.current_revision", :rev => @label.rev) %>
<% if @label.locked? %>
<%= t("txt.views.versioning.in_ongoing_editing_by", :user => @label.locking_user.name) %>
<% end %>
<% end %>

<div class="editing_versioning_toolbar">
<% if (not @label.locked?) || @label.locked_by == @current_user.id %>
<% if can?(:merge, @label) %>
<%= button_to t("txt.views.versioning.publishing"),
label_versions_merge_path(:origin => @label.origin), :class => 'btn btn-primary' %>
label_versions_merge_path(:origin => @label.origin), :class => 'btn btn-primary' %>
<% end %>
<% if can?(:check_consistency, @label) %>
<%= button_to t("txt.views.versioning.consistency_check"),
label_versions_consistency_check_path(:origin => @label.origin),
:method => :get, :class => 'btn btn-outline-secondary' %>
<% end %>
<%= button_to t("txt.views.versioning.consistency_check"),
label_versions_consistency_check_path(:origin => @label.origin),
:method => :get, :class => 'btn btn-outline-secondary' %>
<% if (not @label.in_review?) && @label.locked_by == @current_user.id %>
<% if can?(:send_to_review, @label) %>
<%= button_to t("txt.common.to_review"),
label_versions_to_review_path(:origin => @label.origin),
:class => 'btn btn-outline-secondary' %>
<% end %>
<% if @label.locked? %>
<%= button_to t("txt.views.versioning.unlock"),
label_versions_unlock_path(:origin => @label.origin),
:class => 'btn btn-outline-secondary' if can?(:unlock, @label) %>
<% if can?(:update, @label) %>
<%= link_to t("txt.views.versioning.edit_mode"),
edit_label_path(:published => 0, :id => @label.origin),
:class => 'btn btn-outline-secondary' if can?(:update, @label) %>
<% elsif can?(:lock, @label) %>
<%= button_to t("txt.views.versioning.to_edit_mode"),
label_versions_lock_path(:origin => @label.origin), :class => 'btn btn-outline-secondary' %>
edit_label_path(:published => 0, :id => @label.origin),
:class => 'btn btn-outline-secondary' %>
<% end %>
<% if can?(:destroy, @label) %>
Expand Down
19 changes: 5 additions & 14 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,11 @@
scope ':lang', constraints: Iqvoc.routing_constraint do
resources :labels

post 'labels/versions/:origin/branch' => 'labels/versions#branch',
:as => 'label_versions_branch'
post 'labels/versions/:origin/merge' => 'labels/versions#merge',
:as => 'label_versions_merge'
post 'labels/versions/:origin/lock' => 'labels/versions#lock',
:as => 'label_versions_lock'
post 'labels/versions/:origin/unlock' => 'labels/versions#unlock',
:as => 'label_versions_unlock'
post 'labels/versions/:origin/to_review' => 'labels/versions#to_review',
:as => 'label_versions_to_review'
get 'labels/versions/:origin/consistency_check' => 'labels/versions#consistency_check',
:as => 'label_versions_consistency_check'
get 'labels/:origin/duplicate' => 'labels#duplicate',
:as => 'label_duplicate'
post 'labels/versions/:origin/branch' => 'labels/versions#branch', :as => 'label_versions_branch'
post 'labels/versions/:origin/merge' => 'labels/versions#merge', :as => 'label_versions_merge'
post 'labels/versions/:origin/to_review' => 'labels/versions#to_review', :as => 'label_versions_to_review'
get 'labels/versions/:origin/consistency_check' => 'labels/versions#consistency_check', :as => 'label_versions_consistency_check'
get 'labels/:origin/duplicate' => 'labels#duplicate', :as => 'label_duplicate'
get 'label_dashboard' => 'xl_dashboard#label_index', as: 'label_dashboard'
get 'concept_new_label' => 'labels#new_from_concept', as: 'concept_new_label'
post 'concept_create_label' => 'labels#create_from_concept', as: 'concept_create_label'
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20231012174634_remove_locked_by_for_label.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RemoveLockedByForLabel < ActiveRecord::Migration[7.0]
def change
remove_column :labels, :locked_by
end
end
4 changes: 2 additions & 2 deletions test/integration/label_relation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class UnidirectionalRelation < Label::Relation::SKOSXL::Base
visit label_path(@dog_en, lang: 'en', format: 'html')
click_link_or_button('Create new version')
assert_equal edit_label_path(@dog_en, lang: 'en', format: 'html'), current_path
assert page.has_content? 'Instance copy has been created and locked.'
assert page.has_content? 'Instance copy has been created.'

# add translation dog_en => dog_de
fill_in 'label_relation_skosxl_translations', with: 'dog_de'
Expand Down Expand Up @@ -101,7 +101,7 @@ class UnidirectionalRelation < Label::Relation::SKOSXL::Base
visit label_path(@dog_en, lang: 'en', format: 'html')
click_link_or_button('Create new version')
assert_equal edit_label_path(@dog_en, lang: 'en', format: 'html'), current_path
assert page.has_content? 'Instance copy has been created and locked.'
assert page.has_content? 'Instance copy has been created.'

# add translation dog_en => dog_de
fill_in 'label_relation_skosxl_unidirectional_relations', with: 'dog_de'
Expand Down

0 comments on commit e661893

Please sign in to comment.