It is now possible to follow events' and organisations' versions. Refs #15

This commit is contained in:
echarp 2016-01-10 01:10:22 +01:00
parent a51e7cf8fc
commit b0fe24ca4b
11 changed files with 185 additions and 16 deletions

View File

@ -0,0 +1,15 @@
# Supervise all the actions done
class VersionsController < ApplicationController
def index
respond_to do |format|
format.html do
@search = PaperTrail::Version.search params[:q]
@search.sorts = 'created_at desc' if @search.sorts.empty?
@versions = @search.result.page params[:page]
end
format.rss do
@versions = PaperTrail::Version.order('created_at desc').limit(20)
end
end
end
end

View File

@ -4,7 +4,7 @@
class Event < ActiveRecord::Base
extend SimpleCalendar
strip_attributes
has_paper_trail
has_paper_trail ignore: [:last_updated, :secret, :submitter]
belongs_to :region
has_many :notes, dependent: :destroy

View File

@ -1,6 +1,7 @@
# Groups related to this agenda
# Organisations related to this agenda
class Orga < ActiveRecord::Base
has_paper_trail
strip_attributes
has_paper_trail ignore: [:last_updated, :secret, :submitter]
belongs_to :region
belongs_to :kind
@ -54,4 +55,8 @@ class Orga < ActiveRecord::Base
def name_as_tag
name.gsub(/\AL'/, '').gsub(/[\s\*']/, '-').delete ':'
end
def to_s
"[#{kind.name}] #{name}"
end
end

View File

@ -62,6 +62,9 @@
= link_to orgas_path do
%em.fa.fa-users
= Orga.model_name.human.pluralize
= link_to versions_path do
%em.fa.fa-exchange
= t 'versions.index.title'
= link_to application_infos_path do
%em.fa.fa-info
= t '.infos'

View File

@ -0,0 +1,49 @@
%h2
%em.fa.fa-exchange
= title t '.title'
%table.list.autopagerize_page_element
%thead
%th.event= sort_link @search, :event
%th.whodunnit= sort_link @search, :whodunnit
%th.object= sort_link @search, :object_id
%th.created_at= sort_link @search, :created_at
%th.view/
%tbody
- @versions.each do |version|
:ruby
if version.event == 'create'
object = version.item_type.constantize.find version.item_id
else
object = version.reify
end
next unless object.moderated?
changes = ''
if version.event == 'update'
version.changeset.each do |key, val|
changes += version.item_type.constantize.human_attribute_name(key)
changes += ': '
if key == 'description'
changes += Differ.diff(val[1], val[0]).to_s
else
changes += "#{val[0]} -> #{val[1]}"
end
changes += '
'
end
changes = strip_tags(changes).gsub(/^\s*/, '')
end
%tr
%td{ title: changes }= t ".#{version.event}_html"
%td= User.find version.whodunnit if version.whodunnit
%td= object
%td= l version.created_at
%td
%a{ href: polymorphic_path(version.item_type.tableize.singularize,
id: version.item_id) }
%em.fa.fa-eye
= paginate @versions

View File

