Browse Source

Possibility to preview organisations

remotes/origin/master
echarp 2 years ago
parent
commit
368301945a
  1. 21
      app/controllers/orgas_controller.rb
  2. 4
      app/views/orgas/_form.html.haml
  3. 6
      app/views/orgas/edit.html.haml
  4. 7
      app/views/orgas/new.html.haml
  5. 7
      config/locales/views/de.yml
  6. 8
      config/locales/views/en.yml
  7. 8
      config/locales/views/fr.yml
  8. 6
      config/locales/views/nl.yml
  9. 8
      config/locales/views/pt-BR.yml
  10. 2
      config/routes.rb
  11. 87
      test/controllers/orgas_controller_test.rb

21
app/controllers/orgas_controller.rb

@ -4,9 +4,10 @@ class OrgasController < ApplicationController
has_scope :near, type: :hash, using: %i[location distance]
has_scope :active, type: :boolean, default: true, allow_blank: true
before_action :set_orga, except: %i[index new create]
before_action :authenticate_user!, except: %i[index new create show],
unless: :check_secret
before_action :set_orga, if: -> { params[:id].present? }
before_action :authenticate_user!, if: -> { params[:id].present? },
unless: :check_secret,
except: %i[show]
def index
@unfiltered_orgas = apply_scopes(Orga.moderated)
@ -22,6 +23,13 @@ class OrgasController < ApplicationController
@orga = Orga.new region_id: session[:region]
end
# POST /orgas/preview
def preview_create
@orga = Orga.new orga_params
@orga.valid?
render action: :new
end
# POST /orgas
# POST /orgas.json
def create
@ -42,6 +50,13 @@ class OrgasController < ApplicationController
@events_past = Event.moderated.past.tag @orga.name_as_tag
end
# PATCH/PUT /orgas/1/preview
def preview
@orga.attributes = orga_params
@orga.valid?
render action: :edit
end
# PATCH/PUT /orgas/1
# PATCH/PUT /orgas/1.json
def update

4
app/views/orgas/_form.html.haml

@ -70,6 +70,10 @@
= f.check_box :active
.actions
= f.button formaction: :preview do
%em.fa.fa-eye
= t '.visualise'
= f.button do
%em.fa.fa-check
= t '.save'

6
app/views/orgas/edit.html.haml

@ -2,6 +2,12 @@
%em.fa.fa-users
= title t '.title'
%fieldset
%legend
%em.fa.fa-eye
= t '.preview'
= render template: '/orgas/show'
%fieldset
%legend
%em.fa.fa-edit

7
app/views/orgas/new.html.haml

@ -2,6 +2,13 @@
%em.fa.fa-users
= title t '.title'
- if @orga.description
%fieldset
%legend
%em.fa.fa-eye
= t '.preview'
= render template: '/orgas/show'
%fieldset
%legend
%em.fa.fa-edit

7
config/locales/views/de.yml

@ -37,7 +37,6 @@ de:
map: Karte
show:
at: in
dateAndPlace: Datum und Veranstaltungsort
noMap: Mit dieser Adresse konnte keine Karte verknüpft werden. Sie können
andere Syntax hier testen
infos: Informationen
@ -50,7 +49,6 @@ de:
cancel: Veranstaltung löschen
html:
at: in
dateAndPlace: Datum und Veranstaltungsort
description: Beschreibung
infos: Informationen
new:
@ -286,6 +284,7 @@ erneut zu übermitteln."
edit: Bearbeiten
cancel: Löschen
show:
infos: Informationen
future: In kurze Zeit
past: In der Vergangenheit
count:
@ -294,11 +293,13 @@ erneut zu übermitteln."
other: "%{count} Veranstaltung(en)"
new:
title: Organisation
preview: Vorschau
edit: Erstellung
create:
ok: Die Organisation wurde moderiert
edit:
title: Organisation
preview: Vorschau
edit: Bearbeitung
forbidden: Sie sind nicht berechtigt, diese Organisation zu bearbeiten
update:
@ -317,8 +318,8 @@ erneut zu übermitteln."
nur vom Absender geändert werden, der einen geheimen verbindlichen Link erhält ...
tags_helper: Durch Leerzeichen getrennt, bestehend aus Buchstaben, Zahlen
und Bindestrichen.
save: Speichern
visualise: Anzeigen
validate:
title: Bearbeitung der Organisation
ok: Ja

8
config/locales/views/en.yml

