From 40e367734cb03699092e3709f0a3109dd9874938 Mon Sep 17 00:00:00 2001 From: echarp Date: Sat, 26 Dec 2015 23:32:04 +0100 Subject: [PATCH] =?UTF-8?q?Champs=20"active"=20et=20"description"=20ajout?= =?UTF-8?q?=C3=A9s=20aux=20organisations.=20Refs=20#12?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/assets/javascripts/tinymce.coffee.erb | 2 +- app/assets/stylesheets/form.css.sass | 4 ++ app/controllers/orgas_controller.rb | 4 +- app/mailers/orga_mailer.rb | 2 + app/models/orga.rb | 12 ++-- app/views/events/_form.html.haml | 2 +- app/views/orgas/_form.html.haml | 6 ++ app/views/orgas/show.html.haml | 37 ++++++---- app/views/orgas/show.text.haml | 18 +++-- config/database.yml | 5 +- config/locales/models/en.yml | 4 ++ config/locales/models/fr.yml | 4 ++ config/locales/views/en.yml | 9 +-- config/locales/views/fr.yml | 5 +- ...25194836_add_active_description_to_orga.rb | 7 ++ db/schema.rb | 72 ++++++++----------- test/controllers/orgas_controller_test.rb | 3 +- test/models/orga_test.rb | 11 +++ 18 files changed, 123 insertions(+), 84 deletions(-) create mode 100644 db/migrate/20151225194836_add_active_description_to_orga.rb diff --git a/app/assets/javascripts/tinymce.coffee.erb b/app/assets/javascripts/tinymce.coffee.erb index 2ecc890a..260a14a8 100644 --- a/app/assets/javascripts/tinymce.coffee.erb +++ b/app/assets/javascripts/tinymce.coffee.erb @@ -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, diff --git a/app/assets/stylesheets/form.css.sass b/app/assets/stylesheets/form.css.sass index 007317eb..a1e98004 100644 --- a/app/assets/stylesheets/form.css.sass +++ b/app/assets/stylesheets/form.css.sass @@ -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 diff --git a/app/controllers/orgas_controller.rb b/app/controllers/orgas_controller.rb index 6facc582..ee90de7a 100644 --- a/app/controllers/orgas_controller.rb +++ b/app/controllers/orgas_controller.rb @@ -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 diff --git a/app/mailers/orga_mailer.rb b/app/mailers/orga_mailer.rb index abe313f9..65823018 100644 --- a/app/mailers/orga_mailer.rb +++ b/app/mailers/orga_mailer.rb @@ -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: # diff --git a/app/models/orga.rb b/app/models/orga.rb index 98a14813..e30bfb8c 100644 --- a/app/models/orga.rb +++ b/app/models/orga.rb @@ -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! diff --git a/app/views/events/_form.html.haml b/app/views/events/_form.html.haml index 94bb7290..e4d85edf 100644 --- a/app/views/events/_form.html.haml +++ b/app/views/events/_form.html.haml @@ -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 diff --git a/app/views/orgas/_form.html.haml b/app/views/orgas/_form.html.haml index c0f8e1ba..6605e000 100644 --- a/app/views/orgas/_form.html.haml +++ b/app/views/orgas/_form.html.haml @@ -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 diff --git a/app/views/orgas/show.html.haml b/app/views/orgas/show.html.haml index fd208da9..ce5291c5 100644 --- a/app/views/orgas/show.html.haml +++ b/app/views/orgas/show.html.haml @@ -44,18 +44,23 @@ %em.fa.fa-li.fa-dot-circle-o GeoJSON - - if user_signed_in? - %h1 - %em.fa.fa-wrench - = t '.actions' - %h2 - = link_to edit_orga_path @orga do - %em.fa.fa-lg.fa-pencil - = t '.edit' - %h2 - = link_to cancel_orga_path @orga do - %em.fa.fa-lg.fa-thumbs-down - = t '.cancel' + %h1 + %em.fa.fa-wrench + = t '.actions' + %h2 + = link_to edit_orga_path @orga do + %em.fa.fa-lg.fa-pencil + = t '.edit' + %h2 + = link_to cancel_orga_path @orga do + %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? @@ -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' diff --git a/app/views/orgas/show.text.haml b/app/views/orgas/show.text.haml index 708383e5..0974ac9f 100644 --- a/app/views/orgas/show.text.haml +++ b/app/views/orgas/show.text.haml @@ -1,9 +1,13 @@ ===================================================== -#{Orga.human_attribute_name(:kind).concat(':').ljust 12 } #{@orga.kind.name} -#{Orga.human_attribute_name(:name).concat(':').ljust 12 } #{@orga.name} -#{Orga.human_attribute_name(:region).concat(':').ljust 12 } #{@orga.region} -#{Orga.human_attribute_name(:url).concat(':').ljust 12 } #{@orga.url} -#{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(:kind).concat(':').ljust 12 } #{@orga.kind.name} +#{Orga.human_attribute_name(:name).concat(':').ljust 12 } #{@orga.name} +#{Orga.human_attribute_name(:region).concat(':').ljust 12 } #{@orga.region} +#{Orga.human_attribute_name(:url).concat(':').ljust 12 } #{@orga.url} +#{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(/ /, '')).gsub /^/, ' ' ===================================================== diff --git a/config/database.yml b/config/database.yml index beb7f232..f663b585 100644 --- a/config/database.yml +++ b/config/database.yml @@ -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 diff --git a/config/locales/models/en.yml b/config/locales/models/en.yml index 27e69224..1f27ef9d 100644 --- a/config/locales/models/en.yml +++ b/config/locales/models/en.yml @@ -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 diff --git a/config/locales/models/fr.yml b/config/locales/models/fr.yml index ff9a3e8d..e494faf9 100644 --- a/config/locales/models/fr.yml +++ b/config/locales/models/fr.yml @@ -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 diff --git a/config/locales/views/en.yml b/config/locales/views/en.yml index 3c84da72..d4ad680f 100644 --- a/config/locales/views/en.yml +++ b/config/locales/views/en.yml @@ -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 diff --git a/config/locales/views/fr.yml b/config/locales/views/fr.yml index 7ce1154e..6ebbc8ca 100644 --- a/config/locales/views/fr.yml +++ b/config/locales/views/fr.yml @@ -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 diff --git a/db/migrate/20151225194836_add_active_description_to_orga.rb b/db/migrate/20151225194836_add_active_description_to_orga.rb new file mode 100644 index 00000000..d7c7a0f9 --- /dev/null +++ b/db/migrate/20151225194836_add_active_description_to_orga.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index d73f3280..539b1844 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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 @@ -100,54 +100,38 @@ ActiveRecord::Schema.define(version: 20151022214618) do end create_table "orgas", force: :cascade do |t| - t.integer "region_id", limit: 4, default: 0, null: false + t.integer "region_id", limit: 4, default: 0, null: false t.integer "department", limit: 4 - t.string "name", limit: 255, default: "", null: false - t.string "url", limit: 255, default: "", null: false - t.string "city", limit: 255, default: "", null: false + t.string "name", limit: 255, default: "", null: false + t.string "url", limit: 255, default: "", null: false + t.string "city", limit: 255, default: "", null: false t.integer "kind_id", limit: 4 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 diff --git a/test/controllers/orgas_controller_test.rb b/test/controllers/orgas_controller_test.rb index a1d1b0aa..ca730ba1 100644 --- a/test/controllers/orgas_controller_test.rb +++ b/test/controllers/orgas_controller_test.rb @@ -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 diff --git a/test/models/orga_test.rb b/test/models/orga_test.rb index d35f6d7c..9524f9a2 100644 --- a/test/models/orga_test.rb +++ b/test/models/orga_test.rb @@ -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',