Champs "active" et "description" ajoutés aux organisations. Refs #12

This commit is contained in:
echarp 2015-12-26 23:32:04 +01:00
parent dfde6295f8
commit 40e367734c
18 changed files with 123 additions and 84 deletions

View File

@ -4,7 +4,7 @@ $(document).ready ->
schema: 'html5',
menubar: false,
language: 'fr_FR',
selector: 'textarea#event_description',
selector: 'textarea.description',
content_css: '<%= asset_path 'application.css' %>',
entity_encoding : 'raw',
add_unload_trigger: true,

View File

@ -60,6 +60,8 @@
content: $fa-var-map-marker
.field.city label:before
content: $fa-var-compress
.field.department label:before
content: $fa-var-puzzle-piece
.field.region label:before
content: $fa-var-shield
.field.locality > label:before
@ -72,6 +74,8 @@
content: $fa-var-external-link
.field.tags label:before
content: $fa-var-tags
.field.active label:before
content: $fa-var-heartbeat
.field.kind > label:before
content: $fa-var-cubes

View File

@ -87,8 +87,8 @@ class OrgasController < ApplicationController
# through
def orga_params
params.require(:orga)
.permit :lock_version, :kind_id, :name, :city, :department, :region_id,
:url, :feed, :contact, :submitter
.permit :lock_version, :kind_id, :name, :description, :city, :department,
:region_id, :url, :feed, :contact, :submitter, :active
end
# Check that you can only edit an existing event if you know its secret

View File

@ -1,5 +1,7 @@
# Send mails to check on organisations life cycle
class OrgaMailer < ApplicationMailer
helper :events
# Subject can be set in your I18n file at config/locales/en.yml
# with the following lookup:
#

View File

@ -10,26 +10,24 @@ class Orga < ActiveRecord::Base
validates :region, presence: true
validates :url, format: %r{\Ahttps?:\/\/.*\..*\z}
validates :feed, allow_blank: true, format: %r{\Ahttps?:\/\/.*\..*\z}
validates :contact, presence: true, email: true
validates :contact, allow_blank: true, email: true
validates :submitter, allow_blank: true, email: true
scope :active, -> { where active: true }
scope :moderated, -> { where moderated: true }
scope :unmoderated, -> { where moderated: false }
before_validation do
self.secret ||= SecureRandom.urlsafe_base64(32)[0...32]
self.secret ||= SecureRandom.urlsafe_base64(32)[0...32] if submitter
self.submission_time ||= Time.zone.now
# Populate submitter using contact info if absent
self.submitter = contact if submitter.blank?
end
after_create do
send_secret
send_secret if submitter
end
after_update do
send_secret if secret_changed?
send_secret if secret_changed? && submitter
if moderated_changed?
OrgaMailer.accept(self).deliver_now!

View File

@ -24,7 +24,7 @@
:markdown
#{t '.description_helper'}
= f.label :description
= f.text_area :description, rows: 25
= f.text_area :description, rows: 25, class: :description
.field.place_name
= f.label :place_name

View File

@ -18,6 +18,9 @@
.field.name
= f.label :name
= f.text_field :name, required: true
.field.description
= f.label :description
= f.text_area :description, rows: 25, class: :description
.field.city
= f.label :city
= f.text_field :city, list: :cities
@ -55,6 +58,9 @@
#{t '.submitter_helper'}
= f.label :submitter
= f.email_field :submitter
.field.active
= f.label :active
= f.check_box :active
.actions
= f.button do

View File

@ -44,7 +44,6 @@
%em.fa.fa-li.fa-dot-circle-o
GeoJSON
- if user_signed_in?
%h1
%em.fa.fa-wrench
= t '.actions'
@ -57,6 +56,12 @@
%em.fa.fa-lg.fa-thumbs-down
= t '.cancel'
%h3= t '.description'
.description
= description sanitize @orga.description,
tags: %w(p h1 h2 h3 h4 br table tr th td ul ol li a strong b em i img),
attributes: %w(href src width height style)
%dl
- if @orga.city.present?
%dt
@ -64,7 +69,9 @@
= Orga.human_attribute_name :city
%dd= @orga.city
- if @orga.department.present?
%dt= Orga.human_attribute_name :department
%dt
%em.fa.fa-puzzle-piece
= Orga.human_attribute_name :department
%dd= @orga.department
- if @orga.region.present?
%dt
@ -88,6 +95,10 @@
%dd= mail_to @orga.contact, nil,
encode: (request.format == 'text/html' ? :javascript : nil),
replace_at: ' CHEZ ', replace_dot: ' POINT '
%dt
%em.fa.fa-heartbeat
= Orga.human_attribute_name :active
%dd= t @orga.active.to_s
- if @events_future && @events_future.any?
%dt= t '.future'

View File

