Class: Collections::VersionsController

Inherits:
ApplicationController
  • Object
show all
Includes:
RDFSyncService::Helper
Defined in:
app/controllers/collections/versions_controller.rb

Overview

Copyright 2011-2013 innoQ Deutschland GmbH

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Instance Method Summary collapse

Methods included from RDFSyncService::Helper

#triplestore_syncer

Instance Method Details

#branchObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/controllers/collections/versions_controller.rb', line 54

def branch
  scope = Iqvoc::Collection.base_class.by_origin(params[:origin])
  current_collection = scope.published.last!

  if draft_collection = scope.unpublished.last
    raise "There already is an unpublished version for collection '#{draft_collection.origin}'"
  end

  authorize! :branch, current_collection

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

#consistency_checkObject



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'app/controllers/collections/versions_controller.rb', line 112

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

  authorize! :check_consistency, collection

  if collection.publishable?
    flash[:success] = t('txt.controllers.versioning.consistency_check_success')
    redirect_to collection_path(collection, published: 0)
  else
    flash[:error] = t('txt.controllers.versioning.consistency_check_error')
    redirect_to edit_collection_path(collection, published: 0, full_consistency_check: '1')
  end
end

#lockObject



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'app/controllers/collections/versions_controller.rb', line 73

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

#mergeObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/collections/versions_controller.rb', line 20

def merge
  scope = Iqvoc::Collection.base_class.by_origin(params[:origin])

  current_collection = scope.published.last
  new_version = scope.unpublished.last!

  authorize! :merge, new_version

  ActiveRecord::Base.transaction do
    new_version.rdf_updated_at = nil
    new_version.publish
    new_version.unlock
    if new_version.publishable?
      new_version.save

      if current_collection && !current_collection.destroy
        flash[:error] = t('txt.controllers.versioning.merged_delete_error')
        redirect_to collection_path(new_version, published: 0)
      end

      if Iqvoc.config['triplestore.autosync']
        synced = triplestore_syncer.sync([new_version]) # XXX: blocking
        flash[:warning] = 'triplestore synchronization failed' unless synced # TODO: i18n
      end

      flash[:success] = t('txt.controllers.versioning.published')
      redirect_to collection_path(new_version)
    else
      flash[:error] = t('txt.controllers.versioning.merged_publishing_error')
      redirect_to collection_path(new_version, published: 0)
    end
  end
end

#to_reviewObject



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'app/controllers/collections/versions_controller.rb', line 129

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

  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)
end

#unlockObject



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'app/controllers/collections/versions_controller.rb', line 92

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