Manage publicities
This commit is contained in:
+2
-1
@@ -8,7 +8,8 @@
|
|||||||
/.bundle
|
/.bundle
|
||||||
/.rspec
|
/.rspec
|
||||||
.ruby-version
|
.ruby-version
|
||||||
|
.env
|
||||||
|
/avatars
|
||||||
# Ignore all logfiles and tempfiles.
|
# Ignore all logfiles and tempfiles.
|
||||||
/log/*
|
/log/*
|
||||||
!/log/.keep
|
!/log/.keep
|
||||||
|
|||||||
@@ -35,12 +35,15 @@ $font-size-h3: floor($font-size-base * 1.2)
|
|||||||
.alert-notice
|
.alert-notice
|
||||||
@extend .alert-info
|
@extend .alert-info
|
||||||
|
|
||||||
|
body.admin
|
||||||
|
background: repeating-linear-gradient(45deg, yellow, yellow 50px, black 50px, black 100px)
|
||||||
|
|
||||||
body
|
body
|
||||||
> .container
|
> .container
|
||||||
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19)
|
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19)
|
||||||
padding: 20px
|
padding: 20px
|
||||||
margin-top: 10px
|
margin-top: 10px
|
||||||
|
background: #FFF
|
||||||
header
|
header
|
||||||
h1
|
h1
|
||||||
font-size: 20px
|
font-size: 20px
|
||||||
|
|||||||
@@ -1,5 +1,15 @@
|
|||||||
module Admin
|
module Admin
|
||||||
class ApplicationController < ::ApplicationController
|
class ApplicationController < ::ApplicationController
|
||||||
http_basic_authenticate_with name: 'admin', password: ENV['ADMIN_PASSWORD'] unless Rails.env.development?
|
before_action :authenticate_supporter!
|
||||||
|
before_action :authenticate_admin!
|
||||||
|
|
||||||
|
def authenticate_admin!
|
||||||
|
return true if current_supporter.admin?
|
||||||
|
head(:forbidden)
|
||||||
|
end
|
||||||
|
|
||||||
|
def admin_area
|
||||||
|
true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
module Admin
|
||||||
|
class PublicitiesController < Admin::ApplicationController
|
||||||
|
def index
|
||||||
|
@pending = Supporter.where('publicity.state' => :pending).asc(:created_at)
|
||||||
|
@active = Supporter.where('publicity.state' => :approved).asc(:created_at)
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit
|
||||||
|
@publicity = Supporter.find(params[:id]).publicity
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
@publicity = Supporter.find(params[:id]).publicity
|
||||||
|
return redirect_to(admin_publicities_path) if @publicity.update_attributes(publicity_params)
|
||||||
|
render :edit
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
current_supporter.publicity&.destroy
|
||||||
|
redirect_to(admin_publicities_path)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def publicity_params
|
||||||
|
params.require(:publicity).permit(:organisation, :statement, :avatar, :state)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -29,6 +29,10 @@ class ApplicationController < ActionController::Base
|
|||||||
options.merge locale: I18n.locale
|
options.merge locale: I18n.locale
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def admin_area
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def configure_permitted_parameters
|
def configure_permitted_parameters
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ class Supporter
|
|||||||
## Database authenticatable
|
## Database authenticatable
|
||||||
field :email, type: String, default: ''
|
field :email, type: String, default: ''
|
||||||
field :encrypted_password, type: String, default: ''
|
field :encrypted_password, type: String, default: ''
|
||||||
|
field :admin, type: Boolean, default: false
|
||||||
|
|
||||||
## Recoverable
|
## Recoverable
|
||||||
field :reset_password_token, type: String
|
field :reset_password_token, type: String
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
h1= title "#{t('.title')} #{@publicity.supporter.first_name} #{@publicity.supporter.last_name}, #{@publicity.supporter.city}"
|
||||||
|
= simple_form_for(@publicity, url: admin_publicity_path(@publicity.supporter)) do |form|
|
||||||
|
.form-group
|
||||||
|
= "#{@publicity.supporter.first_name} #{@publicity.supporter.last_name}, #{@publicity.supporter.city}"
|
||||||
|
|
||||||
|
= form.input :organisation, required: false
|
||||||
|
= form.input :statement, as: :text, required: false
|
||||||
|
= form.input :avatar, as: :file, required: false
|
||||||
|
- if @publicity.avatar
|
||||||
|
.form-group
|
||||||
|
= image_tag(@publicity.avatar.url(:medium))
|
||||||
|
= form.input :state, as: :radio_buttons, collection: t('publicity_states').map{ |x| [x.first, raw(x.last)]}, label_method: :last, value_method: :first, required: false
|
||||||
|
= form.submit t('shared.save'), class: 'btn btn-primary'
|
||||||
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
= render 'form'
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
h1 = title t('.title')
|
||||||
|
table.table
|
||||||
|
tbody
|
||||||
|
- @pending.each do | supporter |
|
||||||
|
tr
|
||||||
|
td
|
||||||
|
= "#{supporter.first_name} #{supporter.last_name}"
|
||||||
|
br
|
||||||
|
= supporter.city
|
||||||
|
br
|
||||||
|
= mail_to supporter.email, supporter.email
|
||||||
|
br
|
||||||
|
= supporter.publicity.organisation
|
||||||
|
td width="50%" = supporter.publicity.statement
|
||||||
|
td = image_tag(supporter.publicity.avatar.url(:small))
|
||||||
|
td = link_to t('shared.edit'), edit_admin_publicity_path(supporter)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ html lang="#{I18n.locale}"
|
|||||||
meta content="/ms-icon-144x144.png" name="msapplication-TileImage" /
|
meta content="/ms-icon-144x144.png" name="msapplication-TileImage" /
|
||||||
meta content="#ffffff" name="theme-color" /
|
meta content="#ffffff" name="theme-color" /
|
||||||
|
|
||||||
body
|
body class="#{'admin' if controller.admin_area}"
|
||||||
javascript:
|
javascript:
|
||||||
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
||||||
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
||||||
|
|||||||
@@ -11,3 +11,6 @@
|
|||||||
= navbar_item t('.sponsoring'), sponsoring_path
|
= navbar_item t('.sponsoring'), sponsoring_path
|
||||||
= navbar_item t('.sign_in'), new_supporter_session_path unless supporter_signed_in?
|
= navbar_item t('.sign_in'), new_supporter_session_path unless supporter_signed_in?
|
||||||
= navbar_item t('.sign_out'), destroy_supporter_session_path, nil, 'data-method' => :delete if supporter_signed_in?
|
= navbar_item t('.sign_out'), destroy_supporter_session_path, nil, 'data-method' => :delete if supporter_signed_in?
|
||||||
|
- if supporter_signed_in? && current_supporter.admin?
|
||||||
|
= navbar_dropdown t('admin.title') do
|
||||||
|
= navbar_item t('admin.publicities.index.title'), admin_publicities_path
|
||||||
|
|||||||
@@ -6,10 +6,7 @@
|
|||||||
.panel-body
|
.panel-body
|
||||||
dl.dl-horizontal
|
dl.dl-horizontal
|
||||||
dt = Publicity.human_attribute_name(:status)
|
dt = Publicity.human_attribute_name(:status)
|
||||||
- if current_supporter.publicity.state == 'pending'
|
dd= t("publicity_states.#{current_supporter.publicity.state}")
|
||||||
dd.text-danger = t('.pending')
|
|
||||||
- if current_supporter.publicity.state == 'approved'
|
|
||||||
dd.text-success = t('.pending')
|
|
||||||
- unless current_supporter.publicity.organisation.blank?
|
- unless current_supporter.publicity.organisation.blank?
|
||||||
dt = Publicity.human_attribute_name(:organisation)
|
dt = Publicity.human_attribute_name(:organisation)
|
||||||
dd = current_supporter.publicity.organisation
|
dd = current_supporter.publicity.organisation
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
de:
|
||||||
|
admin:
|
||||||
|
title: Administration
|
||||||
|
publicities:
|
||||||
|
index:
|
||||||
|
title: Unveröffentlichte Statements
|
||||||
|
form:
|
||||||
|
title: Statement
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fr:
|
||||||
|
admin:
|
||||||
|
title: Administration
|
||||||
|
publicities:
|
||||||
|
index:
|
||||||
|
title: Déclarations non publiées
|
||||||
|
form:
|
||||||
|
title: Déclaration
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
it:
|
||||||
|
admin:
|
||||||
|
title: Amministrazione
|
||||||
|
publicities:
|
||||||
|
index:
|
||||||
|
title: Dichiarazioni non pubblicati
|
||||||
|
form:
|
||||||
|
title: Dichiarazione
|
||||||
@@ -17,6 +17,8 @@ de:
|
|||||||
numbers: Zahlen
|
numbers: Zahlen
|
||||||
|
|
||||||
are_you_sure: Bist du sicher?
|
are_you_sure: Bist du sicher?
|
||||||
|
edit: Bearbeiten
|
||||||
|
save: Speichern
|
||||||
|
|
||||||
counter:
|
counter:
|
||||||
supporters: "Unterstützer:"
|
supporters: "Unterstützer:"
|
||||||
@@ -39,6 +41,11 @@ de:
|
|||||||
middle: Ich bin 30 bis 64 Jahre alt
|
middle: Ich bin 30 bis 64 Jahre alt
|
||||||
retired: Ich bin über 64 Jahre alt
|
retired: Ich bin über 64 Jahre alt
|
||||||
|
|
||||||
|
publicity_states:
|
||||||
|
pending: Die Veröffentlichung wurde noch nicht genehmigt
|
||||||
|
approved: Das Statement wurde Veröffentlicht
|
||||||
|
declined: Das Statement wurde abgelehnt
|
||||||
|
|
||||||
languages:
|
languages:
|
||||||
de: Deutsch
|
de: Deutsch
|
||||||
fr: Français
|
fr: Français
|
||||||
@@ -64,8 +71,6 @@ de:
|
|||||||
title: Mein Statement
|
title: Mein Statement
|
||||||
renew: Statement neu einreichen
|
renew: Statement neu einreichen
|
||||||
delete: Statement löschen
|
delete: Statement löschen
|
||||||
pending: Die Veröffentlichung wurde noch nicht genehmigt
|
|
||||||
approved: Das statement wurde Veröffentlicht
|
|
||||||
create_publicity: Deine Meinung zählt, darum bitten wir dir hier die Möglichkeit öffentlich deine Meinung zur Cannabis-Initiative kundzutun. Gib ein Starkes Statement ab und zeig dein Gesicht! Meine Unterstützung öffentlich kundtun ...
|
create_publicity: Deine Meinung zählt, darum bitten wir dir hier die Möglichkeit öffentlich deine Meinung zur Cannabis-Initiative kundzutun. Gib ein Starkes Statement ab und zeig dein Gesicht! Meine Unterstützung öffentlich kundtun ...
|
||||||
|
|
||||||
create:
|
create:
|
||||||
@@ -125,7 +130,7 @@ de:
|
|||||||
password_confirmation: Passwort bestätigen
|
password_confirmation: Passwort bestätigen
|
||||||
current_password: Aktuelles Passwort
|
current_password: Aktuelles Passwort
|
||||||
publicity:
|
publicity:
|
||||||
status: Status
|
state: Status
|
||||||
organisation: Organisation
|
organisation: Organisation
|
||||||
statement: Statement
|
statement: Statement
|
||||||
avatar: Bild
|
avatar: Bild
|
||||||
@@ -22,6 +22,8 @@ fr:
|
|||||||
numbers: Chiffres (en allemand)
|
numbers: Chiffres (en allemand)
|
||||||
|
|
||||||
are_you_sure: Tu es sûre?
|
are_you_sure: Tu es sûre?
|
||||||
|
edit: Éditer
|
||||||
|
save: Sauver
|
||||||
|
|
||||||
welcome_email:
|
welcome_email:
|
||||||
subject: Merci beaucoup pour ton soutien!
|
subject: Merci beaucoup pour ton soutien!
|
||||||
@@ -38,6 +40,11 @@ fr:
|
|||||||
middle: J’ai entre 30 et 64 ans
|
middle: J’ai entre 30 et 64 ans
|
||||||
retired: J’ai plus que 64 ans
|
retired: J’ai plus que 64 ans
|
||||||
|
|
||||||
|
publicity_states:
|
||||||
|
pending: La publication n'a pas été approuvé
|
||||||
|
approved: La déclaration a été publiée
|
||||||
|
declined: La déclaration a été rejetée
|
||||||
|
|
||||||
languages:
|
languages:
|
||||||
de: Deutsch
|
de: Deutsch
|
||||||
fr: Français
|
fr: Français
|
||||||
@@ -56,12 +63,11 @@ fr:
|
|||||||
city: Hinterpfupfikon
|
city: Hinterpfupfikon
|
||||||
zip: "4200"
|
zip: "4200"
|
||||||
email: hans.muster@hanflegal.ch
|
email: hans.muster@hanflegal.ch
|
||||||
|
|
||||||
publicity:
|
publicity:
|
||||||
title: Ma déclaration
|
title: Ma déclaration
|
||||||
renew: resoumettre déclaration
|
renew: resoumettre déclaration
|
||||||
delete: supprimer déclaration
|
delete: supprimer déclaration
|
||||||
pending: La publication n'a pas été approuvé
|
|
||||||
approved: La déclaration a été publiée
|
|
||||||
create_publicity: Votre opinion compte, nous vous demandons ici d'exprimer publiquement votre avis sur initiative de cannabis possible. Rendre public mon soutien ...
|
create_publicity: Votre opinion compte, nous vous demandons ici d'exprimer publiquement votre avis sur initiative de cannabis possible. Rendre public mon soutien ...
|
||||||
|
|
||||||
create:
|
create:
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ it:
|
|||||||
amount_of_supporters: Al momento abbiamo %{amount} sostenitori.
|
amount_of_supporters: Al momento abbiamo %{amount} sostenitori.
|
||||||
|
|
||||||
are_you_sure: Sei sicuro?
|
are_you_sure: Sei sicuro?
|
||||||
|
edit: Modifica
|
||||||
|
save: Salvare
|
||||||
|
|
||||||
welcome_email:
|
welcome_email:
|
||||||
subject: Grazie mille per il tuo sostegno!
|
subject: Grazie mille per il tuo sostegno!
|
||||||
@@ -39,6 +41,11 @@ it:
|
|||||||
middle: Ho tra i 30 ed i 64 anni
|
middle: Ho tra i 30 ed i 64 anni
|
||||||
retired: Ho più di 64 anni
|
retired: Ho più di 64 anni
|
||||||
|
|
||||||
|
publicity_states:
|
||||||
|
pending: La pubblicazione non è stato approvato
|
||||||
|
approved: La dichiarazione è stata rilasciata
|
||||||
|
declined: La dichiarazione è stata respinta
|
||||||
|
|
||||||
languages:
|
languages:
|
||||||
de: Deutsch
|
de: Deutsch
|
||||||
fr: Français
|
fr: Français
|
||||||
@@ -63,8 +70,6 @@ it:
|
|||||||
title: La mia dichiarazione
|
title: La mia dichiarazione
|
||||||
renew: Ripresentare Statement
|
renew: Ripresentare Statement
|
||||||
delete: Eliminare la dichiarazione
|
delete: Eliminare la dichiarazione
|
||||||
pending: La pubblicazione non è stato approvato
|
|
||||||
approved: La dichiarazione è stata rilasciata
|
|
||||||
create_publicity: La tua opinione conta, quindi vi chiediamo qui pubblicamente esprimere la tua opinione su iniziativa di cannabis possibile. Girare in una dichiarazione forte e mostrare il tuo volto! Il mio supporto rendere pubblico ...
|
create_publicity: La tua opinione conta, quindi vi chiediamo qui pubblicamente esprimere la tua opinione su iniziativa di cannabis possibile. Girare in una dichiarazione forte e mostrare il tuo volto! Il mio supporto rendere pubblico ...
|
||||||
|
|
||||||
create:
|
create:
|
||||||
|
|||||||
+3
-2
@@ -2,12 +2,11 @@ Rails.application.routes.draw do
|
|||||||
devise_for :supporters
|
devise_for :supporters
|
||||||
root to: 'supporters#new'
|
root to: 'supporters#new'
|
||||||
|
|
||||||
mount RailsAdmin::Engine => '/admin', as: 'rails_admin'
|
|
||||||
|
|
||||||
get "/pages/:page" => "pages#show"
|
get "/pages/:page" => "pages#show"
|
||||||
|
|
||||||
namespace :admin do
|
namespace :admin do
|
||||||
get '/map', to: 'pages#map', as: :map
|
get '/map', to: 'pages#map', as: :map
|
||||||
|
resources :publicities
|
||||||
# resources :supporters, only: :index
|
# resources :supporters, only: :index
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -28,4 +27,6 @@ Rails.application.routes.draw do
|
|||||||
get '/thanks', to: 'pages#thanks', as: :thanks
|
get '/thanks', to: 'pages#thanks', as: :thanks
|
||||||
get '/spenden', to: 'pages#spenden', as: :spenden
|
get '/spenden', to: 'pages#spenden', as: :spenden
|
||||||
end
|
end
|
||||||
|
|
||||||
|
mount RailsAdmin::Engine => '/admin', as: 'rails_admin'
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
feature 'Publicity' do
|
feature 'Publicity' do
|
||||||
let(:supporter) { create :supporter }
|
let(:supporter) { create :supporter, first_name: 'Hans', last_name: 'Muster' }
|
||||||
|
let(:admin) { create :supporter, admin: true }
|
||||||
|
|
||||||
before { sign_in(supporter) }
|
before { sign_in(supporter) }
|
||||||
|
|
||||||
@@ -38,4 +39,37 @@ feature 'Publicity' do
|
|||||||
expect(page).to have_content 'Besten Dank die Daten werden überprüft.'
|
expect(page).to have_content 'Besten Dank die Daten werden überprüft.'
|
||||||
expect(page).to have_content 'Die Veröffentlichung wurde noch nicht genehmigt'
|
expect(page).to have_content 'Die Veröffentlichung wurde noch nicht genehmigt'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
scenario 'non admin users cannot manage pending publicities' do
|
||||||
|
visit admin_publicities_path
|
||||||
|
expect(page.status_code).to eq 403
|
||||||
|
end
|
||||||
|
context 'management' do
|
||||||
|
|
||||||
|
|
||||||
|
before { sign_in(admin) }
|
||||||
|
|
||||||
|
scenario 'an administrator approves a pending announcement' do
|
||||||
|
create :publicity, state: :pending, supporter: supporter
|
||||||
|
|
||||||
|
# Already declined, so we don't list it'
|
||||||
|
create :publicity, state: :declined, supporter: create(:supporter, first_name: 'Donald', last_name: 'Trump')
|
||||||
|
|
||||||
|
visit admin_publicities_path
|
||||||
|
|
||||||
|
expect(page).to have_content 'Hans Muster'
|
||||||
|
expect(page).not_to have_content 'Donald Trump'
|
||||||
|
|
||||||
|
click_link 'Bearbeiten'
|
||||||
|
|
||||||
|
fill_in 'Organisation', with: 'Free Hemp Association'
|
||||||
|
fill_in 'Statement', with: 'Marihuana ist die Heilung der Nation, Alkohol die Zerstörung.'
|
||||||
|
attach_file('publicity_avatar', "#{Rails.root}/spec/support/fixtures/image.jpg")
|
||||||
|
choose 'Das Statement wurde Veröffentlicht'
|
||||||
|
|
||||||
|
click_button 'Speichern'
|
||||||
|
|
||||||
|
expect(page).not_to have_content 'Hans Muster'
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
Reference in New Issue
Block a user