@ -37,7 +37,6 @@ en:
map: Map
show:
at: At
dateAndPlace: Date and place
noMap: No OpenStreetMap map could be associated to this address. You can
test other syntaxes here
infos: Informations
@ -50,7 +49,6 @@ en:
cancel: Cancel event
html:
at: At
dateAndPlace: Date and place
description: Description
infos: Informations
new:
@ -109,7 +107,7 @@ it more readable or agreable."
rule_helper: The "Nth day of the month", for example "1st thursday of the
month" ou "3rd saturday of the month", is deducted from the very first
event
save: Validate
save: Save
visualise: Visualise
cancel:
title: Cancel event
@ -273,6 +271,7 @@ description."
edit: Edit
cancel: Delete
show:
infos: Informations
future: Coming
past: In the past
count:
@ -281,11 +280,13 @@ description."
other: "%{count} events"
new:
title: Organisation
preview: Preview
edit: Creation
create:
ok: Organisation has been submitted to moderation
edit:
title: Organisation
preview: Preview
edit: Edition
forbidden: You are not authorised to modify this organisation
update:
@ -305,6 +306,7 @@ description."
will receive a secret edition link...
tags_helper: Separated with spaces, contain letters, numbers and hyphens
save: Save
visualise: Visualise
validate:
title: Organisation moderation
ok: Yes

8
config/locales/views/fr.yml

@ -37,7 +37,6 @@ fr:
map: Carte
show:
at: À
dateAndPlace: Date et lieu
noMap: Aucune carte n'a pu être associée à cette adresse. Vous pouvez
tester d'autres syntaxes ici
infos: Informations
@ -50,7 +49,6 @@ fr:
cancel: Annuler événement
html:
at: À
dateAndPlace: Date et lieu
description: Description
infos: Informations
new:
@ -124,7 +122,7 @@ procédure à l'aide d'un [script](/adl-submit.py)"
rule_helper: Le "Nème jour du mois", par exemple "1er jeudi du mois" ou
"3ème samedi du mois", est déduit à partir du tout premier événement
save: Valider
visualise: Visualiser
visualise: Prévisualiser
cancel:
title: Annulation de l'événement
already_moderated: 'Événement déjà modéré: cette annulation le supprimera'
@ -292,6 +290,7 @@ description plus complète."
edit: Éditer
cancel: Supprimer
show:
infos: Informations
future: Prochainement
past: Dans le passé
count:
@ -300,11 +299,13 @@ description plus complète."
other: "%{count} événements"
new:
title: Organisation
preview: Prévisualisation
edit: Création
create:
ok: L'organisation a été soumise à modération
edit:
title: Organisation
preview: Prévisualisation
edit: Édition
forbidden: Vous n'êtes pas autorisé à modifier cette organisation
update:
@ -324,6 +325,7 @@ description plus complète."
tags_helper: Séparés par des espaces, constitués de lettres, chiffres
et tirets
save: Envoyer
visualise: Prévisualiser
validate:
title: Modération d'organisation
ok: Oui

6
config/locales/views/nl.yml

@ -37,7 +37,6 @@ nl:
map: Kaart
show:
at: in
dateAndPlace: Datum en evenement plaats
noMap: Aan dit adres kan geen kaart gekoppeld worden. Andere syntaxen
kunnen hier getestet worden
infos: Informatie
@ -50,7 +49,6 @@ nl:
cancel: Evenement verwijderen
html:
at: bij
dateAndPlace: Datum en plaats
description: Beschrijving
infos: Informatie
new:
@ -288,6 +286,7 @@ vollediger beschrijving."
edit: Bewerken
cancel: Verwijderen
show:
infos: Informatie
future: Binnenkort
past: In het verleden
count:
@ -296,11 +295,13 @@ vollediger beschrijving."
other: "%{count} evenementen"
new:
title: Organisatie
preview: Voorvertoning
edit: Creatie
create:
ok: Registratie van de organisatie werd onder evaluatie gesteld
edit:
title: Organisation
preview: Voorvertoning
edit: Bewerken
forbidden: U bent niet gemachtigd om deze organisatie te bewerken
update:
@ -321,6 +322,7 @@ vollediger beschrijving."
tags_helper: Gescheiden door spaties, bestaande uit letters, cijfers en
streepjes
save: Opslaan
visualise: Visualiseren
validate:
title: Evaluatie van organisatie
ok: Ja

8
config/locales/views/pt-BR.yml