@ -0,0 +1,78 @@
require 'differ/format/patch'
Differ.format = Differ::Format::Patch
xml.instruct!
xml.rdf :RDF,
'xmlns:rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
'xmlns' => 'http://purl.org/rss/1.0/',
'xmlns:dc' => 'http://purl.org/dc/elements/1.1/',
'xmlns:sy' => 'http://purl.org/rss/1.0/modules/syndication/',
'xmlns:admin' => 'http://webns.net/mvcb/',
'xmlns:cc' => 'http://web.resource.org/cc/',
'xmlns:content' => 'http://purl.org/rss/1.0/modules/content/',
'xmlns:georss' => 'http://www.georss.org/georss' do
xml.channel 'rdf:about' => root_url do
title = t 'layouts.application.title'
if params[:region].present? && params[:region] != 'all'
region = Region.find(params[:region]).name
title += " [#{region}]"
end
xml.title title
xml.description t 'layouts.application.subtitle'
xml.link root_url
xml.dc :language, 'fr'
xml.dc :creator, root_url
xml.items do
xml.rdf :Seq do
@versions.each do |version|
xml.rdf :li, 'rdf:resource' =>
polymorphic_url(version.item_type.tableize.singularize,
id: version.item_id)
end
end
end
end
@versions.each do |version|
if version.event == 'create'
object = version.item_type.constantize.find version.item_id
else
object = version.reify
end
next unless object.moderated?
url = polymorphic_url(version.item_type.tableize.singularize,
id: version.item_id)
xml.item 'rdf:about' => url do
xml.title "#{version.event} - #{object}"
xml.link url
domain = root_url.gsub(/www/, '').gsub(/http.?:../, '').gsub(/:.*/, '')
xml.dc :identifier, "version_#{version.id}@#{domain}"
xml.dc :date, version.created_at.iso8601
if object.try(:description)
if version.event == 'create'
xml.description strip_tags object.description
xml.content(:encoded) { xml.cdata! object.description }
elsif version.event == 'update'
changes = ''
version.changeset.each do |key, val|
changes += version.item_type.constantize.human_attribute_name(key)
changes += ': '
if key == 'description'
changes += Differ.diff(val[1], val[0]).to_s
else
changes += "#{val[0]} -> #{val[1]}"
end
changes += '
'
end
xml.description changes
xml.content(:encoded) { xml.cdata! changes }
end
end
end
end
end

View File

@ -380,15 +380,7 @@ reason:
signature: Have a good day!
accept:
subject: "Organisation '%{subject}' moderated"
body: "Organisation has been modérée by %{moderator}.
\nYou can acces it here:"
edit_link: "Vous pouvez modifier cette organisation ultérieurement pour y ajouter des
\nprécisions en vous rendant à l'adresse:"
delete_link: "You can also delete it using the address:"
signature: Thank you for your contribution and see you soon!
accept:
subject: "Organisation '%{subject}' moderated"
body: The orgnisation has been moderated by %{author}.
body: The organisation has been moderated by %{author}.
access: "You can consult it here:"
signature: Thanks for your contribution!
destroy:
@ -399,3 +391,10 @@ reason:
moderation team.
reminder: "Reminder, here is your organisation's content:"
signature: With all our thanks for your contribution
versions:
index:
title: Versions
create_html: <em class='fa fa-plus-circle'></em>
update_html: <em class='fa fa-exchange'></em>
destroy_html: <em class='fa fa-trash'></em>

View File

@ -391,3 +391,10 @@ l'adresse:"
de modérateurs.
reminder: "Pour rappel, voici le contenu de l'organisation:"
signature: Avec tous nos remerciements pour votre contribution
versions:
index:
title: Versions
create_html: <em class='fa fa-plus-circle'></em>
update_html: <em class='fa fa-exchange'></em>
destroy_html: <em class='fa fa-trash'></em>

View File

@ -3,6 +3,7 @@ Rails.application.routes.draw do
get 'application/contact'
get 'application/rules'
get 'stats', to: 'stats#index'
get 'versions', to: 'versions#index'
resources :users
resources :events do

View File

@ -0,0 +1,10 @@
# Can trace the exact changes to paper trailed objects
class AddObjectChangesToVersions < ActiveRecord::Migration
# The largest text column available in all supported RDBMS.
# See `create_versions.rb` for details.
TEXT_BYTES = 1_073_741_823
def change
add_column :versions, :object_changes, :text, limit: TEXT_BYTES
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160107203117) do
ActiveRecord::Schema.define(version: 20160109203136) do
create_table "active_admin_comments", force: :cascade do |t|
t.string "namespace", limit: 255
@ -121,6 +121,7 @@ ActiveRecord::Schema.define(version: 20160107203117) do
t.text "tag"
t.text "tags", default: ""
t.text "diaspora"
t.text "object_changes"
end
add_index "orgas", ["kind_id"], name: "index_orgas_on_kind_id"
@ -166,12 +167,13 @@ ActiveRecord::Schema.define(version: 20160107203117) do
end
create_table "versions", force: :cascade do |t|
t.string "item_type", null: false
t.integer "item_id", null: false
t.string "event", null: false
t.string "item_type", null: false
t.integer "item_id", null: false
t.string "event", null: false
t.string "whodunnit"
t.text "object"
t.datetime "created_at"
t.text "object_changes", limit: 1073741823
end
add_index "versions", ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id"