Class: EditMediator

Inherits:
Object
  • Object
show all
Defined in:
frontend/app/models/edit_mediator.rb

Defined Under Namespace

Classes: UpdateThread

Class Method Summary collapse

Class Method Details

.record(user, uri, lock_version, last_report_time) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'frontend/app/models/edit_mediator.rb', line 12

def self.record(user, uri, lock_version, last_report_time)
  # Check whether the lock version is out of date, or whether someone else is
  # editing.
  status = @active_edits.value[uri]

  if status && status['lock_version'] && status['lock_version'] > lock_version
    # Stale
    return {:status => "stale"}
  end


  # Record the fact that this user is editing
  @queue << {
    :type => :update,
    :values => [user, uri, last_report_time.iso8601]
  }

  if status && status['edited_by'].keys.count > 1
    # Someone else is editing too!
    {
      :status => "opened_for_editing",
      'edited_by' => Hash[status['edited_by'].reject {|u, _| u == user}]
    }
  else
    {:status => "ok"}
  end
end