Class: Concepts::VersionsController

Inherits:
ApplicationController
  • Object
show all
Includes:
Iqvoc::RDFSync::Helper
Defined in:
app/controllers/concepts/versions_controller.rb

Instance Method Summary collapse

Methods included from Iqvoc::RDFSync::Helper

#triplestore_syncer

Instance Method Details

#branchObject

Raises:

  • (ActiveRecord::RecordNotFound)


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

def branch
  current_concept = Iqvoc::Concept.base_class.by_origin(params[:origin]).published.last
  raise ActiveRecord::RecordNotFound.new("Couldn't find published concept with origin '#{params[:origin]}'") unless current_concept
  raise "There already is an unpublished version for concept '#{params[:origin]}'" if Iqvoc::Concept.base_class.by_origin(params[:origin]).unpublished.last

  authorize! :branch, current_concept

  new_version = nil
  ActiveRecord::Base.transaction do
    new_version = current_concept.branch(current_user)
    new_version.save!
  end
  flash[:success] = t("txt.controllers.versioning.branched")
  redirect_to edit_concept_path(:published => 0, :id => new_version)
end

#consistency_checkObject

Raises:

  • (ActiveRecord::RecordNotFound)


100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'app/controllers/concepts/versions_controller.rb', line 100

def consistency_check
  concept = Iqvoc::Concept.base_class.by_origin(params[:origin]).unpublished.last
  raise ActiveRecord::RecordNotFound unless concept

  authorize! :check_consistency, concept

  if concept.valid_with_full_validation?
    flash[:success] = t("txt.controllers.versioning.consistency_check_success")
    redirect_to concept_path(:published => 0, :id => concept)
  else
    flash[:error] = t("txt.controllers.versioning.consistency_check_error")
    redirect_to edit_concept_path(:published => 0, :id => concept, :full_consistency_check => "1")
  end
end

#lockObject

Raises:

  • (ActiveRecord::RecordNotFound)


71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/controllers/concepts/versions_controller.rb', line 71

def lock
  new_version = Iqvoc::Concept.base_class.by_origin(params[:origin]).unpublished.last
  raise ActiveRecord::RecordNotFound.new("Couldn't find unpublished concept with origin '#{params[:origin]}'") unless new_version
  raise "Concept 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 :validate => false

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

#mergeObject

Raises:

  • (ActiveRecord::RecordNotFound)


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
53
# File 'app/controllers/concepts/versions_controller.rb', line 22

def merge
  current_concept = Iqvoc::Concept.base_class.by_origin(params[:origin]).published.last
  new_version = Iqvoc::Concept.base_class.by_origin(params[:origin]).unpublished.last
  raise ActiveRecord::RecordNotFound.new("Couldn't find unpublished concept with origin '#{params[:origin]}'") unless new_version

  authorize! :merge, new_version

  ActiveRecord::Base.transaction do
    if current_concept.blank? || current_concept.destroy
      new_version.rdf_updated_at = nil
      new_version.publish
      new_version.unlock
      if new_version.valid_with_full_validation?
        new_version.save

        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 concept_path(:id => new_version)
      else
        flash[:error] = t("txt.controllers.versioning.merged_publishing_error")
        redirect_to concept_path(:published => 0, :id => new_version)
      end
    else
      flash[:error] = t("txt.controllers.versioning.merged_delete_error")
      redirect_to concept_path(:published => 0, :id => new_version)
    end
  end
end

#to_reviewObject

Raises:

  • (ActiveRecord::RecordNotFound)


115
116
117
118
119
120
121
122
123
124
125
# File 'app/controllers/concepts/versions_controller.rb', line 115

def to_review
  concept = Iqvoc::Concept.base_class.by_origin(params[:origin]).unpublished.last
  raise ActiveRecord::RecordNotFound unless concept

  authorize! :send_to_review, concept

  concept.to_review
  concept.save!
  flash[:success] = t("txt.controllers.versioning.to_review_success")
  redirect_to concept_path(:published => 0, :id => concept)
end

#unlockObject

Raises:

  • (ActiveRecord::RecordNotFound)


85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'app/controllers/concepts/versions_controller.rb', line 85

def unlock
  new_version = Iqvoc::Concept.base_class.by_origin(params[:origin]).unpublished.last
  raise ActiveRecord::RecordNotFound.new("Couldn't find unpublished concept with origin '#{params[:origin]}'") unless new_version
  raise "Concept with origin '#{params[:origin]}' wasn't locked." unless new_version.locked?

  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