@ -37,7 +37,6 @@ pt-BR:
map: Mapa
show:
at: Em
dateAndPlace: Data e local
noMap: Não foi possível associar um mapa no OpenStreetMap a este endereço.
Você pode testar outras sintaxes aqui
infos: Informações
@ -50,7 +49,6 @@ pt-BR:
cancel: Cancelar evento
html:
at: Em
dateAndPlace: Data e local
description: Descrição
infos: Informações
new:
@ -106,7 +104,7 @@ completa, deixando o texto mais legível e agradável.
month" ou "3rd saturday of the month", is deducted from the very first
event
save: Enviar
visualise: Visualizar
visualise: Pré-visualização
cancel:
title: Cancelar o evento
already_moderated: 'Evento já publicado: este cancelamento irá
@ -266,6 +264,7 @@ descrição mais completa."
edit: Editar
cancel: Excluir
show:
infos: Informações
future: A realizar
past: Realizado
count:
@ -274,11 +273,13 @@ descrição mais completa."
other: "%{count} eventos"
new:
title: Organização
preview: Pré-visualização
edit: Criação
create:
ok: A organização foi enviada para moderação
edit:
title: Organização
preview: Prévisualisation
edit: Edição
forbidden: Você não está autorizado a alterar esta organização
update:
@ -298,6 +299,7 @@ descrição mais completa."
receberá um link secreto para edição.
tags_helper: Separado por espaço, contendo letras, número e hífens
save: Enviar
visualise: Pré-visualização
validate:
title: Confirma a aprovação desta organização?
ok: Sim

2
config/routes.rb

@ -20,6 +20,8 @@ Rails.application.routes.draw do
resources :maps, only: %i[index show]
resources :orgas do
get :cancel, :validate, :refuse, on: :member
post :preview, on: :collection, to: 'orgas#preview_create'
patch :preview, on: :member
put :accept, on: :member
end

87
test/controllers/orgas_controller_test.rb

@ -20,21 +20,30 @@ class OrgasControllerTest < ActionDispatch::IntegrationTest
assert_response :success
end
test 'should preview orga creation' do
assert_no_difference 'Orga.count' do
post preview_orgas_url, params: { orga: {
kind_id: @orga.kind_id, name: @orga.name,
city: @orga.city, region_id: @orga.region.id,
description: @orga.description,
url: @orga.url, contact: @orga.contact, tag_list: 'helo world'
} }
assert_empty assigns(:orga).errors
end
assert_response :success
end
test 'should create orga' do
assert_difference 'Orga.count' do
post orgas_url, params: {
orga: {
kind_id: @orga.kind_id,
name: @orga.name,
city: @orga.city,
region_id: @orga.region.id,
description: @orga.description,
url: @orga.url,
feed: @orga.feed,
contact: @orga.contact,
submitter: @orga.contact
}
}
post orgas_url, params: { orga: {
kind_id: @orga.kind_id, name: @orga.name,
city: @orga.city, region_id: @orga.region.id,
description: @orga.description,
url: @orga.url, feed: @orga.feed,
contact: @orga.contact, submitter: @orga.contact
} }
end
assert_redirected_to assigns(:orga)
@ -42,15 +51,13 @@ class OrgasControllerTest < ActionDispatch::IntegrationTest
test 'should create minimalist orga' do
assert_difference 'Orga.count' do
post orgas_url, params: {
orga: {
kind_id: @orga.kind_id,
name: @orga.name,
region_id: @orga.region.id,
description: @orga.description,
url: @orga.url
}
}
post orgas_url, params: { orga: {
kind_id: @orga.kind_id,
name: @orga.name,
region_id: @orga.region.id,
description: @orga.description,
url: @orga.url
} }
end
assert_redirected_to assigns(:orga)
@ -58,14 +65,12 @@ class OrgasControllerTest < ActionDispatch::IntegrationTest
test 'should create orga without content' do
assert_difference 'Orga.count' do
post orgas_url, params: {
orga: {
kind_id: @orga.kind_id,
name: @orga.name,
region_id: @orga.region.id,
url: @orga.url
}
}
post orgas_url, params: { orga: {
kind_id: @orga.kind_id,
name: @orga.name,
region_id: @orga.region.id,
url: @orga.url
} }
end
assert_redirected_to assigns(:orga)
@ -84,6 +89,18 @@ class OrgasControllerTest < ActionDispatch::IntegrationTest
assert_response :success
end
test 'should preview' do
assert_no_difference 'Orga.count' do
patch preview_orga_url(@orga), params: {
secret: @orga.secret, orga: { name: @orga.name }
}
assert_empty assigns(:orga).errors
end
assert_response :success
end
test 'should update orga' do
# Necessary to have the proper paper_trail version
@orga.update name: 'My Title'
@ -97,19 +114,13 @@ class OrgasControllerTest < ActionDispatch::IntegrationTest
end
test 'should not update orga' do
patch orga_url(@orga), params: {
orga: { name: nil }
}
patch orga_url(@orga), params: { orga: { name: nil } }
assert_redirected_to :new_user_session
end
test 'should not update orga without proper secret' do
patch orga_url(@orga), params: {
orga: {
name: 'hello world'
}
}
patch orga_url(@orga), params: { orga: { name: 'hello world' } }
assert_redirected_to :new_user_session
end

Loading…
Cancel
Save