@ -6,4 +6,8 @@
#{Orga.human_attribute_name(:feed).concat(':').ljust 12 } #{@orga.feed}
#{Orga.human_attribute_name(:contact).concat(':').ljust 12 } #{@orga.contact}
#{Orga.human_attribute_name(:submitter).concat(':').ljust 12} #{@orga.submitter}
#{Orga.human_attribute_name(:active).concat(':').ljust 12 } #{t @orga.active.to_s}
- if @orga.description
#{Orga.human_attribute_name(:description).concat(':').ljust 12}
= wrap(strip_tags(@orga.description).gsub(/&#13;/, '')).gsub /^/, ' '
=====================================================

View File

@ -1,4 +1,4 @@
development:
evelopment:
adapter: sqlite3
pool: 5
timeout: 5000
@ -13,7 +13,8 @@ test:
timeout: 5000
database: db/test.sqlite3
production:
roduction:
development:
adapter: mysql2
encoding: utf8
database: adl_fr

View File

@ -1,4 +1,6 @@
en:
'true': Yes
'false': No
attributes:
id: ID
name: Name
@ -35,6 +37,7 @@ en:
orga:
kind: Type
name: Name
description: Description
city: City
department: Department
region: Region
@ -43,6 +46,7 @@ en:
contact: Contact
submitter: Soumetteur
submission_time: En attente depuis
active: Active
kind:
name_association: Association
name_enterprise: Enterprise

View File

@ -1,4 +1,6 @@
fr:
'true': Oui
'false': Non
attributes:
id: ID
name: Nom
@ -36,6 +38,7 @@ fr:
orga:
kind: Type
name: Nom
description: Description
city: Ville
department: Département
region: Région
@ -44,6 +47,7 @@ fr:
contact: Contact
submitter: Soumetteur
submission_time: En attente depuis
active: Actif
kind:
name_association: Association
name_enterprise: Entreprise

View File

@ -257,14 +257,15 @@ description."
update:
ok: Organisation has been updated
form:
url_helper: Link toe the organisation's website
url_helper: Link to the organisation's website
feed_helper: "**Direct** link to a syndication feed, RSS or atom"
contact_helper: Contact's email address, obfuscated so that spammers
won't understand it
submitter_helper: Submitter's email address. It will only be used by the
moderators to contact the person who proposed the event, to inform her
about her acceptation or rejection. If this address is absent, the
contact's will be used
moderators to contact the person who proposed the organisation, to
inform about her acceptation or rejection. If this address is
present, this organisation will only be editable by the submitter, who
will receive a secret edition link...
save: Save
validate:
ok: Yes

View File

@ -265,8 +265,9 @@ description plus complète."
compréhensible par les spammeurs
submitter_helper: Adresse e-mail du soumetteur de l'organisation.
Utilisée par les modérateurs pour informer de sa validation ou de son
rejet. Si cette adresse n'est pas présente, l'adresse de contact sera
utilisée
rejet. Si cette adresse est présente, l'organisation ne sera plus
modifiable que par le soumetteur, qui recevra un lien secret
d'édition...
save: Envoyer
validate:
ok: Oui

View File

@ -0,0 +1,7 @@
# Adding an active flag to organisations, and a description
class AddActiveDescriptionToOrga < ActiveRecord::Migration
def change
add_column :orgas, :active, :boolean, null: false, default: true
add_column :orgas, :description, :text
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: 20151022214618) do
ActiveRecord::Schema.define(version: 20151226222910) do
create_table "active_admin_comments", force: :cascade do |t|
t.string "namespace", limit: 255
@ -24,9 +24,9 @@ ActiveRecord::Schema.define(version: 20151022214618) do
t.datetime "updated_at"
end
add_index "active_admin_comments", ["author_type", "author_id"], name: "index_active_admin_comments_on_author_type_and_author_id"
add_index "active_admin_comments", ["namespace"], name: "index_active_admin_comments_on_namespace"
add_index "active_admin_comments", ["resource_type", "resource_id"], name: "index_active_admin_comments_on_resource_type_and_resource_id"
add_index "active_admin_comments", ["author_type", "author_id"], name: "index_active_admin_comments_on_author_type_and_author_id", using: :btree
add_index "active_admin_comments", ["namespace"], name: "index_active_admin_comments_on_namespace", using: :btree
add_index "active_admin_comments", ["resource_type", "resource_id"], name: "index_active_admin_comments_on_resource_type_and_resource_id", using: :btree
create_table "admin_users", force: :cascade do |t|
t.string "email", limit: 255, default: "", null: false
@ -43,8 +43,8 @@ ActiveRecord::Schema.define(version: 20151022214618) do
t.datetime "updated_at"
end
add_index "admin_users", ["email"], name: "index_admin_users_on_email", unique: true
add_index "admin_users", ["reset_password_token"], name: "index_admin_users_on_reset_password_token", unique: true
add_index "admin_users", ["email"], name: "index_admin_users_on_email", unique: true, using: :btree
add_index "admin_users", ["reset_password_token"], name: "index_admin_users_on_reset_password_token", unique: true, using: :btree
create_table "cities", force: :cascade do |t|
t.string "name", limit: 255, default: "", null: false
@ -56,7 +56,7 @@ ActiveRecord::Schema.define(version: 20151022214618) do
t.float "longitude", limit: 24
end
add_index "cities", ["name"], name: "cities_name"
add_index "cities", ["name"], name: "cities_name", using: :btree
create_table "events", force: :cascade do |t|
t.string "title", limit: 255, default: "", null: false
@ -72,8 +72,8 @@ ActiveRecord::Schema.define(version: 20151022214618) do
t.integer "moderated", limit: 4, default: 0, null: false
t.string "tags", limit: 255, default: "", null: false
t.string "secret", limit: 255, default: "", null: false
t.datetime "decision_time"
t.datetime "submission_time"
t.datetime "decision_time", null: false
t.datetime "submission_time", null: false
t.string "moderator_mail_id", limit: 32
t.string "submitter_mail_id", limit: 32
t.text "address", limit: 65535
@ -83,7 +83,7 @@ ActiveRecord::Schema.define(version: 20151022214618) do
t.string "place_name", limit: 255
end
add_index "events", ["start_time", "end_time"], name: "events_date"
add_index "events", ["start_time", "end_time"], name: "events_date", using: :btree
create_table "kinds", force: :cascade do |t|
t.string "name", limit: 255, null: false
@ -109,45 +109,29 @@ ActiveRecord::Schema.define(version: 20151022214618) do
t.string "feed", limit: 255
t.string "contact", limit: 255
t.string "submitter", limit: 255
t.boolean "moderated", limit: 1, default: false
t.boolean "moderated", default: false
t.datetime "submission_time"
t.datetime "decision_time"
t.string "secret", limit: 255
t.boolean "deleted", limit: 1, default: false, null: false
t.boolean "deleted", default: false, null: false
t.boolean "active", default: true, null: false
t.text "description", limit: 65535
t.datetime "createdAt"
t.datetime "updatedAt"
end
add_index "orgas", ["kind_id"], name: "index_orgas_on_kind_id"
add_index "orgas", ["kind_id"], name: "index_orgas_on_kind_id", using: :btree
create_table "regions", force: :cascade do |t|
t.string "name", limit: 255, default: "", null: false
end
create_table "taggings", force: :cascade do |t|
t.integer "tag_id"
t.integer "taggable_id"
t.string "taggable_type", limit: 255
t.integer "tagger_id"
t.string "tagger_type", limit: 255
t.string "context", limit: 128
t.datetime "created_at"
end
add_index "taggings", ["tag_id", "taggable_id", "taggable_type", "context", "tagger_id", "tagger_type"], name: "taggings_idx", unique: true
add_index "taggings", ["taggable_id", "taggable_type", "context"], name: "index_taggings_on_taggable_id_and_taggable_type_and_context"
create_table "tags", force: :cascade do |t|
t.string "name", limit: 255
t.integer "taggings_count", default: 0
end
add_index "tags", ["name"], name: "index_tags_on_name", unique: true
create_table "translations", force: :cascade do |t|
t.string "locale", limit: 255
t.string "key", limit: 255
t.text "value", limit: 65535
t.text "interpolations", limit: 65535
t.boolean "is_proc", limit: 1, default: false
t.boolean "is_proc", default: false
end
create_table "users", force: :cascade do |t|
@ -159,14 +143,14 @@ ActiveRecord::Schema.define(version: 20151022214618) 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 "whodunnit"
t.text "object"
t.string "item_type", limit: 255, null: false
t.integer "item_id", limit: 4, null: false
t.string "event", limit: 255, null: false
t.string "whodunnit", limit: 255
t.text "object", limit: 65535
t.datetime "created_at"
end
add_index "versions", ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id"
add_index "versions", ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id", using: :btree
end

View File

@ -29,7 +29,8 @@ class OrgasControllerTest < ActionController::TestCase
region_id: @orga.region.id,
url: @orga.url,
feed: @orga.feed,
contact: @orga.contact
contact: @orga.contact,
submitter: @orga.contact
}
assert_empty assigns(:orga).errors.messages

View File

@ -10,6 +10,17 @@ class OrgaTest < ActiveSupport::TestCase
test 'propose orga' do
assert_difference 'ActionMailer::Base.deliveries.size', 1 do
Orga.create!(
kind: Kind.first,
name: 'Tested organisation',
url: 'http://example.com',
region: Region.first,
contact: 'contact@example.com',
submitter: 'contact@example.com'
)
end
assert_no_difference 'ActionMailer::Base.deliveries.size' do
Orga.create!(
kind: Kind.first,
name: 'Tested organisation',