From 927b1e8e5d40816e81a8988d153b6ee05d5d0034 Mon Sep 17 00:00:00 2001 From: Ana Date: Fri, 11 Mar 2016 00:21:39 +0100 Subject: [PATCH 001/163] Share with WhatsApp in debates --- Gemfile | 3 +++ Gemfile.lock | 3 +++ app/assets/stylesheets/application.scss | 4 +++- app/assets/stylesheets/participation.scss | 12 ++++++++++++ app/views/debates/show.html.erb | 7 ++++++- 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 573192fa8..cbe3d1ece 100644 --- a/Gemfile +++ b/Gemfile @@ -59,6 +59,9 @@ gem 'tolk' # Web interface for translations gem 'browser' gem 'turnout' gem 'redcarpet' + +gem 'font-awesome-sass', '~> 4.5.0' # icons + group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug' diff --git a/Gemfile.lock b/Gemfile.lock index fab1252d1..7726d1248 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -163,6 +163,8 @@ GEM i18n (~> 0.5) faraday (0.9.2) multipart-post (>= 1.2, < 3) + font-awesome-sass (4.5.0) + sass (>= 3.2) foundation-rails (6.2.0.1) railties (>= 3.1.0) sass (>= 3.3.0, < 3.5) @@ -457,6 +459,7 @@ DEPENDENCIES email_spec factory_girl_rails faker + font-awesome-sass (~> 4.5.0) foundation-rails foundation_rails_helper fuubar diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 822e4cd4c..445af82fb 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -11,4 +11,6 @@ @import "annotator.min"; @import "annotator_overrides"; @import "jquery-ui/datepicker"; -@import "datepicker_overrides"; \ No newline at end of file +@import "datepicker_overrides"; +@import "font-awesome-sprockets"; +@import "font-awesome"; diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index 182c52863..72b8c44e2 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -337,6 +337,18 @@ .debate-show, .proposal-show { + .social-share-button{ + display:inline; + } + + .whatsapp{ + margin-left: 0.5px; + color: white; + vertical-align: top; + background-color: #43d854; + padding: 7px 9.5px 7px 9.5px; + } + .edit-debate, .edit-proposal { margin-bottom: 0; } diff --git a/app/views/debates/show.html.erb b/app/views/debates/show.html.erb index eb3f5bbc0..935a785b0 100644 --- a/app/views/debates/show.html.erb +++ b/app/views/debates/show.html.erb @@ -54,8 +54,13 @@

<%= t("debates.show.share") %>

+
<%= social_share_button_tag(@debate.title) %> - + <% if browser.mobile? %> + + <%= icon('whatsapp', class: 'fa-2x whatsapp') %> + + <% end %> <% end %> From f866c7be8fdeba0c0218eefcd56e7b5751b431db Mon Sep 17 00:00:00 2001 From: Ana Date: Fri, 11 Mar 2016 00:25:29 +0100 Subject: [PATCH 002/163] Share with WhatsApp in proposals --- app/views/proposals/show.html.erb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/views/proposals/show.html.erb b/app/views/proposals/show.html.erb index 2b060d501..96b38fae9 100644 --- a/app/views/proposals/show.html.erb +++ b/app/views/proposals/show.html.erb @@ -86,7 +86,13 @@

<%= t("proposals.show.share") %>

+
<%= social_share_button_tag(@proposal.title) %> + <% if browser.mobile? %> + + <%= icon('whatsapp', class: 'fa-2x whatsapp') %> + + <% end %> From f4b7e0c14203989878c444cbcb0ffbc88e1475da Mon Sep 17 00:00:00 2001 From: Ana Date: Fri, 11 Mar 2016 00:34:07 +0100 Subject: [PATCH 003/163] Share with Whatsapp improvement --- app/assets/stylesheets/participation.scss | 2 +- app/views/debates/show.html.erb | 15 ++++++++------- app/views/proposals/show.html.erb | 15 ++++++++------- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index 72b8c44e2..a8ee508d6 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -337,7 +337,7 @@ .debate-show, .proposal-show { - .social-share-button{ + .social_share_full .social-share-button{ display:inline; } diff --git a/app/views/debates/show.html.erb b/app/views/debates/show.html.erb index 935a785b0..459561c10 100644 --- a/app/views/debates/show.html.erb +++ b/app/views/debates/show.html.erb @@ -54,13 +54,14 @@

<%= t("debates.show.share") %>

-
- <%= social_share_button_tag(@debate.title) %> - <% if browser.mobile? %> - - <%= icon('whatsapp', class: 'fa-2x whatsapp') %> - - <% end %> + <% end %> diff --git a/app/views/proposals/show.html.erb b/app/views/proposals/show.html.erb index 96b38fae9..58fef7bae 100644 --- a/app/views/proposals/show.html.erb +++ b/app/views/proposals/show.html.erb @@ -86,13 +86,14 @@

<%= t("proposals.show.share") %>

-
- <%= social_share_button_tag(@proposal.title) %> - <% if browser.mobile? %> - - <%= icon('whatsapp', class: 'fa-2x whatsapp') %> - - <% end %> + From 8119df26fb2321f71d181106633b1e19afb3064f Mon Sep 17 00:00:00 2001 From: Ana Date: Sat, 12 Mar 2016 22:20:35 +0100 Subject: [PATCH 004/163] Use of fontastic instead of font-awesome --- Gemfile | 2 -- Gemfile.lock | 3 --- app/assets/fonts/icons.eot | Bin 9564 -> 9904 bytes app/assets/fonts/icons.svg | 1 + app/assets/fonts/icons.ttf | Bin 9408 -> 9748 bytes app/assets/fonts/icons.woff | Bin 7496 -> 7800 bytes app/assets/stylesheets/application.scss | 2 -- app/assets/stylesheets/icons.scss | 3 +++ app/assets/stylesheets/participation.scss | 10 ++++++---- app/views/debates/show.html.erb | 4 ++-- app/views/proposals/show.html.erb | 4 ++-- 11 files changed, 14 insertions(+), 15 deletions(-) diff --git a/Gemfile b/Gemfile index cbe3d1ece..0d9f64f56 100644 --- a/Gemfile +++ b/Gemfile @@ -60,8 +60,6 @@ gem 'browser' gem 'turnout' gem 'redcarpet' -gem 'font-awesome-sass', '~> 4.5.0' # icons - group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug' diff --git a/Gemfile.lock b/Gemfile.lock index 7726d1248..fab1252d1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -163,8 +163,6 @@ GEM i18n (~> 0.5) faraday (0.9.2) multipart-post (>= 1.2, < 3) - font-awesome-sass (4.5.0) - sass (>= 3.2) foundation-rails (6.2.0.1) railties (>= 3.1.0) sass (>= 3.3.0, < 3.5) @@ -459,7 +457,6 @@ DEPENDENCIES email_spec factory_girl_rails faker - font-awesome-sass (~> 4.5.0) foundation-rails foundation_rails_helper fuubar diff --git a/app/assets/fonts/icons.eot b/app/assets/fonts/icons.eot index 7323d578fd97c45babb7d99ac69f377304b9e790..5fe0c1d3d094b8e011bd8776b56cf2100f7e7056 100644 GIT binary patch delta 781 zcmYjPPfXKL82{dD*N$#$_qQFgmC>!;SYXHoD+#b*1Wil?6O2K##8f~?I- zXcW2EQ`UlAs{w=lFQ|K`X71j!2XglS*bIQWJUwYm@Et8NCrA>j0x*Zzw1vhSGxOut z(~XyH0L%x()mdxVh81{=dJp2%oHaWsmG6H7(4HVSXU{JzK3*$52gvvlzXyUY-1c$R zb6x5?0v|;JV8?5t{;yJ~^Ij~@D^eis&Mw)xs=F5Vt?N5c4+Gdl_6Y#aZ@Nj^wqGzlLZ!a#H*9}$l>r^nWRHA@5{$qt z{8dFoR^(We=XfryWeX&0^pmn#?j>@`m7;&uSk(0?NSbB7XjX_>?(WJO?xVTAJckb6 zl*9ErMXm?dBYD&4?lLjbB$ZWn($Bm*0e-vZ<- z_y_A7`QMJ&&%nSK0py1z=Oz|#vpfT;XA%I4tx8WUF8KeSff=a21}M*wo>Q6Tnf_CO zfq_MWfkDRCoH6SI0|WCOAU`TMv7&&X zl3^=Q-U7&1$V<#k<+toS!@!^z0u;+D$S*E&Gr7pkz@T&l$lt-h2vh~c*+5^!^V@u7 z;AR2}Ffd%&Ys!yIGckb0Ie^sU)r@+KI+JfPUiJmr3RDEbGGK!k7?uEeAR}cMSQt8h zG#3L%3rMdYLoh=X(2pSC2xKQh*#EBq`5+w}li8TpFfwf3%*@RQRKNKEi>>TrOXW|j uCJed^hLa6cRGCe54JSva6ap# diff --git a/app/assets/fonts/icons.svg b/app/assets/fonts/icons.svg index e272b9550..51044c3e2 100644 --- a/app/assets/fonts/icons.svg +++ b/app/assets/fonts/icons.svg @@ -48,4 +48,5 @@ + diff --git a/app/assets/fonts/icons.ttf b/app/assets/fonts/icons.ttf index 4db54078da27f3f3a2e6576813fffc478c62c3e1..b0b1565817b71faba9fe7231ca4b2baec218a300 100644 GIT binary patch delta 767 zcmYL`PiWIn9LIm}rA@jtP5&p|)@EIrq+Quo*KW;VTT$F5!rX=%GNmYS&J|p@=n9)d zsO~0S#CjOhix&^FgE%}Zc<~|#0}(c_A`0FHdaA!v!51FyeZJrK`;y;#Z_hrSssjN4 zAKV27W+x}-&)u5d{sy4`LN$J7d}0zV0gL<@IXN?z%g-E^-vE#Wc%jSQCcL8Vw zwO7m5y4`GI66hb%_bjj6zHXn)+yiiF0Lo@%$-2hnx})eF;Vf1vOLfbYqi!t50MIJc z+9nUoPvn=#S69{+t!FzgdI6aC$mOcFX~P!0Mt>MNxoTCH{Kfkp0Mw_bt=enrwI|z! z=NKg*ziTyz4cfoU?koP$WAIWe132*5=sPR5g-2wJ^fgN4;G*tm&hNKoyj2abhvZyR z99-}aR{=agaSt#JvoHr+*s?QDwaEHQ&7$mPuvF^fZk zX~X$crCW@*&k>lsHhLQ;4NObmOv%@Dg34+Q%3RDz#{Jwm$D{XYCF)1L50V$?-86*9t zC51c)29$V@UN$m`&Tz2Ps120*^`5vAXq@jpb`L-w6dF^i&J6Sw8a4GMKH^t(fs*Wg eDODo8XQN`()-BtH#vLs|dKYa0kyj1_qTSKv5ZY7gsliNCq|_zXixw@DJ8E z^1mIkpMilf0>}?b&P^=fW_bow&m;g8Ta}(zT=4%t&?E+x8lXH!dQN4UXZlYC1_l-h z1_oK1jMT&wwi&CXfpT|%*eoL>wLXzWpNSQySp+Dcl95|d!Fih*XdvSTAU`1|KRI#X zj9DKT7?}3}`BAxv6$K2H3|oQn7C^p2USe)4zh&nc1_s3tpjci(esPJL$wh7k2BjlF z{tmF`fF8`=bbV7izs*+$ZYH2M28K&}P5B`-lPUisMq5Um$##sFeSy{hML}2wtdoIZ z36KX0AQ=W0h7KUj#lXS91cVF>ehk43RY1>zfFqEd2x0%f2IPZua7@l(TEob&S)7@h z5vYE%3X84m+QC4L((KVdBN4XGaxt>bI<_;A*#>p2{Wf`?6zf+as JK{(Nr9{_y5U@8Cr diff --git a/app/assets/fonts/icons.woff b/app/assets/fonts/icons.woff index 33d2d4dee85d5db357db665de1a95c7741bb1621..edcc9bc61d0fe59d992202df6dba2a316ddfd00d 100644 GIT binary patch delta 7679 zcmXw;WlS7Q*M=8gyx8Jeptwu1!WOqK?i6=-iga7t-CYV4cQ3lQJ1p*Qg%+oLJa6(% za{aik$(hN?Br`u|Ncc{a&b%e=a|*G%~e4L}Eg3{mIgd3AqYv-~T@s>h$(%^XaeUrQuj zb29*dQ1_?epQg2iiTSI$dv#2&2%vG&5?Q~>*QID)Gs!FT$WTs1Bx?tE?^pT$RVclp z2LvFUIhc6AE=U>lno<7;s|vu;#KGd#MZMAx+dtm9z#IgAs$**a|wL8Z=y6%RG&6GAD`lq z@)NFEn6VGU3Uk0`XP?|+$GLgV%I{R8UxqQWK z=P4c{^FpRja(43ly8p%c?YY>&dWN_C!Gw+|6(kC)c%ZKKE=EW6=272hwe~OC1-$KR z$yW=CDnDF<)_N!H(-0@KZ1m~o%x2m7Sit+`TY4*vDVl0c7Q7EELsd-aR8^kj{5`SU_%<7o9Wq-y*yVnQcTRnBrf(lH?z{!q3`iM)^uj2 zkk0FqK5*9W?mO>>uoYI)$o{<+eC-`Qify0OuuK#nfc|gKUj!Ee zHv?AN9e4JA93QBS!Z-&~w?}^`-`V=HcT$OiHo~Z5bHj3@awD7uAWqe%F-yj$kR9r1 z#f$s1+h3j6<9&svkry2&9q&B-O^FTef3re=J)Yk_Pdwh0S9SOd&QHw0_+Yz@zqH&G zF25j55L@z1f+ovpgL%BqgSGav>fK0Wf~K#mh4h(r zG4J(IXX4yqo8Ac%)T@s&XsTIgGL{vLL{u=bXewzQRYqmlNNJKP!?=(E?r58`DA<2B zNmWWmybJWCAl_|O?;m8$8XH$nn8iF$C%WaKx89H5z7|c*@7s6TVPxOumlaH0Y`J+w zmZ==5U2y^EEL+fn6p?z~?E9Nv?ZC(yHnx=gNX$gu^cX{)2$g__xXN8QA?>sw(A8}E zh>n;hd7>;hNci#rKGuK5`_pgoFx~u%ZDXCPmj>jTk54EglLI+p+1R5j5G*lBEF1`h z0xt17Y^ROdMj{w8%Sva61c?%vKwoPMW(U^dHjWQ4dXqF%4)n8g+TRaDFl6_74JIIk zn%9kpRE?tMKwz8kT;f0t^rzR)RK1bPMa3&VCGa$xfPy3ZV8tUKL)RkJnr(M2d_u#@ zC&ei4M8U8;5V?TkaKgO)y?T1-SOoN1LS|-o#_T7j!U8qKzxfYV*0-IT+I?mw6( zWXsOmCwovHmLyH}(%F?pUMei&S!2BaRJ3xNy6DlwpsA7&a51h`zqXq4W9K((!cRhX zsi}tz_QO4-)sH0|L9AUWw#16b3bni1`u>dA!g-f|;lywA-H#rQ?A@VR81A+j(uB*9 z!Q+?FlXcp{7WTq5;$Yq+Rc6g*3zcZ7F6yxi5gMVS=S$EzudJk30y{j;S=KBqA3;W@ zIvEQt1(7U4G!3-SNwGKvE$xOo>$r^S`IX`O znkME3IgcE@H}kJ>UUFy~X3To>^52vrNp%}$<>B)7fq=Okk>rUVnbX4vt8xsDKM9FG zS2BAfr$(wZeNJ+AeE$JeJc}Iz%SAM+Lb@a}v9Td!_nPWL`+Rl)&vDJjvUp5{2hM{11)RACzNo*m>GG^cBoSYz2jX zTG*3QR$6Z9Yg~l`qGNb9I5_8IfrZsh9@~X3RXeYckd(NKkEM}p{|BQv| zx4tKuCD+d%fzYkIeBlDggaeXkka83ajj;~xR>xLHbH|8WlQ9O#FT5s(1PW6r`F>Ot zK`B}Kp6bx9iKT?{mMOrXyS?kVL5(z1NlI}4jy?zTvV)2Nc*wUXSuUR#|&XYCry06i6p&ktx= z0}7JXahzS~=Y~p_6goz3gEy2f zJ-X&!2tcCkTY9?}6FG-G($zDilR(2SsFpo~elWWnsCcalXrd=v722gcYsZ98yj!4C z2GNY@CllfyKgIcsE{ek#RH|01lY!4@j99#CS~5rE!-ae8SUr12w@L?`kc1qj2upim zFv`^&yq68v3R;j;8x|yw3b>^ElHy=CvmK#k?{ zD7RdIDyh9t)hqvvL(KyZuc4DQ@Zljzf#nwoqX_UxMZcyaji?YP6sfgpB_oeyFac?1 zn9mA~951EHhL>_gb*z{s)cStV$8X|D!DW!sfN_&^qy+I(Rl^DNK>k_|^dv9vTw0S` zIq&S~mpWx?&cu;xawW+dLI`a%+J>bGq4hBII^OCyW-GmZzs$DcU@H z?k>9FxzSS|tyaAZ5;dij(fjbFxJTunhzSQz`V58CvA)yC#3_&WQu)SMIG9UdnOPHvAk+!1u&ZRu2gE6Z>ryd`e+#-qhlMOF&F z(;U!{P$QJuzx2}hl%iZtt$O}tU;yL~okCa;AS!)vG-l@b3l7H~aN3Vxvl#Yw79{sL ztP4}r+PIFZ;Y(~Ycz?xnyIK_5xq$n{Bp^3KK^x~Iet1)azGfg7sve!58PbFXM7eTv zGa3Fs#}Z9K9qcf=S@sT zd^}dL=x-p|m2!}SA>^E9iK}3lU zRMSaU(~DGF-GsnaY*uBU_{zP50fT8ih5Jco5#!`?KVhu+no(OG;BL$&oN9@W_Lp~U zr*mY8=v0_!B-++Y%I<_wI2`DX7>>m*op}BCg!{AU`LM!ad!FXp4YWsNC~s?$!3RH4 zxAUd`*>}`N+wb~BcYzf4)VjkJ<^m&`*0s?$7*uE2zYOt-@9zhpZY8*sE3&<>Pu;g9 z+~!{e);vm*@)a5^zchNK6W?lweCh#9tp#x(6c+)Rb z#wv1jf#r0rzta5R?8|u?96I_q^EeQSTTGqIEehb#_+gw<^Kf_+NIXkCn9C-P0_jOS zi?k!whB#Gy9sGy^l`-)+x$dc^b!3g%ja&Kb|5tOMNx5%j6cRGQlOXAZfY`_qzT33I z6thDRu``{RPyd!SZ??MFSaDa={_6bQK?t3JQ=ZBXae*GNqc8bU;k$zgLn@+@>!M2X zDNgQ*Ag>xcfl}FPS%uI|;15071J{$c9kfyd@?S6r;$rKPpqa$1m5xT2k|6bXM{15z z>v@pnV#eU+`wDFkBe8m>x|IpS{#lOfGoj!G)j35L2$K9Mc@g9Ki;_WoT1#;`e0Wvr z>n|=fDrW3RNeLE}?{(nfXr9U4nBtN_mguULdfz_7NzXJTt2*rr*70ymCck;39Q_O< zgG{mc5A#B2&@33`g(?V|AfBT?SsBZLGmdpbWhaUl+imu@r!@a)+K(ey@pqwfSa(|L zxrI;qULm=sk^uk+fa`wGa-CP&+ z!}M~<=xJtov?2kz%?0x~;-GVrBqsK-E8^AIKj^NO<8Vt7;W})zH@=_20@qJ}5&FQy?mau=EH96*E z@_oyK-dFV@kW@p6iZTE4QPAUx{edf*?ETHVBCfdQ32E=obyZOlkdAw#@Q`zv~@i21>lVELO(>KU8_+D+yO`(06dr0>ohR{iLcn1C3~$g|?N zv0VI-k31X^kZ%{pXfu~?EoR~VHA9EiC{m4WWCs_uJD*x<@!qG1p2&Ka&(?DsL{abo)sp%IJ=t^Ouz<7UOd3-oR=>AB6wNh3Q#y_Q8QJ%SUmU9hn03eo z%5B6#ku9oM*coqYdGPK4b9CP9y^E~VVUU`b-cz24(_;>hO(RRquI*=XLqf!tB7>xo zq6C#vP20vY9Xtgdy+{f8F6DY@n+N0)*~nI&ope^cv9zgyQ55??e^6^^+0_?YAg|Ok zN>*Sc&R`hNaE!qINyod9AyO`l(ZtdkD(ee!Q&<5!*=S4Dljf zxpZpY0B0_x8Si?tSF<^(TCOLyh%ZF1wakDk5`P^L|$RS7j)ib7_kX#OTUdGsRZL@=&U~MgWhWpwIk->0iuYG5t zgXL30c7ThVVmiz4rL1Cul-9^~x~-PfPH#)%4ez+p0aFtvTauP{U2nC59n-P>$sEu9 zK`ie|QI-+Q&S}0#_YaR>4jf&Ep)+$#tRFM{SvkV`W`$LW*de`SmE^h&Q9%VMkIgZP^K zmOlJ3e#=YiF&G`XC-RE~uWg1&rm76(SGEy`ub;Igs8iU2MH>a5Z0{PqwBsNYU)!~Q z8G`@mUCx)>@T`!Yv|pXC>3cmx&MS2a`UKmb!Kr5gnc1DMX?8dA*#w%(e&tun`OHU5 zf%QTsI)vJv>teL_G{P7p_);<+Mz%58;qf+!87=9dHxfNOK^mBY?Fg*G{eTvw%)G5C zU?2PviWw4+8&bQ`E3kB<9=@g@*aO|^_0^4Q1maBYCFJAC*$xo_*Rzg5oV_&R^ig~7?^+gyrKrHc2Zn@ z9s|KpF2o|{h~JYFTQ zR{e4^(Oj;tYGQR#g`BOzmu(%2!in6~-x%k2BfTdQ?w8SF(CEhAJpc0GW}xqS!mrD8 zo2(7LTv9afUeR%0iJzw~fm`*iv~cL}mDBA%(ddq0Xysn9*E{L)bHZrejbmIMO! zXzT~HdNbjRUE^SM+aW}6aKVoj$Hj~vN$BVL_ZTbIJ_6AwRpwXL1uRL!C%DcUqIC$W z{r+#YzLZ8GmNjiga?Gr9wDx^mv|o0Fl{D4~+$BUhDN{w5pT_do!|{K8Kx5Mj;N=>4 zH0Q@#CxzY_=z@+t;10K9gH7zs(={ri#?Y3D9)b~h8?Zw-m8(;;<@E#j1iTY@DScP$ zqf%uJOh7DM?9b4PzZ#*XpMD&Z^jzPJ511X|9ubHS~#%^1ROgOpK*8 zMH$>%?DWX4X3+n{@fSl@5q}z7{?EzZvi-E{`Sr>!by>h;QV%lQG}remD^JZrR<-R*7eA#Lp2mqNXAj=5g1Void|W z{kWL#jxI!-&oAL8XZKBmsSbfstUIqriy5N{gPm$QEH(^V@?D5PNNoI^sSWlg6-$p+ zs&J8KUi3gvxs3-UchFQp8&1YdNsW~f4s^MW`g!+TN>N+N_tXMvhQkodTv_{CZ$Cr3 zf-j{^^hBV3{76$wb4UgPwC~tsHvNQ^E^2i#70}&;S4lx}Zs?fkmg27T zv2}`=HozlqrP*up6iLrqsX}X2X($l!rbHZDC#=(&eylF(joZ=A>_PINd>nRN_+aw& z?BFbfQSdxaJSeVXFD0%&^HCrHVybkNv+Ek%TJ%pFzqQxAiu2CcncvF<5ECMfq|Q{?(I*!zT7`uI<0$ihSN!%Bt%4C z`dJc@U0NJOo6GLakb65?si%KvE%V10kEHml4QD@ij#X3JcGLkr`{tdszdEn=aDp|S zI*pn}LF%rnE|aagl!?i5HuO}1q}~%Xrl+lb!N7st<6wXPpk2|s-LiUT$85&O zBKgv;zbL$QxOG*jO=w+7$n2Zrfg$EnujS}y?s}M<)7l4~1xm%k>50HDAWNf1f4!?akRD;D6SXC(( zx})`Tu-oN~OV0Q@{VWde3t&LOV{L7uWlVOInMhGfYP%zG=RV>F#eTQf+txB6*xcml zfmw}2WeDYG83^8s-XnoV>GUcET{6t?o6K?Bt6Ph`qN?EJw`h`f8u0HspG2X; zd^gdq000#Lfc3xr9b#&2VO)gLu>>Nt4o6e@^$Fa@WB;!bgQDDDo66?b=vF0KU@cVC#9i?nd9U!aHW_hbHZoPUbEE01451t^ojG zDz5uyDs8RJt=`?>yJLKZ4>7Zn#P(gjyYu(_Ut3yuFb6E0t&@k(`+Ugn;`2LtNXu|1 zPUb%E1CnaJXT<-7Sq%U(cd~wWM(=s$eG(9+VDzYqv%AOp+63Mm);p8{H~@^#w{X7? zsiglrZJMhNAK3)Bh)|_j?<5>Yj#i1jjk#KpZVOb+55PEvq6@%+X_9OVijsjd+^eFA zxd(Ed^X;I{_D4a{Gvat);?#_u9xSPo%0hfSEeURezO>$)$p8b@h+y<$wrJnt@ry$k z+O0y9qNZlzTlX9I>}~xi;4WdSuG-M@!bgO2GKYM)f6LI~V&Tl`xt)!~)Nj4N+A#iT z+vVkH~2}T@Y#{hOX$|) zxOD*>WgPwDdtAIQQrDgELVMd>2ab9>YCgH= zcxMH_!s$B8MSh)$#4L?)TU@!9V9yx7J|+8%eseN*U3_~oR$N~s9SRqzab0>RQE{hM z;Y`V&t!!OiZUizb6VDkt8MBV$KG^i|Iy2+@ey}dg^Qo1eKWO(r3BAOvylZ9cRZFZ9 z?Be`38_WeR--JHDc6OEr99$Q?dSs7V__*-oD4&dN5a9|$7IcPM!UdFjn6`PRdJ&JK zq5Zo>FL}BvX1F|Ih^GpyUuY5Y1VzUnto z?Er2*d238Ox#y=?d`a%4XifUez(LFJhvB$>Z|jl;r^(L?!4rxDl|>*j+qRWJTpR|& z4B;ZC(8hjy=O4DIpdtYOOk7V*evXH44sYfxu{og6G$SsFc82x0{CF?lgyanWw)Y(- z#tF!M0MJS;Nlx;5c|&$+{uv`hoNj|9Q~)+}sJ$VCdlo3`;+Bw?3!K2}+u}g4<^92M z_~YoXvH4`HJ0B){e+?WMWI9`*X%#0=q#}sZl$J|1t|yIONQDORSn8hKh>rihqOO;g z!7?)2YVoC>TYuyaeB6hJ9xHRVj?{81W;CM)|N2gw#@8mQ^)q?u8L;S;v~jN9O9b?zR+jH zWLGg|OYvxHYRPKzR%Dh;86xn`M3->3B?Kb@_A!1_pnLq)wUj7g-j24%rr9LvI{4_& zn6|6YTB?!wuUg)g<>ipD>EvOC4)*ixJhCvSlCr*U+3j164xetVJTBt z-_B!tVS3HPwrUrYeTLHFRY_Ivrycq$QI=&HUq+4hl<}|SI;xJHU&Z93wgI^0BWzo6 z<9j@O+eB!_V2Ftn@bjbs)a$_)9*TwrVS!|7UoQW4^dBSJ+?RHQ~Ys;}_4R9{V@&y?<=1fLiE z;l?sKc@w6m5p;gz!1)=IY$dxah93+O)= zoj`(xE>~gZ+G;7>Q~UvQxP7;2SgrZ1B+8R++cxXibjW_vn~ex!4b9&bdQ_g0Bi8lS z+mVG|sI!O$L8iP~AyNWWVJRAQ4c;u6@(@23To7o0!#4C^CH_>iuyw8lp=5w z%{nzUO_^A0+cZ76O}!7MFX=?Q_-S-@>N}nxr}fGdk&SJT`lN%kX5Hk>WO~ben;r+>ZaZlq&z!PBXh$|XQ2=gQfe<>5|pc&XC>WarBrXV zv{;Zm2l!&+SK_dgZn=0J(w5mIsXFfhrGJb6mF4bkQoy*T=0_0)=gsB`K!>ZElAA|eErKQgZHXBV|1 z6;;8NHgn+5n7V_~+SoW`t5e3$1;KOb>c)NPY<(%8u~nfG6n#wl0)(<@7pWdvs=7Q1 zggjJjx}N?@JkMoiDSDeqkXg6zpO^S1NqA8Pj8pc^wEi2SF)fqo>0t>gYW5XBdH-VM zI(0^8X6XTGoxDD>l~%I-6&Ywg)WP-ED4KIw@*@G?HI_d9So2u=6fbE_dyj-+pUu)r z>zSTRI@E&NVtl2Pj2h_7XXXi?A%edGf`Q;nkGyUAaLwg+<$CDDyW zJO>vWpk4VHu4IrUyRR-!N-LW)PxCk|EF6L1C?I5bj8)9l%rNh8Z!V$)PFSWOdB+(S zC13D>G1PefFMV4fTuDrus_|}*qF%U*VJ&)yy_&hnD+yY^y>eCZ&yGRlTr=$;BuRYP z%aegnr_H9=bxVn29S=Psw%+hvM8U*@qQG3(r3r3*xA8r5cT0b7bGHN zhz*x=)gX;@&AdiEv5-6NAszKy^(qZ@iKP@kGOp8fB zaCvMGa1f(9gfz4{RR(|DEoftuNocbY#1`Aj5->RwQU=MFHlf~V#51^QLvMG~g9`+d zupucjA;MVJIoM{@5@H;m2&fA*wXO8=DpM$9Q@thsW;R_h&uA(YSwX~1=+gG)GPAcT zyA$u1<>KnI((munKTg11!}o0H z=#0xLOb7cX71YT|=;DNH_cXv?bkfr@VMy2a=Q*2q*sY$#4@p)dJYJImk;qQVyg2@X z0#L{G7KiQT7SXRn+G&yvSY`K!MFv61u|_RHN#TsJ>57N={Th-w+A_Q6&Ack=tnEnZ zr>NUzv9!N}Jz2F+TPgHnloY^>_0V%Nqu^pzL6o}&^+=4^7AuCI5H$u@9fAw0DdIdI<#neB3tG&6!P+Idi>kj;leP<#U?OI?r=Gn{xCGMsVcCn zk(R5VQ}V~?Bv@Kd)HogS@&}A08csi*W9g(99v?O&{s(zKT9_|T-LV~98p{&`45U3! ze>%qu5gTu+lS?iZz-G!X{L5z_t?`rgo^pIMqFy&MLTExMS%s9-i*uzX-%H8qJ+;C44{zF`*o-@&4h1-=l;Qr;srD2~T$!r$A@h}AGi ztsk+l#Men8yx32sD)<6RgL{J6#TYXJVgQcu)mlkqja; zxJR-Yr-ck0s~h9w9MGK!ixC1(4_3-U;6PJm zRLTD$mt@8VN)k=l5r@F??dCEU&B%SXWo46_Bn^|jtj<~m5Af7g_=Tz(T^@L(C+Iy8I1-t@L3l#@eu%AVKnb>hmDzgK~P zbNLXp+pRsTnifM4551{;VudFxgu+siqi8JolbeJi;@Q>U+)mS;aGuQdGDlVag<}gy zkbgaP&*-@%k$h0qf5S)f{vf`cU!}8C5$0OKyj`yKD`xm8Gf;Yw)zCVQy+g?d>5r0h z1q-?@Oo?&AnHiu`kaxbBL}#@mR`L)CUbR)z$e)q1ft)SpXhqr3r~@cH(5Gm5gQMp( zCHG3B@h=-0`wB%~B><$4(A3`_{uO>JO`fR|(w6fm{+OHjIO5q@GaGF%&p8T><2H7l zHDq%}WSCbwlrk>UUa2>18u5zOqbouaS)}mK9FaDeV4<0|31)c z(uxFJ=gWx0G(-)a^M#$Sa-&#NS1sHt@(FJWBYcZB)Jk>=^=i^9XJfPoVo?oZC5E<) z*Q$L&I36vGLBq-jGn&-}yf=s30ir9(_M{u0^!)!dV5_AvIvqBuf|eTlOi}iK?%?Pod(#w zb>7`}dz>9)m?%18uAwEkxa9i_gbr+Kh?55WVT(H+q5C+l+Bj!xYwAz~Cy3x+{qZU% zvLFxiipsY87b{Zi;cj$#XqWgNqe_t_jV`dYB`I%cBCe?+{&PUD!ks=F z18SCp%Pd75sqLOxVT}nMt`knjygUx}E2}Kild0YeJ6c9Ui z!Pok1L#8-iScPnNYurM~rFtZT|4Rg=@)yWzh6@LzMw_ioVBobnP_${*Lnx9Q)zawN z$SV9tV-x!)@S{o(15VK=F#G3Cs?U`7;R^x3_{2ncMR_B`(EI2J%$xY)<(x1Gv(3WGk4$pDb*)LR#VFL7;v@efO&mA`B*9|4b0{0E7eHucZZ#EnzPHp(O=k9h^ zm-$bhOjnlcWRjgd{6a96?Rb`k;`ItwH$I4(N3xy!a|&LP5|Sdnfq6uJBZlX>n;O0y z3Wa$;m)=Bu6d&#Egi}m~8y-5Bk}9#n4jF+uL93yA!LE$5q?Uhd?!m439QXP}Ps)y= zPU7Dex~52;z1jVf`WV?5x-Zvz#`n5I)=5hle6U*UooMU=ITw0_d}!eWHwCx~m(mF@ zAk=sM&y<8Kz0)${U}7=S=wlRTi}>1M1PZjr9!!uTdUqX@>(dnp8es<*t(=1rRc%@g zo|5p7v-r!d0DX=7bk%VoE1_MO2*q_={DzKNd9}83k6A$`o&2l$Jpj(-VXvQ>74=K~ z_pai{;zrPnLl%0q_luztCbT=8!(aG@&TR*9w|y>hwRjT=HVN(yw>Fzc`c6)lXZ`EkB!NsWF(rUe5i9hq*_+ zVTb3Tt0>#nxfgB2t}RqD`Gjvh9=GpPj0hJTNL!ts!r z@+c%D=pcHgpO?AJiW~OkdO-WyXur2;(y$j#*phyXqAklxr^Mpub8XGO!i#q-)Nu*H zzI|{ZoHu9jm+kpRL2G#BVR-kO0Xp|Dv7T}>aDEC4oCB;i4jWr=^Fey*_ZDE3!q*3I z45#9KP-&Em$=WFR_p`n+;%riHV~8M;zCt3p;{sW(kA@_PXN6xQJVS{we=Ev!NIH9& zDnoBy4}G9=)~>n=!E^D?PXbH?u4^RXCac)MX@s2gjn8oxp7klnXXuAU3fKse7Y0Lw z3+X4bV0%7$;^Pmxf<8b|stE_>A-U5NZL&21GjaPslrH%7X$(edGD!{E5K8UFdXWlp z8Jx}mq5ZgQ5e=7*5C0;%YWz)~K2U;T*7@g8A|#>p5o&gP-(-*A{WHS8@NKQ!6AplV zh+bTV$G+me)(V60hX{4vSlY>HGc&-Up$T(IV39f#SH-A4eEnW9^Q=Ap2ZYMwD3jtE z8PsKy)tgbo&yemXVGwN`11*g5jY=PKGLg~cRk91qE^36WMaXFd9^a8lrvfTV=6bQ| zKU)QAA=}xvlL=7z3;)}FsHADhE<4uvd` z3uHavJb26NOW80C6h$8)a0cmz2Cyax;8#XTej^`*y1v~D_r~De;=&}Y1w19k7&e~h z%hu&)^`-#AW>l6f4ZCsy;i>Vadh+m&UjiD#1P!>jK1}gZc9eER7v~ONEt;a7`tV0x zbvx7MG``w-5pY!FJL5~zldXAbJ0^Sp`CQ>{qHm(-Ep&7duLL=tFL4vTMseFHg2xo# z+}U!cvvhnv+Fa|v*$ftM*o;e;M0J>{@2l`J7;dW&NYB!K3@kJv3x{!Ig6UEr9QxTR zzXNb*;~Wn8RIDyzwZjuv4sZ5DjV-Ffp!XYwcLe&5V-GN7F_d(u^mrQhQEEwS=KP3v znQmD%U;Vm_8Xo4UArFC722%*70nAF*yE0f;?tVB!JBYa0J9F4tZb?I^>3|76lOA02 z{W7>UChbrjO9Xk2HDVWUU%0ZT&d3|23&lj@ciX$`(YtpKdbnDLxyER5+r)fpkri@m zp3Tj&!)JgX+$Jg!k_SK4fded&O6h)dpoxBEM!M_ShVRL#z?Ve+)KIB?1jbtF{oNl^(gx;=2!MzVFoIl=Xn~2LYFOcK$0(8n*eO{0 z>Jf+?WfCOJYEdcIxRCQL!Eyh+HT?;+{0s94sl-y5VXPyOojkLm7-%@lT@6Xw_}02u z;9W{-UTyf-&4{pUwsPC!K_*&5jj2h+JmyCsM0$eUQGt5%n2}^+rCru@6y#_!dD`JydZ#HPee3jd}6)`c&-Revi>sB-DdHB({ zhwLt^RHR|lD1iAYyLBr#ag=+udw&u4*A?=M7+MOU2-z2mBusKsu3# zbVL^8qgRzSpMe+y=jzlnF*_L|l^iT#=cWGaMg@{$kal}pqe^o3+oHW@>X~N1H{nyO jqwPA(P}lgE(j%mAATIa+&VY>sVjP<7`;T4%0O5ZCM~NL$ diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 445af82fb..68065e82a 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -12,5 +12,3 @@ @import "annotator_overrides"; @import "jquery-ui/datepicker"; @import "datepicker_overrides"; -@import "font-awesome-sprockets"; -@import "font-awesome"; diff --git a/app/assets/stylesheets/icons.scss b/app/assets/stylesheets/icons.scss index b13b09f46..2c06f745a 100644 --- a/app/assets/stylesheets/icons.scss +++ b/app/assets/stylesheets/icons.scss @@ -160,3 +160,6 @@ .icon-no-notification:before { content: "\78"; } +.icon-whatsapp:before { + content: "\50"; +} diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index a8ee508d6..afa0659e7 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -337,18 +337,20 @@ .debate-show, .proposal-show { - .social_share_full .social-share-button{ + .social-share-full .social-share-button{ display:inline; } - .whatsapp{ + .whatsapp:before{ + vertical-align: 10px; margin-left: 0.5px; color: white; - vertical-align: top; background-color: #43d854; - padding: 7px 9.5px 7px 9.5px; + padding: 9.5px 9.8px 9.5px 9.8px; + font-size: 1.7em; } + .edit-debate, .edit-proposal { margin-bottom: 0; } diff --git a/app/views/debates/show.html.erb b/app/views/debates/show.html.erb index 459561c10..4182fab9a 100644 --- a/app/views/debates/show.html.erb +++ b/app/views/debates/show.html.erb @@ -54,11 +54,11 @@

<%= t("debates.show.share") %>

-

<%= t("proposals.show.share") %>

- + +
+ +
@@ -90,6 +97,18 @@ <%= events_chart_tag event %> <% end %>
+ +
+

<%= t "admin.stats.show.spending_proposals_title" %>

+ <%= spending_proposals_chart_tag id: "spending_proposals" %> +
+ +
+ <% @event_types.each do |event, count| %> +

<%= event.titleize %> (<%= count %>)

+ <%= events_chart_tag event %> + <% end %> +
diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml index b38a069aa..dfa937a23 100755 --- a/config/locales/admin.en.yml +++ b/config/locales/admin.en.yml @@ -194,6 +194,7 @@ en: debates: Debates proposal_votes: Proposal votes proposals: Proposals + spending_proposals: Spending Proposals unverified_users: Unverified users user_level_three: Level three users user_level_two: Level two users @@ -201,6 +202,7 @@ en: verified_users: Verified users visits: Visits votes: Total votes + spending_proposals_title: Spending Proposals visits_title: Visits tags: create: Create Topic @@ -230,4 +232,4 @@ en: index: phone_not_given: Phone not given sms_code_not_confirmed: Has not confirmed the sms code - title: Incomplete verifications + title: Incomplete verifications \ No newline at end of file diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml index 67c846158..0b1418fcd 100644 --- a/config/locales/admin.es.yml +++ b/config/locales/admin.es.yml @@ -194,6 +194,7 @@ es: debates: Debates proposal_votes: Votos en propuestas proposals: Propuestas + spending_proposals: Propuestas de inversión unverified_users: Usuarios sin verificar user_level_three: Usuarios de nivel tres user_level_two: Usuarios de nivel dos @@ -201,6 +202,7 @@ es: verified_users: Usuarios verificados visits: Visitas votes: Votos + spending_proposals_title: Propuestas de inversión visits_title: Visitas tags: create: Crear Tema From 7a141b814770e343b780381f1fe8f9066f829667 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 28 Mar 2016 11:19:36 +0200 Subject: [PATCH 009/163] updates jwt gem --- Gemfile | 1 + Gemfile.lock | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 383de2122..2e3ed4b15 100644 --- a/Gemfile +++ b/Gemfile @@ -59,6 +59,7 @@ gem 'tolk' # Web interface for translations gem 'browser' gem 'turnout' gem 'redcarpet' +gem 'jwt', '~> 1.5.4' group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console diff --git a/Gemfile.lock b/Gemfile.lock index 18fa95bd9..24494af00 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -208,7 +208,7 @@ GEM jquery-ui-rails (5.0.5) railties (>= 3.2.16) json (1.8.3) - jwt (1.5.3) + jwt (1.5.4) kaminari (0.16.3) actionpack (>= 3.0.0) activesupport (>= 3.0.0) @@ -465,6 +465,7 @@ DEPENDENCIES initialjs-rails (= 0.2.0.1) jquery-rails jquery-ui-rails + jwt (~> 1.5.4) kaminari launchy letter_opener_web (~> 1.3.0) From 9aaeb23e7fc88becdacd56b3884d80b39672ff7a Mon Sep 17 00:00:00 2001 From: rgarcia Date: Wed, 9 Mar 2016 16:47:10 +0100 Subject: [PATCH 010/163] sends an email for unfeasible spending proposals --- .../spending_proposals_controller.rb | 5 +++ app/mailers/mailer.rb | 9 ++++++ app/models/spending_proposal.rb | 8 +++++ .../unfeasible_spending_proposal.html.erb | 16 ++++++++++ config/locales/mailers.en.yml | 4 +++ config/locales/mailers.es.yml | 4 +++ spec/features/emails_spec.rb | 26 ++++++++++++++++ spec/models/spending_proposal_spec.rb | 31 +++++++++++++++++++ 8 files changed, 103 insertions(+) create mode 100644 app/views/mailer/unfeasible_spending_proposal.html.erb diff --git a/app/controllers/valuation/spending_proposals_controller.rb b/app/controllers/valuation/spending_proposals_controller.rb index f8c63c974..c0084a1c0 100644 --- a/app/controllers/valuation/spending_proposals_controller.rb +++ b/app/controllers/valuation/spending_proposals_controller.rb @@ -18,6 +18,11 @@ class Valuation::SpendingProposalsController < Valuation::BaseController def valuate if valid_price_params? && @spending_proposal.update(valuation_params) + + if @spending_proposal.marked_as_unfeasible? + Mailer.unfeasible_spending_proposal(@spending_proposal).deliver_later + end + redirect_to valuation_spending_proposal_path(@spending_proposal), notice: t('valuation.spending_proposals.notice.valuate') else render action: :edit diff --git a/app/mailers/mailer.rb b/app/mailers/mailer.rb index 356f2ea45..d0e6080bb 100644 --- a/app/mailers/mailer.rb +++ b/app/mailers/mailer.rb @@ -33,6 +33,15 @@ class Mailer < ApplicationMailer end end + def unfeasible_spending_proposal(spending_proposal) + @spending_proposal = spending_proposal + @author = spending_proposal.author + + with_user(@author) do + mail(to: @author.email, subject: t('mailers.unfeasible_spending_proposal.subject')) + end + end + private def with_user(user, &block) diff --git a/app/models/spending_proposal.rb b/app/models/spending_proposal.rb index 237da73f7..df5cb17e4 100644 --- a/app/models/spending_proposal.rb +++ b/app/models/spending_proposal.rb @@ -68,4 +68,12 @@ class SpendingProposal < ActiveRecord::Base end end + def marked_as_unfeasible? + previous_changes.has_key?("feasible") && unfeasible? + end + + def unfeasible? + not feasible? + end + end diff --git a/app/views/mailer/unfeasible_spending_proposal.html.erb b/app/views/mailer/unfeasible_spending_proposal.html.erb new file mode 100644 index 000000000..0bb03ed6d --- /dev/null +++ b/app/views/mailer/unfeasible_spending_proposal.html.erb @@ -0,0 +1,16 @@ +

+ <%= @author.name %> +

+ +

+ <%= @spending_proposal.title %> +

+ +

+ <%= @spending_proposal.feasible_explanation %> +

+ +

+ <%= t("mailers.unfeasible_spending_proposal.responsible") %> + <%= @spending_proposal.administrator.id %> +

\ No newline at end of file diff --git a/config/locales/mailers.en.yml b/config/locales/mailers.en.yml index 8e337b42e..e7ff3f928 100755 --- a/config/locales/mailers.en.yml +++ b/config/locales/mailers.en.yml @@ -20,3 +20,7 @@ en: new_reply_by_html: There is a new response from %{commenter} to your comment on subject: Someone has responded to your comment title: New response to your comment + unfeasible_spending_proposal: + hi: Hi + subject: Your spending proposal has been marked as not feasible + responsible: The responsible for the evaluation of your spending proposal is admin \ No newline at end of file diff --git a/config/locales/mailers.es.yml b/config/locales/mailers.es.yml index fb0e7b2fb..b570dba46 100644 --- a/config/locales/mailers.es.yml +++ b/config/locales/mailers.es.yml @@ -20,3 +20,7 @@ es: new_reply_by_html: Hay una nueva respuesta de %{commenter} a tu comentario en subject: Alguien ha respondido a tu comentario title: Nueva respuesta a tu comentario + unfeasible_spending_proposal: + hi: Hola + subject: Tu propuesta de inversión ha sido marcada como inviable + responsible: El responsable de la evaluación de tu respuesta es el administrator \ No newline at end of file diff --git a/spec/features/emails_spec.rb b/spec/features/emails_spec.rb index fd3b219e6..f6fcbf901 100644 --- a/spec/features/emails_spec.rb +++ b/spec/features/emails_spec.rb @@ -122,4 +122,30 @@ feature 'Emails' do expect(email).to have_body_text(user_confirmation_path) end + scenario "Email on unfeasible spending proposal", :focus do + spending_proposal = create(:spending_proposal) + administrator = create(:administrator) + valuator = create(:valuator) + spending_proposal.update(administrator: administrator) + spending_proposal.valuators << valuator + + login_as(valuator.user) + visit edit_valuation_spending_proposal_path(spending_proposal) + + choose 'spending_proposal_feasible_false' + fill_in 'spending_proposal_feasible_explanation', with: 'This is not legal as stated in Article 34.9' + click_button 'Save changes' + + expect(page).to have_content "Dossier updated" + spending_proposal.reload + + email = open_last_email + expect(email).to have_subject('Your spending proposal has been marked as not feasible') + expect(email).to deliver_to(spending_proposal.author.email) + expect(email).to have_body_text(spending_proposal.author.name) + expect(email).to have_body_text(spending_proposal.title) + expect(email).to have_body_text(spending_proposal.feasible_explanation) + expect(email).to have_body_text("admin #{spending_proposal.administrator.id}") + end + end diff --git a/spec/models/spending_proposal_spec.rb b/spec/models/spending_proposal_spec.rb index 2a10851b6..310a8064d 100644 --- a/spec/models/spending_proposal_spec.rb +++ b/spec/models/spending_proposal_spec.rb @@ -59,6 +59,37 @@ describe SpendingProposal do expect(spending_proposal.feasibility).to eq "undefined" end end + + describe "#unfeasible?" do + it "returns true when not feasible" do + spending_proposal.feasible = false + expect(spending_proposal.unfeasible?).to eq true + end + + it "returns false when feasible" do + spending_proposal.feasible = true + expect(spending_proposal.unfeasible?).to eq false + end + end + + describe "#marked_as_unfeasible?" do + let(:spending_proposal) { create(:spending_proposal) } + + it "returns true when feasibility has changed and it is false" do + spending_proposal.update(feasible: false) + expect(spending_proposal.marked_as_unfeasible?).to eq true + end + + it "returns false when feasibility has not changed" do + spending_proposal.update(price: 1000000) + expect(spending_proposal.marked_as_unfeasible?).to eq false + end + + it "returns false when it is feasible" do + spending_proposal.update(feasible: true) + expect(spending_proposal.marked_as_unfeasible?).to eq false + end + end end describe "by_admin" do From 2fe1e0d6247a0a63dc45dba83f5e940ddd2def39 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Wed, 9 Mar 2016 16:47:35 +0100 Subject: [PATCH 011/163] adds pending spec for edge case --- spec/models/spending_proposal_spec.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/models/spending_proposal_spec.rb b/spec/models/spending_proposal_spec.rb index 310a8064d..bf5ee138f 100644 --- a/spec/models/spending_proposal_spec.rb +++ b/spec/models/spending_proposal_spec.rb @@ -89,6 +89,10 @@ describe SpendingProposal do spending_proposal.update(feasible: true) expect(spending_proposal.marked_as_unfeasible?).to eq false end + + xit "when marked as unfeasible but there is no admin associated... + an exception occurs when sending the unfeasible email, + because spending_proposal.administrator.id is nil.." end end From 50b1571126db6f3ee4a18b8a0820a1a4c33f837e Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 28 Mar 2016 12:14:33 +0200 Subject: [PATCH 012/163] adds code to spending proposals --- app/models/spending_proposal.rb | 4 ++++ spec/models/spending_proposal_spec.rb | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/app/models/spending_proposal.rb b/app/models/spending_proposal.rb index df5cb17e4..81293b386 100644 --- a/app/models/spending_proposal.rb +++ b/app/models/spending_proposal.rb @@ -76,4 +76,8 @@ class SpendingProposal < ActiveRecord::Base not feasible? end + def code + "#{id}" + (administrator.present? ? "-#{administrator.id}" : "") + end + end diff --git a/spec/models/spending_proposal_spec.rb b/spec/models/spending_proposal_spec.rb index bf5ee138f..9ca2fae94 100644 --- a/spec/models/spending_proposal_spec.rb +++ b/spec/models/spending_proposal_spec.rb @@ -94,6 +94,19 @@ describe SpendingProposal do an exception occurs when sending the unfeasible email, because spending_proposal.administrator.id is nil.." end + + describe "#code" do + let(:spending_proposal) { create(:spending_proposal) } + + it "returns the proposal id" do + expect(spending_proposal.code).to eq("#{spending_proposal.id}") + end + + it "returns the administrator id when assigned" do + spending_proposal.administrator = create(:administrator) + expect(spending_proposal.code).to eq("#{spending_proposal.id}-#{spending_proposal.administrator.id}") + end + end end describe "by_admin" do From e31fe0060860100bdfa40ee3ebcd948d7668a0c2 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 28 Mar 2016 12:15:35 +0200 Subject: [PATCH 013/163] updates email text --- .../unfeasible_spending_proposal.html.erb | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/app/views/mailer/unfeasible_spending_proposal.html.erb b/app/views/mailer/unfeasible_spending_proposal.html.erb index 0bb03ed6d..958879493 100644 --- a/app/views/mailer/unfeasible_spending_proposal.html.erb +++ b/app/views/mailer/unfeasible_spending_proposal.html.erb @@ -1,16 +1,16 @@ -

- <%= @author.name %> -

+

Estimado usuario,

-

- <%= @spending_proposal.title %> -

+

Desde el Ayuntamiento de Madrid queremos agradecer tu participación en los Presupuestos Participativos de la ciudad de Madrid. +Lamentamos informarte de que tu propuesta '<%= @spending_proposal.title %>' quedará excluida de este proceso participativo por el siguiente motivo:

-

- <%= @spending_proposal.feasible_explanation %> -

+

<%= @spending_proposal.feasible_explanation %>

-

- <%= t("mailers.unfeasible_spending_proposal.responsible") %> - <%= @spending_proposal.administrator.id %> -

\ No newline at end of file +

Por todo ello, te invitamos a que elabores una nueva propuesta que se ajuste a las condiciones de este proceso. Esto lo puedes hacer en este enlace: +<%= link_to "nueva propuesta de inversión", new_spending_proposal_url %>

+ +

Si consideras que la propuesta rechazada cumple los requisitos para mantenerla como propuesta de inversión, podrás comunicarlo, en el plazo de 48 horas, al correo preparticipativos@madrid.es, indicando necesariamente para su tramitación el código <%= @spending_proposal.code %> como asunto del correo, correspondiente a tu propuesta.

+ +

Sentimos las molestias ocasionadas y volvemos a darte las gracias por tu inestimable participación.

+ +

Atentamente

+

DIRECCIÓN GENERAL DE PARTICIPACIÓN CIUDADANA

\ No newline at end of file From d7996cd01bab68a634ab5186bc02a1bf8c7f0646 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 28 Mar 2016 12:15:47 +0200 Subject: [PATCH 014/163] fixes specs --- spec/features/emails_spec.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spec/features/emails_spec.rb b/spec/features/emails_spec.rb index f6fcbf901..849c5a7e2 100644 --- a/spec/features/emails_spec.rb +++ b/spec/features/emails_spec.rb @@ -142,10 +142,9 @@ feature 'Emails' do email = open_last_email expect(email).to have_subject('Your spending proposal has been marked as not feasible') expect(email).to deliver_to(spending_proposal.author.email) - expect(email).to have_body_text(spending_proposal.author.name) expect(email).to have_body_text(spending_proposal.title) expect(email).to have_body_text(spending_proposal.feasible_explanation) - expect(email).to have_body_text("admin #{spending_proposal.administrator.id}") + expect(email).to have_body_text("#{spending_proposal.id}-#{spending_proposal.administrator.id}") end end From db5348938efd57d2b3ce737a20c6ae9bc0c29e8c Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 28 Mar 2016 14:08:39 +0200 Subject: [PATCH 015/163] adds code to email subject --- app/mailers/mailer.rb | 2 +- spec/features/emails_spec.rb | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/mailers/mailer.rb b/app/mailers/mailer.rb index d0e6080bb..fcc2a62b1 100644 --- a/app/mailers/mailer.rb +++ b/app/mailers/mailer.rb @@ -38,7 +38,7 @@ class Mailer < ApplicationMailer @author = spending_proposal.author with_user(@author) do - mail(to: @author.email, subject: t('mailers.unfeasible_spending_proposal.subject')) + mail(to: @author.email, subject: t('mailers.unfeasible_spending_proposal.subject', code: @spending_proposal.code)) end end diff --git a/spec/features/emails_spec.rb b/spec/features/emails_spec.rb index 849c5a7e2..3ca35a14c 100644 --- a/spec/features/emails_spec.rb +++ b/spec/features/emails_spec.rb @@ -140,11 +140,10 @@ feature 'Emails' do spending_proposal.reload email = open_last_email - expect(email).to have_subject('Your spending proposal has been marked as not feasible') + expect(email).to have_subject("Your investment project '#{spending_proposal.id}-#{spending_proposal.administrator.id}' has been marked as unfeasible") expect(email).to deliver_to(spending_proposal.author.email) expect(email).to have_body_text(spending_proposal.title) expect(email).to have_body_text(spending_proposal.feasible_explanation) - expect(email).to have_body_text("#{spending_proposal.id}-#{spending_proposal.administrator.id}") end end From 034c3b527ed95d8ea69e30a7c0ac20ca76d65ede Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 28 Mar 2016 14:08:57 +0200 Subject: [PATCH 016/163] adds translations for unfeasible email --- .../unfeasible_spending_proposal.html.erb | 19 ++++++++++--------- config/locales/mailers.en.yml | 12 +++++++++--- config/locales/mailers.es.yml | 12 +++++++++--- 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/app/views/mailer/unfeasible_spending_proposal.html.erb b/app/views/mailer/unfeasible_spending_proposal.html.erb index 958879493..b89e83afa 100644 --- a/app/views/mailer/unfeasible_spending_proposal.html.erb +++ b/app/views/mailer/unfeasible_spending_proposal.html.erb @@ -1,16 +1,17 @@ -

Estimado usuario,

+

<%= t("mailers.unfeasible_spending_proposal.hi") %>

-

Desde el Ayuntamiento de Madrid queremos agradecer tu participación en los Presupuestos Participativos de la ciudad de Madrid. -Lamentamos informarte de que tu propuesta '<%= @spending_proposal.title %>' quedará excluida de este proceso participativo por el siguiente motivo:

+

<%= t("mailers.unfeasible_spending_proposal.unfeasible", + title: @spending_proposal.title) %>

<%= @spending_proposal.feasible_explanation %>

-

Por todo ello, te invitamos a que elabores una nueva propuesta que se ajuste a las condiciones de este proceso. Esto lo puedes hacer en este enlace: -<%= link_to "nueva propuesta de inversión", new_spending_proposal_url %>

+

<%= t("mailers.unfeasible_spending_proposal.new_html", + url: link_to(t("mailers.unfeasible_spending_proposal.new_href"), + new_spending_proposal_url)) %>

-

Si consideras que la propuesta rechazada cumple los requisitos para mantenerla como propuesta de inversión, podrás comunicarlo, en el plazo de 48 horas, al correo preparticipativos@madrid.es, indicando necesariamente para su tramitación el código <%= @spending_proposal.code %> como asunto del correo, correspondiente a tu propuesta.

+

<%= t("mailers.unfeasible_spending_proposal.reconsider") %>

-

Sentimos las molestias ocasionadas y volvemos a darte las gracias por tu inestimable participación.

+

<%= t("mailers.unfeasible_spending_proposal.sorry") %>

-

Atentamente

-

DIRECCIÓN GENERAL DE PARTICIPACIÓN CIUDADANA

\ No newline at end of file +

<%= t("mailers.unfeasible_spending_proposal.sincerely") %>

+

<%= t("mailers.unfeasible_spending_proposal.signatory") %>

\ No newline at end of file diff --git a/config/locales/mailers.en.yml b/config/locales/mailers.en.yml index e7ff3f928..53d2b7c60 100755 --- a/config/locales/mailers.en.yml +++ b/config/locales/mailers.en.yml @@ -21,6 +21,12 @@ en: subject: Someone has responded to your comment title: New response to your comment unfeasible_spending_proposal: - hi: Hi - subject: Your spending proposal has been marked as not feasible - responsible: The responsible for the evaluation of your spending proposal is admin \ No newline at end of file + hi: "Dear user," + new_html: "For all these, we invite you to elaborate a new proposal that ajusts to the conditions of this process. You can do it following this link: %{url}" + new_href: "new investment project" + reconsider: "If you believe that the rejected proposal meets the requirements to be an investment proposal, you can communicate this, within 48 hours, responding to this email. Please include all relevant information to reconsider the proposal as valid." + sincerely: "Sincerely" + signatory: "DEPARTMENT OF PUBLIC PARTICIPATION" + sorry: "Sorry for the inconvenience and we again thank you for your invaluable participation." + subject: "Your investment project '%{code}' has been marked as unfeasible" + unfeasible: "From the Madrid City Council we want to thank you for your participation in the participatory budgets of the city of Madrid. We regret to inform you that your proposal '%{title}' will be excluded from this participatory process for the following reason:" \ No newline at end of file diff --git a/config/locales/mailers.es.yml b/config/locales/mailers.es.yml index b570dba46..0624fa410 100644 --- a/config/locales/mailers.es.yml +++ b/config/locales/mailers.es.yml @@ -21,6 +21,12 @@ es: subject: Alguien ha respondido a tu comentario title: Nueva respuesta a tu comentario unfeasible_spending_proposal: - hi: Hola - subject: Tu propuesta de inversión ha sido marcada como inviable - responsible: El responsable de la evaluación de tu respuesta es el administrator \ No newline at end of file + hi: "Estimado usuario," + new_html: "Por todo ello, te invitamos a que elabores una nueva propuesta que se ajuste a las condiciones de este proceso. Esto lo puedes hacer en este enlace: %{url}" + new_href: "nueva propuesta de inversión" + reconsider: "Si consideras que la propuesta rechazada cumple los requisitos para mantenerla como propuesta de inversión, podrás comunicarlo, en el plazo de 48 horas, respondiendo a este email. Por favor incluye toda la información relevante para reconsiderar la propuesta como válida." + sincerely: "Atentamente" + signatory: "DIRECCIÓN GENERAL DE PARTICIPACIÓN CIUDADANA" + sorry: "Sentimos las molestias ocasionadas y volvemos a darte las gracias por tu inestimable participación." + subject: "Tu propuesta de inversión '%{code}' ha sido marcada como inviable" + unfeasible: "Desde el Ayuntamiento de Madrid queremos agradecer tu participación en los Presupuestos Participativos de la ciudad de Madrid. Lamentamos informarte de que tu propuesta '%{title}' quedará excluida de este proceso participativo por el siguiente motivo:" From 8a8f062398c4e9db249d9dc3e634a0b741236fad Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 28 Mar 2016 16:37:16 +0200 Subject: [PATCH 017/163] updates investment project code --- app/models/spending_proposal.rb | 2 +- spec/features/emails_spec.rb | 4 ++-- spec/models/spending_proposal_spec.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/spending_proposal.rb b/app/models/spending_proposal.rb index 81293b386..8998fed6b 100644 --- a/app/models/spending_proposal.rb +++ b/app/models/spending_proposal.rb @@ -77,7 +77,7 @@ class SpendingProposal < ActiveRecord::Base end def code - "#{id}" + (administrator.present? ? "-#{administrator.id}" : "") + "#{id}" + (administrator.present? ? "-A#{administrator.id}" : "") end end diff --git a/spec/features/emails_spec.rb b/spec/features/emails_spec.rb index 3ca35a14c..378098367 100644 --- a/spec/features/emails_spec.rb +++ b/spec/features/emails_spec.rb @@ -122,7 +122,7 @@ feature 'Emails' do expect(email).to have_body_text(user_confirmation_path) end - scenario "Email on unfeasible spending proposal", :focus do + scenario "Email on unfeasible spending proposal" do spending_proposal = create(:spending_proposal) administrator = create(:administrator) valuator = create(:valuator) @@ -140,7 +140,7 @@ feature 'Emails' do spending_proposal.reload email = open_last_email - expect(email).to have_subject("Your investment project '#{spending_proposal.id}-#{spending_proposal.administrator.id}' has been marked as unfeasible") + expect(email).to have_subject("Your investment project '#{spending_proposal.id}-A#{spending_proposal.administrator.id}' has been marked as unfeasible") expect(email).to deliver_to(spending_proposal.author.email) expect(email).to have_body_text(spending_proposal.title) expect(email).to have_body_text(spending_proposal.feasible_explanation) diff --git a/spec/models/spending_proposal_spec.rb b/spec/models/spending_proposal_spec.rb index 9ca2fae94..340515f84 100644 --- a/spec/models/spending_proposal_spec.rb +++ b/spec/models/spending_proposal_spec.rb @@ -104,7 +104,7 @@ describe SpendingProposal do it "returns the administrator id when assigned" do spending_proposal.administrator = create(:administrator) - expect(spending_proposal.code).to eq("#{spending_proposal.id}-#{spending_proposal.administrator.id}") + expect(spending_proposal.code).to eq("#{spending_proposal.id}-A#{spending_proposal.administrator.id}") end end end From 467c06c3ca45d03266dba3b5a49b94b423877f0f Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 28 Mar 2016 18:06:43 +0200 Subject: [PATCH 018/163] allows unfeasible emails only to be send out once --- .../spending_proposals_controller.rb | 2 +- app/models/spending_proposal.rb | 11 +++++- ...ble_email_sent_at_to_spending_proposals.rb | 5 +++ db/schema.rb | 3 +- spec/features/emails_spec.rb | 1 + spec/models/spending_proposal_spec.rb | 37 +++++++++++++------ 6 files changed, 45 insertions(+), 14 deletions(-) create mode 100644 db/migrate/20160328152843_add_unfeasible_email_sent_at_to_spending_proposals.rb diff --git a/app/controllers/valuation/spending_proposals_controller.rb b/app/controllers/valuation/spending_proposals_controller.rb index c0084a1c0..deba1777d 100644 --- a/app/controllers/valuation/spending_proposals_controller.rb +++ b/app/controllers/valuation/spending_proposals_controller.rb @@ -20,7 +20,7 @@ class Valuation::SpendingProposalsController < Valuation::BaseController if valid_price_params? && @spending_proposal.update(valuation_params) if @spending_proposal.marked_as_unfeasible? - Mailer.unfeasible_spending_proposal(@spending_proposal).deliver_later + @spending_proposal.send_unfeasible_email end redirect_to valuation_spending_proposal_path(@spending_proposal), notice: t('valuation.spending_proposals.notice.valuate') diff --git a/app/models/spending_proposal.rb b/app/models/spending_proposal.rb index 8998fed6b..ea182b3fb 100644 --- a/app/models/spending_proposal.rb +++ b/app/models/spending_proposal.rb @@ -69,15 +69,24 @@ class SpendingProposal < ActiveRecord::Base end def marked_as_unfeasible? - previous_changes.has_key?("feasible") && unfeasible? + unfeasible_email_sent_at.blank? && unfeasible? && valuation_finished? end def unfeasible? not feasible? end + def valuation_finished? + valuation_finished + end + def code "#{id}" + (administrator.present? ? "-A#{administrator.id}" : "") end + def send_unfeasible_email + Mailer.unfeasible_spending_proposal(self).deliver_later + update(unfeasible_email_sent_at: Time.now) + end + end diff --git a/db/migrate/20160328152843_add_unfeasible_email_sent_at_to_spending_proposals.rb b/db/migrate/20160328152843_add_unfeasible_email_sent_at_to_spending_proposals.rb new file mode 100644 index 000000000..bbe1dc6ec --- /dev/null +++ b/db/migrate/20160328152843_add_unfeasible_email_sent_at_to_spending_proposals.rb @@ -0,0 +1,5 @@ +class AddUnfeasibleEmailSentAtToSpendingProposals < ActiveRecord::Migration + def change + add_column :spending_proposals, :unfeasible_email_sent_at, :datetime, default: nil + end +end diff --git a/db/schema.rb b/db/schema.rb index a406d3f4c..c6c5faa19 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: 20160315092854) do +ActiveRecord::Schema.define(version: 20160328152843) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -311,6 +311,7 @@ ActiveRecord::Schema.define(version: 20160315092854) do t.integer "valuation_assignments_count", default: 0 t.integer "price_first_year", limit: 8 t.string "time_scope" + t.datetime "unfeasible_email_sent_at" end add_index "spending_proposals", ["author_id"], name: "index_spending_proposals_on_author_id", using: :btree diff --git a/spec/features/emails_spec.rb b/spec/features/emails_spec.rb index 378098367..c6d675a73 100644 --- a/spec/features/emails_spec.rb +++ b/spec/features/emails_spec.rb @@ -134,6 +134,7 @@ feature 'Emails' do choose 'spending_proposal_feasible_false' fill_in 'spending_proposal_feasible_explanation', with: 'This is not legal as stated in Article 34.9' + check 'spending_proposal_valuation_finished' click_button 'Save changes' expect(page).to have_content "Dossier updated" diff --git a/spec/models/spending_proposal_spec.rb b/spec/models/spending_proposal_spec.rb index 340515f84..6d506d587 100644 --- a/spec/models/spending_proposal_spec.rb +++ b/spec/models/spending_proposal_spec.rb @@ -75,24 +75,39 @@ describe SpendingProposal do describe "#marked_as_unfeasible?" do let(:spending_proposal) { create(:spending_proposal) } - it "returns true when feasibility has changed and it is false" do - spending_proposal.update(feasible: false) + it "returns true when marked as unfeasibable and valuation_finished" do + spending_proposal.update(feasible: false, valuation_finished: true) expect(spending_proposal.marked_as_unfeasible?).to eq true end - it "returns false when feasibility has not changed" do - spending_proposal.update(price: 1000000) - expect(spending_proposal.marked_as_unfeasible?).to eq false - end - - it "returns false when it is feasible" do + it "returns false when marked as feasible" do spending_proposal.update(feasible: true) expect(spending_proposal.marked_as_unfeasible?).to eq false end - xit "when marked as unfeasible but there is no admin associated... - an exception occurs when sending the unfeasible email, - because spending_proposal.administrator.id is nil.." + it "returns false when marked as feasable and valuation_finished" do + spending_proposal.update(feasible: true, valuation_finished: true) + expect(spending_proposal.marked_as_unfeasible?).to eq false + end + + it "returns false when unfeasible email already sent" do + spending_proposal.update(unfeasible_email_sent_at: 1.day.ago) + expect(spending_proposal.marked_as_unfeasible?).to eq false + end + end + + describe "#send_unfeasible_email" do + let(:spending_proposal) { create(:spending_proposal) } + + it "sets the time when the unfeasible email was sent" do + expect(spending_proposal.unfeasible_email_sent_at).to_not be + spending_proposal.send_unfeasible_email + expect(spending_proposal.unfeasible_email_sent_at).to be + end + + it "send an email" do + expect {spending_proposal.send_unfeasible_email}.to change { ActionMailer::Base.deliveries.count }.by(1) + end end describe "#code" do From 26039d490697ee539eb5bd4ca35e9b05b73d07e7 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Mon, 28 Mar 2016 15:20:17 +0200 Subject: [PATCH 019/163] Improves styles for email --- .../unfeasible_spending_proposal.html.erb | 40 ++++++++++++++----- config/locales/mailers.en.yml | 6 +-- config/locales/mailers.es.yml | 6 +-- 3 files changed, 35 insertions(+), 17 deletions(-) diff --git a/app/views/mailer/unfeasible_spending_proposal.html.erb b/app/views/mailer/unfeasible_spending_proposal.html.erb index b89e83afa..fa4e3cf96 100644 --- a/app/views/mailer/unfeasible_spending_proposal.html.erb +++ b/app/views/mailer/unfeasible_spending_proposal.html.erb @@ -1,17 +1,35 @@ -

<%= t("mailers.unfeasible_spending_proposal.hi") %>

+ -

<%= t("mailers.unfeasible_spending_proposal.unfeasible", - title: @spending_proposal.title) %>

+

+ <%= t("mailers.unfeasible_spending_proposal.hi") %> +

-

<%= @spending_proposal.feasible_explanation %>

+

+ <%= t("mailers.unfeasible_spending_proposal.unfeasible_html", + title: @spending_proposal.title) %> +

-

<%= t("mailers.unfeasible_spending_proposal.new_html", - url: link_to(t("mailers.unfeasible_spending_proposal.new_href"), - new_spending_proposal_url)) %>

+

+ <%= @spending_proposal.feasible_explanation %> +

-

<%= t("mailers.unfeasible_spending_proposal.reconsider") %>

+

+ <%= t("mailers.unfeasible_spending_proposal.new_html", + url: link_to(t("mailers.unfeasible_spending_proposal.new_href"), + new_spending_proposal_url, style: "color: #2895F1; text-decoration: underline;")) %> +

-

<%= t("mailers.unfeasible_spending_proposal.sorry") %>

+

+ <%= t("mailers.unfeasible_spending_proposal.reconsider_html") %> +

-

<%= t("mailers.unfeasible_spending_proposal.sincerely") %>

-

<%= t("mailers.unfeasible_spending_proposal.signatory") %>

\ No newline at end of file +

+ <%= t("mailers.unfeasible_spending_proposal.sorry") %> +

+ +

+ <%= t("mailers.unfeasible_spending_proposal.sincerely") %>
+ + <%= t("mailers.unfeasible_spending_proposal.signatory") %> +

+ \ No newline at end of file diff --git a/config/locales/mailers.en.yml b/config/locales/mailers.en.yml index 53d2b7c60..b13c8b194 100755 --- a/config/locales/mailers.en.yml +++ b/config/locales/mailers.en.yml @@ -22,11 +22,11 @@ en: title: New response to your comment unfeasible_spending_proposal: hi: "Dear user," - new_html: "For all these, we invite you to elaborate a new proposal that ajusts to the conditions of this process. You can do it following this link: %{url}" + new_html: "For all these, we invite you to elaborate a new proposal that ajusts to the conditions of this process. You can do it following this link: %{url}." new_href: "new investment project" - reconsider: "If you believe that the rejected proposal meets the requirements to be an investment proposal, you can communicate this, within 48 hours, responding to this email. Please include all relevant information to reconsider the proposal as valid." + reconsider_html: "If you believe that the rejected proposal meets the requirements to be an investment proposal, you can communicate this, within 48 hours, responding to this email. Please include all relevant information to reconsider the proposal as valid." sincerely: "Sincerely" signatory: "DEPARTMENT OF PUBLIC PARTICIPATION" sorry: "Sorry for the inconvenience and we again thank you for your invaluable participation." subject: "Your investment project '%{code}' has been marked as unfeasible" - unfeasible: "From the Madrid City Council we want to thank you for your participation in the participatory budgets of the city of Madrid. We regret to inform you that your proposal '%{title}' will be excluded from this participatory process for the following reason:" \ No newline at end of file + unfeasible_html: "From the Madrid City Council we want to thank you for your participation in the participatory budgets of the city of Madrid. We regret to inform you that your proposal '%{title}' will be excluded from this participatory process for the following reason:" \ No newline at end of file diff --git a/config/locales/mailers.es.yml b/config/locales/mailers.es.yml index 0624fa410..cfc099643 100644 --- a/config/locales/mailers.es.yml +++ b/config/locales/mailers.es.yml @@ -22,11 +22,11 @@ es: title: Nueva respuesta a tu comentario unfeasible_spending_proposal: hi: "Estimado usuario," - new_html: "Por todo ello, te invitamos a que elabores una nueva propuesta que se ajuste a las condiciones de este proceso. Esto lo puedes hacer en este enlace: %{url}" + new_html: "Por todo ello, te invitamos a que elabores una nueva propuesta que se ajuste a las condiciones de este proceso. Esto lo puedes hacer en este enlace: %{url}." new_href: "nueva propuesta de inversión" - reconsider: "Si consideras que la propuesta rechazada cumple los requisitos para mantenerla como propuesta de inversión, podrás comunicarlo, en el plazo de 48 horas, respondiendo a este email. Por favor incluye toda la información relevante para reconsiderar la propuesta como válida." + reconsider_html: "Si consideras que la propuesta rechazada cumple los requisitos para mantenerla como propuesta de inversión, podrás comunicarlo, en el plazo de 48 horas, respondiendo a este email. Por favor incluye toda la información relevante para reconsiderar la propuesta como válida." sincerely: "Atentamente" signatory: "DIRECCIÓN GENERAL DE PARTICIPACIÓN CIUDADANA" sorry: "Sentimos las molestias ocasionadas y volvemos a darte las gracias por tu inestimable participación." subject: "Tu propuesta de inversión '%{code}' ha sido marcada como inviable" - unfeasible: "Desde el Ayuntamiento de Madrid queremos agradecer tu participación en los Presupuestos Participativos de la ciudad de Madrid. Lamentamos informarte de que tu propuesta '%{title}' quedará excluida de este proceso participativo por el siguiente motivo:" + unfeasible_html: "Desde el Ayuntamiento de Madrid queremos agradecer tu participación en los Presupuestos Participativos de la ciudad de Madrid. Lamentamos informarte de que tu propuesta '%{title}' quedará excluida de este proceso participativo por el siguiente motivo:" From 57299ec968399a696fffe1fe19439ccc07ae28f3 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 28 Mar 2016 18:26:09 +0200 Subject: [PATCH 020/163] adds rake task to send current unfeasible spending proposals --- app/models/spending_proposal.rb | 2 +- lib/tasks/spending_proposals.rake | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 lib/tasks/spending_proposals.rake diff --git a/app/models/spending_proposal.rb b/app/models/spending_proposal.rb index ea182b3fb..4dc776ae2 100644 --- a/app/models/spending_proposal.rb +++ b/app/models/spending_proposal.rb @@ -73,7 +73,7 @@ class SpendingProposal < ActiveRecord::Base end def unfeasible? - not feasible? + feasible == false end def valuation_finished? diff --git a/lib/tasks/spending_proposals.rake b/lib/tasks/spending_proposals.rake new file mode 100644 index 000000000..eb33eed59 --- /dev/null +++ b/lib/tasks/spending_proposals.rake @@ -0,0 +1,13 @@ +namespace :spending_proposals do + desc "Sends an email to the authors of unfeasible spending proposals" + task send_unfeasible_emails: :environment do + SpendingProposal.find_each do |spending_propsal| + if spending_propsal.marked_as_unfeasible? + spending_propsal.send_unfeasible_email + puts "email sent for proposal #{spending_propsal.title}" + else + puts "this proposal is feasible: #{spending_propsal.title}" + end + end + end +end \ No newline at end of file From 381b66abdbd635df802a825ae29e080ea988989a Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 28 Mar 2016 18:29:59 +0200 Subject: [PATCH 021/163] updates reply email address --- config/locales/mailers.en.yml | 2 +- config/locales/mailers.es.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/locales/mailers.en.yml b/config/locales/mailers.en.yml index b13c8b194..9e18435dd 100755 --- a/config/locales/mailers.en.yml +++ b/config/locales/mailers.en.yml @@ -24,7 +24,7 @@ en: hi: "Dear user," new_html: "For all these, we invite you to elaborate a new proposal that ajusts to the conditions of this process. You can do it following this link: %{url}." new_href: "new investment project" - reconsider_html: "If you believe that the rejected proposal meets the requirements to be an investment proposal, you can communicate this, within 48 hours, responding to this email. Please include all relevant information to reconsider the proposal as valid." + reconsider_html: "If you believe that the rejected proposal meets the requirements to be an investment proposal, you can communicate this, within 48 hours, responding to the email address preparticipativos@madrid.es. Please include all relevant information to reconsider the proposal as valid." sincerely: "Sincerely" signatory: "DEPARTMENT OF PUBLIC PARTICIPATION" sorry: "Sorry for the inconvenience and we again thank you for your invaluable participation." diff --git a/config/locales/mailers.es.yml b/config/locales/mailers.es.yml index cfc099643..2e11604a3 100644 --- a/config/locales/mailers.es.yml +++ b/config/locales/mailers.es.yml @@ -24,7 +24,7 @@ es: hi: "Estimado usuario," new_html: "Por todo ello, te invitamos a que elabores una nueva propuesta que se ajuste a las condiciones de este proceso. Esto lo puedes hacer en este enlace: %{url}." new_href: "nueva propuesta de inversión" - reconsider_html: "Si consideras que la propuesta rechazada cumple los requisitos para mantenerla como propuesta de inversión, podrás comunicarlo, en el plazo de 48 horas, respondiendo a este email. Por favor incluye toda la información relevante para reconsiderar la propuesta como válida." + reconsider_html: "Si consideras que la propuesta rechazada cumple los requisitos para mantenerla como propuesta de inversión, podrás comunicarlo, en el plazo de 48 horas, al correo preparticipativos@madrid.es. Por favor incluye toda la información relevante para reconsiderar la propuesta como válida." sincerely: "Atentamente" signatory: "DIRECCIÓN GENERAL DE PARTICIPACIÓN CIUDADANA" sorry: "Sentimos las molestias ocasionadas y volvemos a darte las gracias por tu inestimable participación." From cfe75932882215f742acf1e049c08f56022efaf1 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 28 Mar 2016 18:43:56 +0200 Subject: [PATCH 022/163] updates method name to be more accurate --- .../valuation/spending_proposals_controller.rb | 2 +- app/models/spending_proposal.rb | 2 +- lib/tasks/spending_proposals.rake | 2 +- spec/models/spending_proposal_spec.rb | 10 +++++----- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/controllers/valuation/spending_proposals_controller.rb b/app/controllers/valuation/spending_proposals_controller.rb index deba1777d..364671d09 100644 --- a/app/controllers/valuation/spending_proposals_controller.rb +++ b/app/controllers/valuation/spending_proposals_controller.rb @@ -19,7 +19,7 @@ class Valuation::SpendingProposalsController < Valuation::BaseController def valuate if valid_price_params? && @spending_proposal.update(valuation_params) - if @spending_proposal.marked_as_unfeasible? + if @spending_proposal.unfeasible_email_pending? @spending_proposal.send_unfeasible_email end diff --git a/app/models/spending_proposal.rb b/app/models/spending_proposal.rb index 4dc776ae2..a084a800e 100644 --- a/app/models/spending_proposal.rb +++ b/app/models/spending_proposal.rb @@ -68,7 +68,7 @@ class SpendingProposal < ActiveRecord::Base end end - def marked_as_unfeasible? + def unfeasible_email_pending? unfeasible_email_sent_at.blank? && unfeasible? && valuation_finished? end diff --git a/lib/tasks/spending_proposals.rake b/lib/tasks/spending_proposals.rake index eb33eed59..b49f2acf5 100644 --- a/lib/tasks/spending_proposals.rake +++ b/lib/tasks/spending_proposals.rake @@ -2,7 +2,7 @@ namespace :spending_proposals do desc "Sends an email to the authors of unfeasible spending proposals" task send_unfeasible_emails: :environment do SpendingProposal.find_each do |spending_propsal| - if spending_propsal.marked_as_unfeasible? + if spending_propsal.unfeasible_email_pending? spending_propsal.send_unfeasible_email puts "email sent for proposal #{spending_propsal.title}" else diff --git a/spec/models/spending_proposal_spec.rb b/spec/models/spending_proposal_spec.rb index 6d506d587..4d320a8d7 100644 --- a/spec/models/spending_proposal_spec.rb +++ b/spec/models/spending_proposal_spec.rb @@ -72,27 +72,27 @@ describe SpendingProposal do end end - describe "#marked_as_unfeasible?" do + describe "#unfeasible_email_pending?" do let(:spending_proposal) { create(:spending_proposal) } it "returns true when marked as unfeasibable and valuation_finished" do spending_proposal.update(feasible: false, valuation_finished: true) - expect(spending_proposal.marked_as_unfeasible?).to eq true + expect(spending_proposal.unfeasible_email_pending?).to eq true end it "returns false when marked as feasible" do spending_proposal.update(feasible: true) - expect(spending_proposal.marked_as_unfeasible?).to eq false + expect(spending_proposal.unfeasible_email_pending?).to eq false end it "returns false when marked as feasable and valuation_finished" do spending_proposal.update(feasible: true, valuation_finished: true) - expect(spending_proposal.marked_as_unfeasible?).to eq false + expect(spending_proposal.unfeasible_email_pending?).to eq false end it "returns false when unfeasible email already sent" do spending_proposal.update(unfeasible_email_sent_at: 1.day.ago) - expect(spending_proposal.marked_as_unfeasible?).to eq false + expect(spending_proposal.unfeasible_email_pending?).to eq false end end From 31aac21a2b1f6453c36456fcd093916317a844cd Mon Sep 17 00:00:00 2001 From: rgarcia Date: Tue, 29 Mar 2016 11:38:04 +0200 Subject: [PATCH 023/163] redirect to login when creating new spending proposal --- app/controllers/spending_proposals_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/spending_proposals_controller.rb b/app/controllers/spending_proposals_controller.rb index 9b64c462d..1c2c83047 100644 --- a/app/controllers/spending_proposals_controller.rb +++ b/app/controllers/spending_proposals_controller.rb @@ -1,9 +1,10 @@ class SpendingProposalsController < ApplicationController include FeatureFlags + before_action :authenticate_user!, except: [:index] + load_and_authorize_resource - before_action :authenticate_user!, except: [:index] before_action :verify_access, only: [:show] before_filter -> { flash.now[:notice] = flash[:notice].html_safe if flash[:html_safe] && flash[:notice] } From 595c5485d6aa25511676546ad86281c9505a4e78 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Tue, 29 Mar 2016 11:38:54 +0200 Subject: [PATCH 024/163] adds code to email body --- app/views/mailer/unfeasible_spending_proposal.html.erb | 2 +- config/locales/mailers.en.yml | 2 +- config/locales/mailers.es.yml | 2 +- spec/features/emails_spec.rb | 1 + 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/views/mailer/unfeasible_spending_proposal.html.erb b/app/views/mailer/unfeasible_spending_proposal.html.erb index fa4e3cf96..1e55106f1 100644 --- a/app/views/mailer/unfeasible_spending_proposal.html.erb +++ b/app/views/mailer/unfeasible_spending_proposal.html.erb @@ -20,7 +20,7 @@

- <%= t("mailers.unfeasible_spending_proposal.reconsider_html") %> + <%= t("mailers.unfeasible_spending_proposal.reconsider_html", code: @spending_proposal.code) %>

diff --git a/config/locales/mailers.en.yml b/config/locales/mailers.en.yml index 9e18435dd..16cc762d6 100755 --- a/config/locales/mailers.en.yml +++ b/config/locales/mailers.en.yml @@ -24,7 +24,7 @@ en: hi: "Dear user," new_html: "For all these, we invite you to elaborate a new proposal that ajusts to the conditions of this process. You can do it following this link: %{url}." new_href: "new investment project" - reconsider_html: "If you believe that the rejected proposal meets the requirements to be an investment proposal, you can communicate this, within 48 hours, responding to the email address preparticipativos@madrid.es. Please include all relevant information to reconsider the proposal as valid." + reconsider_html: "If you believe that the rejected proposal meets the requirements to be an investment proposal, you can communicate this, within 48 hours, responding to the email address preparticipativos@madrid.es. Including the code %{code} in the subject of the email." sincerely: "Sincerely" signatory: "DEPARTMENT OF PUBLIC PARTICIPATION" sorry: "Sorry for the inconvenience and we again thank you for your invaluable participation." diff --git a/config/locales/mailers.es.yml b/config/locales/mailers.es.yml index 2e11604a3..8a16c00ec 100644 --- a/config/locales/mailers.es.yml +++ b/config/locales/mailers.es.yml @@ -24,7 +24,7 @@ es: hi: "Estimado usuario," new_html: "Por todo ello, te invitamos a que elabores una nueva propuesta que se ajuste a las condiciones de este proceso. Esto lo puedes hacer en este enlace: %{url}." new_href: "nueva propuesta de inversión" - reconsider_html: "Si consideras que la propuesta rechazada cumple los requisitos para mantenerla como propuesta de inversión, podrás comunicarlo, en el plazo de 48 horas, al correo preparticipativos@madrid.es. Por favor incluye toda la información relevante para reconsiderar la propuesta como válida." + reconsider_html: "Si consideras que la propuesta rechazada cumple los requisitos para mantenerla como propuesta de inversión, podrás comunicarlo, en el plazo de 48 horas, al correo preparticipativos@madrid.es, indicando necesariamente para su tramitación el código %{code} como asunto del correo, correspondiente a tu propuesta." sincerely: "Atentamente" signatory: "DIRECCIÓN GENERAL DE PARTICIPACIÓN CIUDADANA" sorry: "Sentimos las molestias ocasionadas y volvemos a darte las gracias por tu inestimable participación." diff --git a/spec/features/emails_spec.rb b/spec/features/emails_spec.rb index c6d675a73..4d813493d 100644 --- a/spec/features/emails_spec.rb +++ b/spec/features/emails_spec.rb @@ -144,6 +144,7 @@ feature 'Emails' do expect(email).to have_subject("Your investment project '#{spending_proposal.id}-A#{spending_proposal.administrator.id}' has been marked as unfeasible") expect(email).to deliver_to(spending_proposal.author.email) expect(email).to have_body_text(spending_proposal.title) + expect(email).to have_body_text(spending_proposal.code) expect(email).to have_body_text(spending_proposal.feasible_explanation) end From e52004edc3daa4088b188fd06fce0e3be9fffd07 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Tue, 29 Mar 2016 13:26:08 +0200 Subject: [PATCH 025/163] adds permissions for everyone to see investment projects --- .../spending_proposals_controller.rb | 5 --- spec/features/spending_proposals_spec.rb | 43 +++---------------- 2 files changed, 5 insertions(+), 43 deletions(-) diff --git a/app/controllers/spending_proposals_controller.rb b/app/controllers/spending_proposals_controller.rb index 1c2c83047..76f230575 100644 --- a/app/controllers/spending_proposals_controller.rb +++ b/app/controllers/spending_proposals_controller.rb @@ -5,7 +5,6 @@ class SpendingProposalsController < ApplicationController load_and_authorize_resource - before_action :verify_access, only: [:show] before_filter -> { flash.now[:notice] = flash[:notice].html_safe if flash[:html_safe] && flash[:notice] } feature_flag :spending_proposals @@ -41,8 +40,4 @@ class SpendingProposalsController < ApplicationController params.require(:spending_proposal).permit(:title, :description, :external_url, :geozone_id, :association_name, :terms_of_service, :captcha, :captcha_key) end - def verify_access - raise CanCan::AccessDenied unless current_user.try(:valuator?) || current_user.try(:administrator?) || @spending_proposal.author == current_user - end - end diff --git a/spec/features/spending_proposals_spec.rb b/spec/features/spending_proposals_spec.rb index 0fd31f5f7..8462cc77f 100644 --- a/spec/features/spending_proposals_spec.rb +++ b/spec/features/spending_proposals_spec.rb @@ -113,42 +113,6 @@ feature 'Spending proposals' do expect(page).to have_content(spending_proposal.geozone.name) end - scenario "Show (as valuator)" do - user = create(:user) - admin = create(:valuator, user: user) - login_as(admin.user) - - spending_proposal = create(:spending_proposal, - geozone: create(:geozone), - association_name: 'People of the neighbourhood') - - visit spending_proposal_path(spending_proposal) - - expect(page).to have_content(spending_proposal.title) - expect(page).to have_content(spending_proposal.description) - expect(page).to have_content(spending_proposal.author.name) - expect(page).to have_content(spending_proposal.association_name) - expect(page).to have_content(spending_proposal.geozone.name) - end - - scenario "Show (as author)" do - author = create(:user) - login_as(author) - - spending_proposal = create(:spending_proposal, - geozone: create(:geozone), - association_name: 'People of the neighbourhood', - author: author) - - visit spending_proposal_path(spending_proposal) - - expect(page).to have_content(spending_proposal.title) - expect(page).to have_content(spending_proposal.description) - expect(page).to have_content(spending_proposal.author.name) - expect(page).to have_content(spending_proposal.association_name) - expect(page).to have_content(spending_proposal.geozone.name) - end - scenario "Show (as user)" do user = create(:user) login_as(user) @@ -159,8 +123,11 @@ feature 'Spending proposals' do visit spending_proposal_path(spending_proposal) - expect(page).to_not have_content(spending_proposal.title) - expect(page).to have_content("You do not have permission to access this page") + expect(page).to have_content(spending_proposal.title) + expect(page).to have_content(spending_proposal.description) + expect(page).to have_content(spending_proposal.author.name) + expect(page).to have_content(spending_proposal.association_name) + expect(page).to have_content(spending_proposal.geozone.name) end context "Destroy" do From 63e8950d6c427db331dd6924a1c43fcc6a83b4f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Tue, 29 Mar 2016 13:32:46 +0200 Subject: [PATCH 026/163] adds scopes for feasible values to spending props --- .../concerns/commentable_actions.rb | 3 +- app/models/spending_proposal.rb | 3 ++ app/views/proposals/_comments.html.erb | 1 - spec/models/spending_proposal_spec.rb | 32 +++++++++++++++++++ 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/app/controllers/concerns/commentable_actions.rb b/app/controllers/concerns/commentable_actions.rb index 855ad1de5..01066c8ad 100644 --- a/app/controllers/concerns/commentable_actions.rb +++ b/app/controllers/concerns/commentable_actions.rb @@ -65,8 +65,7 @@ module CommentableActions end end - - def map + def map @resource = resource_model.new @tag_cloud = tag_cloud end diff --git a/app/models/spending_proposal.rb b/app/models/spending_proposal.rb index a084a800e..4b3c7d4f7 100644 --- a/app/models/spending_proposal.rb +++ b/app/models/spending_proposal.rb @@ -24,6 +24,9 @@ class SpendingProposal < ActiveRecord::Base scope :managed, -> { valuation_open.where(valuation_assignments_count: 0).where("administrator_id IS NOT ?", nil) } scope :valuating, -> { valuation_open.where("valuation_assignments_count > 0 AND valuation_finished = ?", false) } scope :valuation_finished, -> { where(valuation_finished: true) } + scope :feasible, -> { where(feasible: true) } + scope :unfeasible, -> { where(feasible: false) } + scope :not_unfeasible, -> { where("feasible IS ? OR feasible = ?", nil, true) } scope :by_admin, -> (admin) { where(administrator_id: admin.presence) } scope :by_tag, -> (tag_name) { tagged_with(tag_name) } diff --git a/app/views/proposals/_comments.html.erb b/app/views/proposals/_comments.html.erb index 4a0bd2aea..31f1cb8ba 100644 --- a/app/views/proposals/_comments.html.erb +++ b/app/views/proposals/_comments.html.erb @@ -2,7 +2,6 @@

-

<%= t("proposals.show.comments_title") %> (<%= @proposal.comments_count %>) diff --git a/spec/models/spending_proposal_spec.rb b/spec/models/spending_proposal_spec.rb index 4d320a8d7..ebe3573a4 100644 --- a/spec/models/spending_proposal_spec.rb +++ b/spec/models/spending_proposal_spec.rb @@ -227,6 +227,38 @@ describe SpendingProposal do expect(valuation_finished.first).to eq(spending_proposal3) end end + + describe "feasible" do + it "should return all feasible spending proposals" do + feasible_spending_proposal = create(:spending_proposal, feasible: true) + create(:spending_proposal) + + expect(SpendingProposal.feasible).to eq [feasible_spending_proposal] + end + end + + describe "unfeasible" do + it "should return all unfeasible spending proposals" do + unfeasible_spending_proposal = create(:spending_proposal, feasible: false) + create(:spending_proposal, feasible: true) + + expect(SpendingProposal.unfeasible).to eq [unfeasible_spending_proposal] + end + end + + describe "not_unfeasible" do + it "should return all not unfeasible spending proposals" do + not_unfeasible_spending_proposal_1 = create(:spending_proposal, feasible: true) + not_unfeasible_spending_proposal_2 = create(:spending_proposal) + create(:spending_proposal, feasible: false) + + not_unfeasibles = SpendingProposal.not_unfeasible + + expect(not_unfeasibles.size).to eq(2) + expect(not_unfeasibles.include?(not_unfeasible_spending_proposal_1)).to eq(true) + expect(not_unfeasibles.include?(not_unfeasible_spending_proposal_2)).to eq(true) + end + end end end From 4ddb778bed056127fdc3c7b1d5246711e616d533 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Tue, 29 Mar 2016 14:12:19 +0200 Subject: [PATCH 027/163] refactors scopes and methods used only in admin --- app/controllers/admin/spending_proposals_controller.rb | 2 +- app/controllers/valuation/spending_proposals_controller.rb | 2 +- app/models/spending_proposal.rb | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/admin/spending_proposals_controller.rb b/app/controllers/admin/spending_proposals_controller.rb index 25707e66e..61f9aa78d 100644 --- a/app/controllers/admin/spending_proposals_controller.rb +++ b/app/controllers/admin/spending_proposals_controller.rb @@ -7,7 +7,7 @@ class Admin::SpendingProposalsController < Admin::BaseController load_and_authorize_resource def index - @spending_proposals = SpendingProposal.search(params, @current_filter).order(created_at: :desc).page(params[:page]) + @spending_proposals = SpendingProposal.scoped_filter(params, @current_filter).order(created_at: :desc).page(params[:page]) end def show diff --git a/app/controllers/valuation/spending_proposals_controller.rb b/app/controllers/valuation/spending_proposals_controller.rb index 364671d09..c5f822b40 100644 --- a/app/controllers/valuation/spending_proposals_controller.rb +++ b/app/controllers/valuation/spending_proposals_controller.rb @@ -10,7 +10,7 @@ class Valuation::SpendingProposalsController < Valuation::BaseController def index if current_user.valuator? - @spending_proposals = SpendingProposal.search(params_for_current_valuator, @current_filter).order(created_at: :desc).page(params[:page]) + @spending_proposals = SpendingProposal.scoped_filter(params_for_current_valuator, @current_filter).order(created_at: :desc).page(params[:page]) else @spending_proposals = SpendingProposal.none.page(params[:page]) end diff --git a/app/models/spending_proposal.rb b/app/models/spending_proposal.rb index 4b3c7d4f7..9e4c4492e 100644 --- a/app/models/spending_proposal.rb +++ b/app/models/spending_proposal.rb @@ -32,7 +32,7 @@ class SpendingProposal < ActiveRecord::Base scope :by_tag, -> (tag_name) { tagged_with(tag_name) } scope :by_valuator, -> (valuator) { where("valuation_assignments.valuator_id = ?", valuator.presence).joins(:valuation_assignments) } - scope :for_render, -> { includes(:geozone, administrator: :user, valuators: :user) } + scope :for_render, -> { includes(:geozone) } def description super.try :html_safe @@ -42,14 +42,14 @@ class SpendingProposal < ActiveRecord::Base params.select{|x,_| %w{geozone_id administrator_id tag_name valuator_id}.include? x.to_s } end - def self.search(params, current_filter) + def self.scoped_filter(params, current_filter) results = self results = results.by_geozone(params[:geozone_id]) if params[:geozone_id].present? results = results.by_admin(params[:administrator_id]) if params[:administrator_id].present? results = results.by_tag(params[:tag_name]) if params[:tag_name].present? results = results.by_valuator(params[:valuator_id]) if params[:valuator_id].present? results = results.send(current_filter) if current_filter.present? - results.for_render + results.includes(:geozone, administrator: :user, valuators: :user) end def self.by_geozone(geozone) From ed1ec1c55380c80cced933b294ada84eadae8ae2 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Tue, 29 Mar 2016 14:53:46 +0200 Subject: [PATCH 028/163] adds votes to spending proposals --- app/controllers/application_controller.rb | 4 ++ .../spending_proposals_controller.rb | 12 ++++ app/models/abilities/common.rb | 1 + app/models/spending_proposal.rb | 15 +++++ app/models/user.rb | 5 ++ app/views/_votes.html.erb/_form.html.erb | 51 +++++++++++++++ app/views/_votes.html.erb/index.html.erb | 16 +++++ app/views/_votes.html.erb/new.html.erb | 27 ++++++++ app/views/_votes.html.erb/show.html.erb | 34 ++++++++++ app/views/spending_proposals/_votes.html.erb | 47 ++++++++++++++ app/views/spending_proposals/show.html.erb | 5 ++ app/views/spending_proposals/vote.js.erb | 1 + config/initializers/vote_extensions.rb | 4 ++ config/locales/en.yml | 32 ++++++++++ config/routes.rb | 6 +- ...5418_add_votes_up_to_spending_proposals.rb | 5 ++ db/schema.rb | 3 +- spec/features/votes_spec.rb | 62 ++++++++++++++++++- 18 files changed, 327 insertions(+), 3 deletions(-) create mode 100644 app/views/_votes.html.erb/_form.html.erb create mode 100644 app/views/_votes.html.erb/index.html.erb create mode 100644 app/views/_votes.html.erb/new.html.erb create mode 100644 app/views/_votes.html.erb/show.html.erb create mode 100644 app/views/spending_proposals/_votes.html.erb create mode 100644 app/views/spending_proposals/vote.js.erb create mode 100644 db/migrate/20160329115418_add_votes_up_to_spending_proposals.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 280dd0c4d..640adf299 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -77,6 +77,10 @@ class ApplicationController < ActionController::Base @proposal_votes = current_user ? current_user.proposal_votes(proposals) : {} end + def set_spending_proposal_votes(spending_proposals) + @spending_proposal_votes = current_user ? current_user.spending_proposal_votes(spending_proposals) : {} + end + def set_comment_flags(comments) @comment_flags = current_user ? current_user.comment_flags(comments) : {} end diff --git a/app/controllers/spending_proposals_controller.rb b/app/controllers/spending_proposals_controller.rb index 76f230575..20add5c24 100644 --- a/app/controllers/spending_proposals_controller.rb +++ b/app/controllers/spending_proposals_controller.rb @@ -9,6 +9,8 @@ class SpendingProposalsController < ApplicationController feature_flag :spending_proposals + respond_to :html, :js + def index end @@ -16,6 +18,10 @@ class SpendingProposalsController < ApplicationController @spending_proposal = SpendingProposal.new end + def show + set_spending_proposal_votes(@spending_proposal) + end + def create @spending_proposal = SpendingProposal.new(spending_proposal_params) @spending_proposal.author = current_user @@ -34,6 +40,12 @@ class SpendingProposalsController < ApplicationController redirect_to user_path(current_user, filter: 'spending_proposals'), notice: t('flash.actions.destroy.spending_proposal') end + def vote + @spending_proposal.register_vote(current_user, 'yes') + set_spending_proposal_votes(@spending_proposal) + end + + private def spending_proposal_params diff --git a/app/models/abilities/common.rb b/app/models/abilities/common.rb index 92eacea52..2438feadb 100644 --- a/app/models/abilities/common.rb +++ b/app/models/abilities/common.rb @@ -43,6 +43,7 @@ module Abilities if user.level_two_or_three_verified? can :vote, Proposal can :vote_featured, Proposal + can :vote, SpendingProposal can :create, SpendingProposal can :destroy, SpendingProposal, author_id: user.id end diff --git a/app/models/spending_proposal.rb b/app/models/spending_proposal.rb index a084a800e..561e6ab52 100644 --- a/app/models/spending_proposal.rb +++ b/app/models/spending_proposal.rb @@ -4,6 +4,7 @@ class SpendingProposal < ActiveRecord::Base include Taggable apply_simple_captcha + acts_as_votable belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id' belongs_to :geozone @@ -80,6 +81,10 @@ class SpendingProposal < ActiveRecord::Base valuation_finished end + def total_votes + cached_votes_up + end + def code "#{id}" + (administrator.present? ? "-A#{administrator.id}" : "") end @@ -89,4 +94,14 @@ class SpendingProposal < ActiveRecord::Base update(unfeasible_email_sent_at: Time.now) end + def votable_by?(user) + user && user.level_two_or_three_verified? + end + + def register_vote(user, vote_value) + if votable_by?(user) + vote_by(voter: user, vote: vote_value) + end + end + end diff --git a/app/models/user.rb b/app/models/user.rb index 3b58fb607..bc4b0f120 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -83,6 +83,11 @@ class User < ActiveRecord::Base voted.each_with_object({}) { |v, h| h[v.votable_id] = v.value } end + def spending_proposal_votes(spending_proposals) + voted = votes.for_spending_proposals(spending_proposals) + voted.each_with_object({}) { |v, h| h[v.votable_id] = v.value } + end + def comment_flags(comments) comment_flags = flags.for_comments(comments) comment_flags.each_with_object({}){ |f, h| h[f.flaggable_id] = true } diff --git a/app/views/_votes.html.erb/_form.html.erb b/app/views/_votes.html.erb/_form.html.erb new file mode 100644 index 000000000..0d6ef0402 --- /dev/null +++ b/app/views/_votes.html.erb/_form.html.erb @@ -0,0 +1,51 @@ +<%= form_for(@spending_proposal, url: form_url) do |f| %> + <%= render 'shared/errors', resource: @spending_proposal %> + +
+
+ <%= f.label :title, t("spending_proposals.form.title") %> + <%= f.text_field :title, maxlength: SpendingProposal.title_max_length, placeholder: t("spending_proposals.form.title"), label: false %> +
+ +
+ <%= f.label :description, t("spending_proposals.form.description") %> + <%= f.cktext_area :description, maxlength: SpendingProposal.description_max_length, ckeditor: { language: I18n.locale }, label: false %> +
+ +
+ <%= f.label :external_url, t("spending_proposals.form.external_url") %> + <%= f.text_field :external_url, placeholder: t("spending_proposals.form.external_url"), label: false %> +
+ +
+ <%= f.label :geozone_id, t("spending_proposals.form.geozone") %> + <%= f.select :geozone_id, geozone_select_options, {include_blank: t("geozones.none"), label: false} %> +
+ +
+ <%= f.label :association_name, t("spending_proposals.form.association_name_label") %> + <%= f.text_field :association_name, placeholder: t("spending_proposals.form.association_name"), label: false %> +
+ +
+ <% if @spending_proposal.new_record? %> + <%= f.label :terms_of_service do %> + <%= f.check_box :terms_of_service, title: t('form.accept_terms_title'), label: false %> + + <%= t("form.accept_terms", + policy: link_to(t("form.policy"), "/privacy", target: "blank"), + conditions: link_to(t("form.conditions"), "/conditions", target: "blank")).html_safe %> + + <% end %> + <% end %> +
+ +
+ <%= f.simple_captcha input_html: { required: false } %> +
+ +
+ <%= f.submit(class: "button", value: t("spending_proposals.form.submit_buttons.#{action_name}")) %> +
+
+<% end %> \ No newline at end of file diff --git a/app/views/_votes.html.erb/index.html.erb b/app/views/_votes.html.erb/index.html.erb new file mode 100644 index 000000000..00a1b6442 --- /dev/null +++ b/app/views/_votes.html.erb/index.html.erb @@ -0,0 +1,16 @@ +<% provide :title do %><%= t('spending_proposals.index.title') %><% end %> +
+
+
+

<%= t('spending_proposals.index.title') %>

+ +

<%= t('spending_proposals.index.text_html') %>

+ + <% if can? :create, SpendingProposal %> + <%= link_to t('spending_proposals.index.create_link'), new_spending_proposal_path, class: 'button' %> + <% else %> +

<%= t('spending_proposals.index.verified_only', verify_account: link_to(t('spending_proposals.index.verify_account'), verification_path)).html_safe %>

+ <% end %> +
+
+
\ No newline at end of file diff --git a/app/views/_votes.html.erb/new.html.erb b/app/views/_votes.html.erb/new.html.erb new file mode 100644 index 000000000..a8d35338f --- /dev/null +++ b/app/views/_votes.html.erb/new.html.erb @@ -0,0 +1,27 @@ +
+ +
+ <%= link_to spending_proposals_path, class: "back" do %> + + <%= t("spending_proposals.new.back_link") %> + <% end %> +

<%= t("spending_proposals.new.start_new") %>

+
+ <%= link_to "/spending_proposals_info", title: t('shared.target_blank_html'), target: "_blank" do %> + <%= t("spending_proposals.new.more_info")%> + <% end %> +
+ <%= render "spending_proposals/form", form_url: spending_proposals_url %> +
+ +
+ +

<%= t("spending_proposals.new.recommendations_title") %>

+
    +
  • <%= t("spending_proposals.new.recommendation_one") %>
  • +
  • <%= t("spending_proposals.new.recommendation_two") %>
  • +
  • <%= t("spending_proposals.new.recommendation_three") %>
  • +
+
+ +
\ No newline at end of file diff --git a/app/views/_votes.html.erb/show.html.erb b/app/views/_votes.html.erb/show.html.erb new file mode 100644 index 000000000..1aaa3d805 --- /dev/null +++ b/app/views/_votes.html.erb/show.html.erb @@ -0,0 +1,34 @@ +<% provide :title do %><%= @spending_proposal.title %><% end %> + +
+
+
+ +

<%= @spending_proposal.title %>

+ +
+ <%= render '/shared/author_info', resource: @spending_proposal %> + +  •  + <%= l @spending_proposal.created_at.to_date %> +  •  + <%= geozone_name(@spending_proposal) %> +
+ + <%= safe_html_with_links @spending_proposal.description.html_safe %> + + <% if @spending_proposal.external_url.present? %> + + <% end %> + +
+ +
+ <%= render 'votes', + { spending_proposal: @spending_proposal, vote_url: vote_spending_proposal_path(@spending_proposal, value: 'yes') } %> +
+ +
+
\ No newline at end of file diff --git a/app/views/spending_proposals/_votes.html.erb b/app/views/spending_proposals/_votes.html.erb new file mode 100644 index 000000000..652df8954 --- /dev/null +++ b/app/views/spending_proposals/_votes.html.erb @@ -0,0 +1,47 @@ +
+ + + <%= t("spending_proposals.spending_proposal.supports", count: spending_proposal.total_votes) %>  + + +
+ <% if voted_for?(@spending_proposal_votes, spending_proposal) %> +
+ <%= t("spending_proposals.spending_proposal.already_supported") %> +
+ <% else %> + <%= link_to vote_url, + class: "button button-support small expanded", + title: t('spending_proposals.spending_proposal.support_title'), method: "post", remote: true do %> + <%= t("spending_proposals.spending_proposal.support") %> + <% end %> + <% end %> +
+ + <% if user_signed_in? && current_user.organization? %> + + <% elsif user_signed_in? && !spending_proposal.votable_by?(current_user)%> + + <% elsif !user_signed_in? %> + + <% end %> + + <% if voted_for?(@spending_proposal_votes, spending_proposal) && setting['twitter_handle'] %> + + <% end %> +
diff --git a/app/views/spending_proposals/show.html.erb b/app/views/spending_proposals/show.html.erb index 987118a6a..1aaa3d805 100644 --- a/app/views/spending_proposals/show.html.erb +++ b/app/views/spending_proposals/show.html.erb @@ -25,5 +25,10 @@

+
+ <%= render 'votes', + { spending_proposal: @spending_proposal, vote_url: vote_spending_proposal_path(@spending_proposal, value: 'yes') } %> +
+
\ No newline at end of file diff --git a/app/views/spending_proposals/vote.js.erb b/app/views/spending_proposals/vote.js.erb new file mode 100644 index 000000000..4fa350aac --- /dev/null +++ b/app/views/spending_proposals/vote.js.erb @@ -0,0 +1 @@ +$("#<%= dom_id(@spending_proposal) %>_votes").html('<%= j render("spending_proposals/votes", spending_proposal: @spending_proposal) %>'); \ No newline at end of file diff --git a/config/initializers/vote_extensions.rb b/config/initializers/vote_extensions.rb index 50fb60c9f..345cb8f01 100644 --- a/config/initializers/vote_extensions.rb +++ b/config/initializers/vote_extensions.rb @@ -7,6 +7,10 @@ ActsAsVotable::Vote.class_eval do where(votable_type: 'Proposal', votable_id: proposals) end + def self.for_spending_proposals(spending_proposals) + where(votable_type: 'SpendingProposal', votable_id: spending_proposals) + end + def value vote_flag end diff --git a/config/locales/en.yml b/config/locales/en.yml index 1f752a9f2..08e289109 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -426,6 +426,38 @@ en: recommendations_title: How to create a spending proposal start_new: Create spending proposal wrong_price_format: Only integer numbers + spending_proposal: + already_supported: You have already supported this. Share it! + comments: + one: 1 comment + other: "%{count} comments" + zero: No comments + proposal: Proposal + reason_for_supports_necessary: 2% of Census + support: Support + support_title: Support this proposal + supports: + one: 1 support + other: "%{count} supports" + zero: No supports + supports_necessary: "%{number} supports needed" + total_percent: 100% + show: + author_deleted: User deleted + back_link: Go back + code: 'Proposal code:' + comments: + one: 1 comment + other: "%{count} comments" + zero: No comments + comments_title: Comments + edit_proposal_link: Edit + flag: This proposal has been flagged as inappropriate by several users. + login_to_comment: You must %{signin} or %{signup} to leave a comment. + share: Share + update: + form: + submit_button: Save changes stats: index: visits: Visits diff --git a/config/routes.rb b/config/routes.rb index 680f657ab..0d704be04 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -66,7 +66,11 @@ Rails.application.routes.draw do end scope '/participatory_budget' do - resources :spending_proposals, only: [:index, :new, :create, :show, :destroy], path: 'investment_projects' + resources :spending_proposals, only: [:index, :new, :create, :show, :destroy], path: 'investment_projects' do + member do + post :vote + end + end end resources :stats, only: [:index] diff --git a/db/migrate/20160329115418_add_votes_up_to_spending_proposals.rb b/db/migrate/20160329115418_add_votes_up_to_spending_proposals.rb new file mode 100644 index 000000000..aa9397c2e --- /dev/null +++ b/db/migrate/20160329115418_add_votes_up_to_spending_proposals.rb @@ -0,0 +1,5 @@ +class AddVotesUpToSpendingProposals < ActiveRecord::Migration + def change + add_column :spending_proposals, :cached_votes_up, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index c6c5faa19..b5daf6abd 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: 20160328152843) do +ActiveRecord::Schema.define(version: 20160329115418) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -312,6 +312,7 @@ ActiveRecord::Schema.define(version: 20160328152843) do t.integer "price_first_year", limit: 8 t.string "time_scope" t.datetime "unfeasible_email_sent_at" + t.integer "cached_votes_up" end add_index "spending_proposals", ["author_id"], name: "index_spending_proposals_on_author_id", using: :btree diff --git a/spec/features/votes_spec.rb b/spec/features/votes_spec.rb index 3ccf6bcdb..c8164de2c 100644 --- a/spec/features/votes_spec.rb +++ b/spec/features/votes_spec.rb @@ -313,7 +313,7 @@ feature 'Votes' do scenario 'Not logged user trying to vote comments in proposals', :js do proposal = create(:proposal) comment = create(:comment, commentable: proposal) - + visit comment_path(comment) within("#comment_#{comment.id}_reply") do find("div.votes").hover @@ -361,4 +361,64 @@ feature 'Votes' do expect_message_only_verified_can_vote_proposals end end + + feature 'Spending Proposals' do + background { login_as(@manuela) } + + xscenario "Index shows user votes on proposals" do + proposal1 = create(:proposal) + proposal2 = create(:proposal) + proposal3 = create(:proposal) + create(:vote, voter: @manuela, votable: proposal1, vote_flag: true) + + visit proposals_path + + within("#proposals") do + within("#proposal_#{proposal1.id}_votes") do + expect(page).to have_content "You have already supported this proposal. Share it!" + end + + within("#proposal_#{proposal2.id}_votes") do + expect(page).to_not have_content "You have already supported this proposal. Share it!" + end + + within("#proposal_#{proposal3.id}_votes") do + expect(page).to_not have_content "You have already supported this proposal. Share it!" + end + end + end + + feature 'Single spending proposal' do + background do + @proposal = create(:spending_proposal) + end + + scenario 'Show no votes' do + visit spending_proposal_path(@proposal) + expect(page).to have_content "No supports" + end + + scenario 'Trying to vote multiple times', :js do + visit spending_proposal_path(@proposal) + + within('.supports') do + find('.in-favor a').click + expect(page).to have_content "1 support" + + expect(page).to_not have_selector ".in-favor a" + end + end + + scenario 'Create from proposal show', :focus, :js do + visit spending_proposal_path(@proposal) + + within('.supports') do + find('.in-favor a').click + + expect(page).to have_content "1 support" + expect(page).to have_content "You have already supported this. Share it!" + end + end + end + end end From d8a0af13eb4186ccb4b95c87aef5225c1069fc56 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Tue, 29 Mar 2016 16:39:58 +0200 Subject: [PATCH 029/163] Adds styles for investment projects --- app/assets/stylesheets/participation.scss | 75 ++++++++++++++++++++--- 1 file changed, 68 insertions(+), 7 deletions(-) diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index 6a12477eb..eb2945deb 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -274,7 +274,7 @@ .debate-new, .debate-edit, .proposal-new, .proposal-edit, -.spending-proposal-new, .spending-proposal-edit { +.spending-proposal-new, .spending-proposal-edit { .back { @include back; @@ -546,7 +546,7 @@ } } -.debate, .proposal { +.debate, .proposal, .investment-project { margin-bottom: 0; margin-top: 0; @@ -565,7 +565,7 @@ padding-bottom: rem-calc(12); } - .label-debate, .label-proposal { + .label-debate, .label-proposal, .label-investment-project { background: none; clear: both; display: block; @@ -587,6 +587,10 @@ color: $proposals; } + .label-investment-project { + color: $budget; + } + h3 { font-weight: bold; margin: 0; @@ -596,7 +600,7 @@ } } - .debate-content, .proposal-content { + .debate-content, .proposal-content, .investment-project-content { margin: 0; min-height: rem-calc(180); position: relative; @@ -606,7 +610,7 @@ } } - .icon-debates, .icon-proposals { + .icon-debates, .icon-proposals, .icon-budget { font-size: rem-calc(18); line-height: $line-height; position: absolute; @@ -623,7 +627,13 @@ left: rem-calc(72); } - .debate-info, .proposal-info { + .icon-budget { + color: $budget; + font-size: $small-font-size; + left: rem-calc(122); + } + + .debate-info, .proposal-info, .investment-project-info { color: $text-medium; font-size: $small-font-size; margin: rem-calc(6) 0 0; @@ -638,7 +648,7 @@ } } - .debate-description, .proposal-description { + .debate-description, .proposal-description, .investment-project-description { color: $text; font-size: rem-calc(13); height: rem-calc(72); @@ -799,6 +809,57 @@ } } +.investment-project { + + .supports { + @include supports; + background: none; + border: 0; + border-left: 1px solid $border; + margin: 0 rem-calc(-12); + min-height: rem-calc(180); + padding-top: $line-height*2; + + &:after { + content: none; + } + + .button-support { + background: $budget; + color: white; + + &:hover { + background: $proposals-border; + color: white; + cursor: pointer; + } + + &:active { + opacity: .75; + } + } + + .total-supports { + color: $budget; + font-size: $base-font-size; + font-weight: bold; + } + + .not-logged, + .organizations-votes, + .anonymous-votes { + background: rgba(69,67,114,.96); + color: white; + padding: rem-calc(12); + } + + .anonymous-votes p, .anonymous-votes a, + .organizations-votes p { + color: white; + } + } +} + .proposals-summary { .panel { From a6d7f9b323d0cf12575986f9221aa8274f47d67e Mon Sep 17 00:00:00 2001 From: rgarcia Date: Tue, 29 Mar 2016 16:44:15 +0200 Subject: [PATCH 030/163] runs all specs --- spec/features/votes_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/votes_spec.rb b/spec/features/votes_spec.rb index c8164de2c..caadf2637 100644 --- a/spec/features/votes_spec.rb +++ b/spec/features/votes_spec.rb @@ -409,7 +409,7 @@ feature 'Votes' do end end - scenario 'Create from proposal show', :focus, :js do + scenario 'Create from proposal show', :js do visit spending_proposal_path(@proposal) within('.supports') do From 6008244ecfb753ffbf9f16c4b968e83927e0d978 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Tue, 29 Mar 2016 16:46:24 +0200 Subject: [PATCH 031/163] adds basic spending_proposals index --- .../spending_proposals_controller.rb | 2 + .../spending_proposals/_sidebar.html.erb | 11 ++++ .../_spending_proposal.html.erb | 53 +++++++++++++++++++ app/views/spending_proposals/index.html.erb | 41 ++++++++++---- config/i18n-tasks.yml | 1 + config/locales/en.yml | 14 +++-- config/locales/es.yml | 14 +++-- spec/features/spending_proposals_spec.rb | 16 +++--- 8 files changed, 125 insertions(+), 27 deletions(-) create mode 100644 app/views/spending_proposals/_sidebar.html.erb create mode 100644 app/views/spending_proposals/_spending_proposal.html.erb diff --git a/app/controllers/spending_proposals_controller.rb b/app/controllers/spending_proposals_controller.rb index 1c2c83047..28c1862e6 100644 --- a/app/controllers/spending_proposals_controller.rb +++ b/app/controllers/spending_proposals_controller.rb @@ -11,6 +11,8 @@ class SpendingProposalsController < ApplicationController feature_flag :spending_proposals def index + @spending_proposals = @search_terms.present? ? SpendingProposal.search(@search_terms) : SpendingProposal.all + @spending_proposals = @spending_proposals.page(params[:page]).for_render end def new diff --git a/app/views/spending_proposals/_sidebar.html.erb b/app/views/spending_proposals/_sidebar.html.erb new file mode 100644 index 000000000..7ab1ab525 --- /dev/null +++ b/app/views/spending_proposals/_sidebar.html.erb @@ -0,0 +1,11 @@ + + +
+
+ <% Geozone.names.each do |geozone| %> + <%= link_to geozone, spending_proposals_path(search: geozone) %> + <% end %> +
+ + +
\ No newline at end of file diff --git a/app/views/spending_proposals/_spending_proposal.html.erb b/app/views/spending_proposals/_spending_proposal.html.erb new file mode 100644 index 000000000..4437fba0b --- /dev/null +++ b/app/views/spending_proposals/_spending_proposal.html.erb @@ -0,0 +1,53 @@ +
+
+
+ +
+
+ + <% cache [locale_and_user_status(spending_proposal), 'index', spending_proposal, spending_proposal.author] do %> + <%= t("spending_proposals.spending_proposal.spending_proposal") %> + +

<%= link_to spending_proposal.title, spending_proposal_path(spending_proposal) %>

+

+ + <%= l spending_proposal.created_at.to_date %> + + <% if spending_proposal.author.hidden? || spending_proposal.author.erased? %> +  •  + + <%= t("spending_proposals.show.author_deleted") %> + + <% else %> +  •  + + <%= spending_proposal.author.name %> + + <% if spending_proposal.author.official? %> +  •  + + <%= spending_proposal.author.official_position %> + + <% end %> + <% end %> + + <% if spending_proposal.author.verified_organization? %> +  •  + + <%= t("shared.collective") %> + + <% end %> +

+
+

<%= link_to spending_proposal.description, spending_proposal_path(spending_proposal) %>

+
+
+ <% end %> +
+
+ + + +
+
+
diff --git a/app/views/spending_proposals/index.html.erb b/app/views/spending_proposals/index.html.erb index 00a1b6442..6f3529369 100644 --- a/app/views/spending_proposals/index.html.erb +++ b/app/views/spending_proposals/index.html.erb @@ -1,16 +1,35 @@ <% provide :title do %><%= t('spending_proposals.index.title') %><% end %> -
-
-
-

<%= t('spending_proposals.index.title') %>

+<% content_for :header_addon do %> + <%= render "shared/search_form", + search_path: spending_proposals_path(page: 1), + i18n_namespace: "spending_proposals.index.search_form" %> +<% end %> -

<%= t('spending_proposals.index.text_html') %>

+
+
+
- <% if can? :create, SpendingProposal %> - <%= link_to t('spending_proposals.index.create_link'), new_spending_proposal_path, class: 'button' %> - <% else %> -

<%= t('spending_proposals.index.verified_only', verify_account: link_to(t('spending_proposals.index.verify_account'), verification_path)).html_safe %>

- <% end %> +
+ <% if @search_terms %> +

+ <%= page_entries_info @spending_proposals %> + <%= t("spending_proposals.index.search_results", count: @spending_proposals.size, search_term: @search_terms) %> +

+ <% end %> +
+ +
+ <%= link_to t("spending_proposals.index.start_proposal"), new_spending_proposal_path, class: 'button expanded' %> +
+ <%= render partial: 'spending_proposals/spending_proposal', collection: @spending_proposals %> + <%= paginate @spending_proposals %>
+ +
+ +
+
-
\ No newline at end of file + diff --git a/config/i18n-tasks.yml b/config/i18n-tasks.yml index c5e88d8dd..40086aab9 100644 --- a/config/i18n-tasks.yml +++ b/config/i18n-tasks.yml @@ -131,6 +131,7 @@ ignore_unused: - 'proposals.index.select_order' - 'proposals.index.orders.*' - 'proposals.index.search_form.*' + - 'spending_proposals.index.search_form.*' - 'notifications.index.comments_on*' - 'notifications.index.replies_to*' - 'helpers.page_entries_info.*' # kaminari diff --git a/config/locales/en.yml b/config/locales/en.yml index 1f752a9f2..158740c47 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -412,11 +412,13 @@ en: new: Create title: Spending proposal title index: - create_link: Create spending proposal - text_html: Here you can send spending proposals to be considered in the frame of the annual participatory budgeting. title: Participatory budgeting - verified_only: Only verified users can create spending proposals, %{verify_account}. - verify_account: verify your account + search_form: + button: Search + placeholder: Investment projects... + title: Search + sidebar: + geozones: Scope of operation new: back_link: Back more_info: How do participatory budgeting works? @@ -425,6 +427,10 @@ en: recommendation_two: Any proposal or comment suggesting illegal action will be deleted. recommendations_title: How to create a spending proposal start_new: Create spending proposal + show: + author_deleted: User deleted + spending_proposal: + spending_proposal: Investment project wrong_price_format: Only integer numbers stats: index: diff --git a/config/locales/es.yml b/config/locales/es.yml index 0e7a8b125..8c6ce610c 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -412,11 +412,13 @@ es: new: Crear title: Título de la propuesta de gasto index: - create_link: Enviar propuesta de gasto - text_html: Desde esta sección podrás sugerir propuestas de gasto que irán asociadas a las partidas de presupuestos ciudadanos.
El requisito principal es que sean propuestas presupuestables. title: Presupuestos participativos - verified_only: Sólo los usuarios verificados pueden crear propuestas de gasto, %{verify_account}. - verify_account: verifica tu cuenta + search_form: + button: Buscar + placeholder: Propuestas de inversión... + title: Buscar + sidebar: + geozones: Ámbitos de actuación new: back_link: Volver more_info: "¿Cómo funcionan los presupuestos participativos?" @@ -425,6 +427,10 @@ es: recommendation_two: Cualquier propuesta o comentario que implique acciones ilegales será eliminada. recommendations_title: Cómo crear una propuesta de gasto start_new: Crear una propuesta de gasto + show: + author_deleted: Usuario eliminado + spending_proposal: + spending_proposal: Propuesta de inversión wrong_price_format: Solo puede incluir caracteres numéricos stats: index: diff --git a/spec/features/spending_proposals_spec.rb b/spec/features/spending_proposals_spec.rb index 0fd31f5f7..df9f041b7 100644 --- a/spec/features/spending_proposals_spec.rb +++ b/spec/features/spending_proposals_spec.rb @@ -5,17 +5,17 @@ feature 'Spending proposals' do let(:author) { create(:user, :level_two, username: 'Isabel') } scenario 'Index' do - visit spending_proposals_path - - expect(page).to_not have_link('Create spending proposal', href: new_spending_proposal_path) - expect(page).to have_link('verify your account') - - login_as(author) + spending_proposals = [create(:spending_proposal), create(:spending_proposal), create(:spending_proposal)] visit spending_proposals_path - expect(page).to have_link('Create spending proposal', href: new_spending_proposal_path) - expect(page).to_not have_link('verify your account') + expect(page).to have_selector('#investment-projects .investment-project', count: 3) + spending_proposals.each do |spending_proposal| + within('#investment-projects') do + expect(page).to have_content spending_proposal.title + expect(page).to have_css("a[href='#{spending_proposal_path(spending_proposal)}']", text: spending_proposal.title) + end + end end scenario 'Create' do From d50700738481ea01e5cff6977be6dca5b8faa1ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Tue, 29 Mar 2016 17:04:12 +0200 Subject: [PATCH 032/163] adds missing i18n keys --- app/views/spending_proposals/index.html.erb | 2 +- config/locales/en.yml | 5 +++++ config/locales/es.yml | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/views/spending_proposals/index.html.erb b/app/views/spending_proposals/index.html.erb index 6f3529369..499948691 100644 --- a/app/views/spending_proposals/index.html.erb +++ b/app/views/spending_proposals/index.html.erb @@ -19,7 +19,7 @@
- <%= link_to t("spending_proposals.index.start_proposal"), new_spending_proposal_path, class: 'button expanded' %> + <%= link_to t("spending_proposals.index.start_spending_proposal"), new_spending_proposal_path, class: 'button expanded' %>
<%= render partial: 'spending_proposals/spending_proposal', collection: @spending_proposals %> <%= paginate @spending_proposals %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 158740c47..b37c5568b 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -417,8 +417,13 @@ en: button: Search placeholder: Investment projects... title: Search + search_results: + one: " containing the term '%{search_term}'" + other: " containing the term '%{search_term}'" sidebar: geozones: Scope of operation + feasibility: Feasibility + start_spending_proposal: Create a spending proposal new: back_link: Back more_info: How do participatory budgeting works? diff --git a/config/locales/es.yml b/config/locales/es.yml index 8c6ce610c..fe9ec06cf 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -417,8 +417,13 @@ es: button: Buscar placeholder: Propuestas de inversión... title: Buscar + search_results: + one: " que contiene '%{search_term}'" + other: " que contienen '%{search_term}'" sidebar: geozones: Ámbitos de actuación + feasibility: Viabilidad + start_spending_proposal: Crea una propuesta de inversión new: back_link: Volver more_info: "¿Cómo funcionan los presupuestos participativos?" From 6f723a871f41af7bd21f494caced6315f00c6323 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Tue, 29 Mar 2016 17:08:31 +0200 Subject: [PATCH 033/163] allows only admins to delete spending proposals --- app/models/abilities/administrator.rb | 2 +- app/models/abilities/common.rb | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/models/abilities/administrator.rb b/app/models/abilities/administrator.rb index 78cb60806..1b440795f 100644 --- a/app/models/abilities/administrator.rb +++ b/app/models/abilities/administrator.rb @@ -37,7 +37,7 @@ module Abilities can :manage, Annotation - can [:read, :update], SpendingProposal + can [:read, :update, :destroy], SpendingProposal end end end diff --git a/app/models/abilities/common.rb b/app/models/abilities/common.rb index 92eacea52..1eddb0484 100644 --- a/app/models/abilities/common.rb +++ b/app/models/abilities/common.rb @@ -44,7 +44,6 @@ module Abilities can :vote, Proposal can :vote_featured, Proposal can :create, SpendingProposal - can :destroy, SpendingProposal, author_id: user.id end can :create, Annotation From bd1c0dfa1993bce9e13de7ee2944bab191bbe795 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Tue, 29 Mar 2016 17:10:14 +0200 Subject: [PATCH 034/163] changes i18n text --- config/locales/en.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index b37c5568b..4ae33fe46 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -423,7 +423,7 @@ en: sidebar: geozones: Scope of operation feasibility: Feasibility - start_spending_proposal: Create a spending proposal + start_spending_proposal: Create an investment project new: back_link: Back more_info: How do participatory budgeting works? From 3e3c32d247e7f0c78fcbc2f044c97fd2f001c5ec Mon Sep 17 00:00:00 2001 From: kikito Date: Tue, 29 Mar 2016 17:26:18 +0200 Subject: [PATCH 035/163] fixes errors in translation and adds missing ones --- config/locales/en.yml | 28 ++-------------------------- config/locales/es.yml | 10 +++++++++- 2 files changed, 11 insertions(+), 27 deletions(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index 08e289109..c320ec9f2 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -418,46 +418,22 @@ en: verified_only: Only verified users can create spending proposals, %{verify_account}. verify_account: verify your account new: - back_link: Back more_info: How do participatory budgeting works? recommendation_one: It's mandatory that the proposal makes reference to a budgetable action. recommendation_three: Try to go into details when describing your spending proposal so the reviewing team undertands your points. recommendation_two: Any proposal or comment suggesting illegal action will be deleted. recommendations_title: How to create a spending proposal start_new: Create spending proposal + back_link: Back wrong_price_format: Only integer numbers spending_proposal: already_supported: You have already supported this. Share it! - comments: - one: 1 comment - other: "%{count} comments" - zero: No comments - proposal: Proposal - reason_for_supports_necessary: 2% of Census support: Support - support_title: Support this proposal + support_title: Support this project supports: one: 1 support other: "%{count} supports" zero: No supports - supports_necessary: "%{number} supports needed" - total_percent: 100% - show: - author_deleted: User deleted - back_link: Go back - code: 'Proposal code:' - comments: - one: 1 comment - other: "%{count} comments" - zero: No comments - comments_title: Comments - edit_proposal_link: Edit - flag: This proposal has been flagged as inappropriate by several users. - login_to_comment: You must %{signin} or %{signup} to leave a comment. - share: Share - update: - form: - submit_button: Save changes stats: index: visits: Visits diff --git a/config/locales/es.yml b/config/locales/es.yml index 0e7a8b125..5a6149f2a 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -418,14 +418,22 @@ es: verified_only: Sólo los usuarios verificados pueden crear propuestas de gasto, %{verify_account}. verify_account: verifica tu cuenta new: - back_link: Volver more_info: "¿Cómo funcionan los presupuestos participativos?" recommendation_one: Es fundamental que haga referencia a una actuación presupuestable. recommendation_three: Intenta detallar lo máximo posible la propuesta para que el equipo de gobierno encargado de estudiarla tenga las menor dudas posibles. recommendation_two: Cualquier propuesta o comentario que implique acciones ilegales será eliminada. recommendations_title: Cómo crear una propuesta de gasto start_new: Crear una propuesta de gasto + back_link: Volver wrong_price_format: Solo puede incluir caracteres numéricos + spending_proposal: + already_supported: Ya has apoyado este proyecto. Compartelo! + support: Apoyar + support_title: Apoyar este proyecto + supports: + one: 1 apoyo + other: "%{count} apoyo" + zero: Sin apoyos stats: index: visits: Visitas From d5453f173332621db2a9a3f680c62b718194cff4 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Tue, 29 Mar 2016 17:36:31 +0200 Subject: [PATCH 036/163] fixes spec --- app/controllers/spending_proposals_controller.rb | 2 +- spec/features/spending_proposals_spec.rb | 6 ++++-- spec/features/users_spec.rb | 8 ++++---- spec/models/abilities/administrator_spec.rb | 1 + spec/models/abilities/common_spec.rb | 4 ++-- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/app/controllers/spending_proposals_controller.rb b/app/controllers/spending_proposals_controller.rb index 76f230575..015454b86 100644 --- a/app/controllers/spending_proposals_controller.rb +++ b/app/controllers/spending_proposals_controller.rb @@ -29,7 +29,7 @@ class SpendingProposalsController < ApplicationController end def destroy - spending_proposal = current_user.spending_proposals.find(params[:id]) + spending_proposal = SpendingProposal.find(params[:id]) spending_proposal.destroy redirect_to user_path(current_user, filter: 'spending_proposals'), notice: t('flash.actions.destroy.spending_proposal') end diff --git a/spec/features/spending_proposals_spec.rb b/spec/features/spending_proposals_spec.rb index 8462cc77f..5212dace2 100644 --- a/spec/features/spending_proposals_spec.rb +++ b/spec/features/spending_proposals_spec.rb @@ -132,10 +132,12 @@ feature 'Spending proposals' do context "Destroy" do - scenario "User can destroy owned spending proposals" do + scenario "Admin can destroy owned spending proposals" do + admin = create(:administrator) user = create(:user, :level_two) spending_proposal = create(:spending_proposal, author: user) - login_as(user) + + login_as(admin.user) visit user_path(user) within("#spending_proposal_#{spending_proposal.id}") do diff --git a/spec/features/users_spec.rb b/spec/features/users_spec.rb index eff63b18b..93369a2c9 100644 --- a/spec/features/users_spec.rb +++ b/spec/features/users_spec.rb @@ -240,19 +240,19 @@ feature 'Users' do expect(page).to have_content('Build a school') end - scenario 'delete button is shown if logged in user is author' do + scenario 'delete button is not shown if logged in user is author' do login_as(@author) visit user_path(@author) within("#spending_proposal_#{@spending_proposal.id}") do - expect(page).to have_content('Delete') + expect(page).to_not have_content('Delete') end end - scenario 'delete button is not shown if logged in user is admin' do + scenario 'delete button is shown if logged in user is admin' do login_as(create(:administrator).user) visit user_path(@author) within("#spending_proposal_#{@spending_proposal.id}") do - expect(page).to_not have_content('Delete') + expect(page).to have_content('Delete') end end diff --git a/spec/models/abilities/administrator_spec.rb b/spec/models/abilities/administrator_spec.rb index b5ee78dd0..f9ed7a0c5 100644 --- a/spec/models/abilities/administrator_spec.rb +++ b/spec/models/abilities/administrator_spec.rb @@ -55,4 +55,5 @@ describe "Abilities::Administrator" do it { should be_able_to(:read, SpendingProposal) } it { should be_able_to(:update, SpendingProposal) } it { should be_able_to(:valuate, SpendingProposal) } + it { should be_able_to(:destroy, SpendingProposal) } end diff --git a/spec/models/abilities/common_spec.rb b/spec/models/abilities/common_spec.rb index 8c90f7cea..468173797 100644 --- a/spec/models/abilities/common_spec.rb +++ b/spec/models/abilities/common_spec.rb @@ -92,7 +92,7 @@ describe "Abilities::Common" do it { should be_able_to(:create, SpendingProposal) } it { should_not be_able_to(:destroy, create(:spending_proposal)) } - it { should be_able_to(:destroy, own_spending_proposal) } + it { should_not be_able_to(:destroy, own_spending_proposal) } end describe "when level 3 verified" do @@ -104,6 +104,6 @@ describe "Abilities::Common" do it { should be_able_to(:create, SpendingProposal) } it { should_not be_able_to(:destroy, create(:spending_proposal)) } - it { should be_able_to(:destroy, own_spending_proposal) } + it { should_not be_able_to(:destroy, own_spending_proposal) } end end From 98e895dec061be8b8df0d3d7acbfc50900f85b02 Mon Sep 17 00:00:00 2001 From: kikito Date: Tue, 29 Mar 2016 18:13:28 +0200 Subject: [PATCH 037/163] adds missing i18n --- config/locales/en.yml | 3 +-- config/locales/es.yml | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index ec1158d52..9b438215a 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -434,10 +434,9 @@ en: back_link: Back show: author_deleted: User deleted - spending_proposal: - spending_proposal: Investment project wrong_price_format: Only integer numbers spending_proposal: + spending_proposal: Investment project already_supported: You have already supported this. Share it! support: Support support_title: Support this project diff --git a/config/locales/es.yml b/config/locales/es.yml index 101e7f026..2480bd7ba 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -434,10 +434,9 @@ es: back_link: Volver show: author_deleted: Usuario eliminado - spending_proposal: - spending_proposal: Propuesta de inversión wrong_price_format: Solo puede incluir caracteres numéricos spending_proposal: + spending_proposal: Propuesta de inversión already_supported: Ya has apoyado este proyecto. Compartelo! support: Apoyar support_title: Apoyar este proyecto From 34f9ce2eceb0a0ae097ab741643e79d07dacde46 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Tue, 29 Mar 2016 18:47:49 +0200 Subject: [PATCH 038/163] fixes specs --- .../management/spending_proposals_controller.rb | 6 ++++++ app/views/_votes.html.erb/index.html.erb | 16 ---------------- app/views/spending_proposals/show.html.erb | 2 +- 3 files changed, 7 insertions(+), 17 deletions(-) delete mode 100644 app/views/_votes.html.erb/index.html.erb diff --git a/app/controllers/management/spending_proposals_controller.rb b/app/controllers/management/spending_proposals_controller.rb index 3a17d86b1..e6170722a 100644 --- a/app/controllers/management/spending_proposals_controller.rb +++ b/app/controllers/management/spending_proposals_controller.rb @@ -19,6 +19,7 @@ class Management::SpendingProposalsController < Management::BaseController def show @spending_proposal = SpendingProposal.find(params[:id]) + set_spending_proposal_votes(@spending_proposal) end private @@ -37,4 +38,9 @@ class Management::SpendingProposalsController < Management::BaseController managed_user end + # This should not be necessary. Maybe we could create a specific show view for managers. + def set_spending_proposal_votes(spending_proposals) + @spending_proposal_votes = current_user ? current_user.spending_proposal_votes(spending_proposals) : {} + end + end diff --git a/app/views/_votes.html.erb/index.html.erb b/app/views/_votes.html.erb/index.html.erb deleted file mode 100644 index 00a1b6442..000000000 --- a/app/views/_votes.html.erb/index.html.erb +++ /dev/null @@ -1,16 +0,0 @@ -<% provide :title do %><%= t('spending_proposals.index.title') %><% end %> -
-
-
-

<%= t('spending_proposals.index.title') %>

- -

<%= t('spending_proposals.index.text_html') %>

- - <% if can? :create, SpendingProposal %> - <%= link_to t('spending_proposals.index.create_link'), new_spending_proposal_path, class: 'button' %> - <% else %> -

<%= t('spending_proposals.index.verified_only', verify_account: link_to(t('spending_proposals.index.verify_account'), verification_path)).html_safe %>

- <% end %> -
-
-
\ No newline at end of file diff --git a/app/views/spending_proposals/show.html.erb b/app/views/spending_proposals/show.html.erb index 1aaa3d805..38616f28a 100644 --- a/app/views/spending_proposals/show.html.erb +++ b/app/views/spending_proposals/show.html.erb @@ -26,7 +26,7 @@
- <%= render 'votes', + <%= render 'spending_proposals/votes', { spending_proposal: @spending_proposal, vote_url: vote_spending_proposal_path(@spending_proposal, value: 'yes') } %>
From d3ccc71c220031ff680c48c94f097abbbfab33d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Tue, 29 Mar 2016 18:25:26 +0200 Subject: [PATCH 039/163] fixes search terms --- app/controllers/spending_proposals_controller.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/controllers/spending_proposals_controller.rb b/app/controllers/spending_proposals_controller.rb index 306348651..b2eb07451 100644 --- a/app/controllers/spending_proposals_controller.rb +++ b/app/controllers/spending_proposals_controller.rb @@ -12,12 +12,13 @@ class SpendingProposalsController < ApplicationController respond_to :html, :js def index - @spending_proposals = @search_terms.present? ? SpendingProposal.search(@search_terms) : SpendingProposal.all + @spending_proposals = search_terms.present? ? SpendingProposal.search(search_terms) : SpendingProposal.all @spending_proposals = @spending_proposals.page(params[:page]).for_render end def new @spending_proposal = SpendingProposal.new + end def show @@ -54,4 +55,8 @@ class SpendingProposalsController < ApplicationController params.require(:spending_proposal).permit(:title, :description, :external_url, :geozone_id, :association_name, :terms_of_service, :captcha, :captcha_key) end + def search_terms + params[:search].presence + end + end From cb681883f887569d202c1e38da93833bb7b8d4d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Tue, 29 Mar 2016 18:25:44 +0200 Subject: [PATCH 040/163] adds pg_search to spending proposals --- app/models/spending_proposal.rb | 13 +++++++++++++ ...0329160106_add_tsvector_to_spending_proposals.rb | 8 ++++++++ db/schema.rb | 4 +++- 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20160329160106_add_tsvector_to_spending_proposals.rb diff --git a/app/models/spending_proposal.rb b/app/models/spending_proposal.rb index 534ce9533..3e461518c 100644 --- a/app/models/spending_proposal.rb +++ b/app/models/spending_proposal.rb @@ -2,6 +2,7 @@ class SpendingProposal < ActiveRecord::Base include Measurable include Sanitizable include Taggable + include Searchable apply_simple_captcha acts_as_votable @@ -53,6 +54,18 @@ class SpendingProposal < ActiveRecord::Base results.includes(:geozone, administrator: :user, valuators: :user) end + def searchable_values + { title => 'A', + author.username => 'B', + geozone.try(:name) => 'B', + description => 'C' + } + end + + def self.search(terms) + self.pg_search(terms) + end + def self.by_geozone(geozone) if geozone == 'all' where(geozone_id: nil) diff --git a/db/migrate/20160329160106_add_tsvector_to_spending_proposals.rb b/db/migrate/20160329160106_add_tsvector_to_spending_proposals.rb new file mode 100644 index 000000000..080a8ebc9 --- /dev/null +++ b/db/migrate/20160329160106_add_tsvector_to_spending_proposals.rb @@ -0,0 +1,8 @@ +class AddTsvectorToSpendingProposals < ActiveRecord::Migration + + def change + add_column :spending_proposals, :tsv, :tsvector + add_index :spending_proposals, :tsv, using: "gin" + end + +end diff --git a/db/schema.rb b/db/schema.rb index b5daf6abd..55021dfa0 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: 20160329115418) do +ActiveRecord::Schema.define(version: 20160329160106) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -313,10 +313,12 @@ ActiveRecord::Schema.define(version: 20160329115418) do t.string "time_scope" t.datetime "unfeasible_email_sent_at" t.integer "cached_votes_up" + t.tsvector "tsv" end add_index "spending_proposals", ["author_id"], name: "index_spending_proposals_on_author_id", using: :btree add_index "spending_proposals", ["geozone_id"], name: "index_spending_proposals_on_geozone_id", using: :btree + add_index "spending_proposals", ["tsv"], name: "index_spending_proposals_on_tsv", using: :gin create_table "taggings", force: :cascade do |t| t.integer "tag_id" From 18d304ea033b74efa878a372963cfaf85e7d422b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Tue, 29 Mar 2016 18:26:12 +0200 Subject: [PATCH 041/163] adds spending proposals search spec --- spec/features/spending_proposals_spec.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/spec/features/spending_proposals_spec.rb b/spec/features/spending_proposals_spec.rb index f600a2bc9..b31eacec8 100644 --- a/spec/features/spending_proposals_spec.rb +++ b/spec/features/spending_proposals_spec.rb @@ -18,6 +18,29 @@ feature 'Spending proposals' do end end + context("Search") do + scenario 'Search by text' do + spending_proposal1 = create(:spending_proposal, title: "Get Schwifty") + spending_proposal2 = create(:spending_proposal, title: "Schwifty Hello") + spending_proposal3 = create(:spending_proposal, title: "Do not show me") + + visit spending_proposals_path + + within(".expanded #search_form") do + fill_in "search", with: "Schwifty" + click_button "Search" + end + + within("#investment-projects") do + expect(page).to have_css('.investment-project', count: 2) + + expect(page).to have_content(spending_proposal1.title) + expect(page).to have_content(spending_proposal2.title) + expect(page).to_not have_content(spending_proposal3.title) + end + end + end + scenario 'Create' do login_as(author) From 6649b0fbdd400b97a4448a2a5a1c3c9486864ea5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Wed, 30 Mar 2016 11:47:40 +0200 Subject: [PATCH 042/163] adds default value for cached_votes_up --- db/migrate/20160329115418_add_votes_up_to_spending_proposals.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20160329115418_add_votes_up_to_spending_proposals.rb b/db/migrate/20160329115418_add_votes_up_to_spending_proposals.rb index aa9397c2e..3b0f2a7ad 100644 --- a/db/migrate/20160329115418_add_votes_up_to_spending_proposals.rb +++ b/db/migrate/20160329115418_add_votes_up_to_spending_proposals.rb @@ -1,5 +1,5 @@ class AddVotesUpToSpendingProposals < ActiveRecord::Migration def change - add_column :spending_proposals, :cached_votes_up, :integer + add_column :spending_proposals, :cached_votes_up, :integer, default: 0 end end From 24bbbcec974175b250e2dbf15f4a1269e576514d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Wed, 30 Mar 2016 11:47:49 +0200 Subject: [PATCH 043/163] fixes i18n --- config/locales/es.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/locales/es.yml b/config/locales/es.yml index 2480bd7ba..cf7141933 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -442,7 +442,7 @@ es: support_title: Apoyar este proyecto supports: one: 1 apoyo - other: "%{count} apoyo" + other: "%{count} apoyos" zero: Sin apoyos stats: index: From 195e759f472c561c1596e1a8f443eccf4b6ae4f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Wed, 30 Mar 2016 12:10:24 +0200 Subject: [PATCH 044/163] favors before_action vs before_filter --- app/controllers/spending_proposals_controller.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/controllers/spending_proposals_controller.rb b/app/controllers/spending_proposals_controller.rb index b2eb07451..a70c3a89a 100644 --- a/app/controllers/spending_proposals_controller.rb +++ b/app/controllers/spending_proposals_controller.rb @@ -2,11 +2,10 @@ class SpendingProposalsController < ApplicationController include FeatureFlags before_action :authenticate_user!, except: [:index] + before_action -> { flash.now[:notice] = flash[:notice].html_safe if flash[:html_safe] && flash[:notice] } load_and_authorize_resource - before_filter -> { flash.now[:notice] = flash[:notice].html_safe if flash[:html_safe] && flash[:notice] } - feature_flag :spending_proposals respond_to :html, :js @@ -48,7 +47,6 @@ class SpendingProposalsController < ApplicationController set_spending_proposal_votes(@spending_proposal) end - private def spending_proposal_params From 207479ec599f2c97e1a9885513771603d2df5568 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Wed, 30 Mar 2016 12:10:43 +0200 Subject: [PATCH 045/163] shows search terms in search results view --- app/controllers/spending_proposals_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/spending_proposals_controller.rb b/app/controllers/spending_proposals_controller.rb index a70c3a89a..24bbbc41a 100644 --- a/app/controllers/spending_proposals_controller.rb +++ b/app/controllers/spending_proposals_controller.rb @@ -54,7 +54,7 @@ class SpendingProposalsController < ApplicationController end def search_terms - params[:search].presence + @search_terms ||= params[:search].presence end end From 948436f130571938ecd0e6ffacd9c4b540025c3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Wed, 30 Mar 2016 12:11:15 +0200 Subject: [PATCH 046/163] adds rake task to touch all spending proposals (it triggers the recalculating of the tsvector for pg_search) --- lib/tasks/spending_proposals.rake | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/tasks/spending_proposals.rake b/lib/tasks/spending_proposals.rake index b49f2acf5..42cde5424 100644 --- a/lib/tasks/spending_proposals.rake +++ b/lib/tasks/spending_proposals.rake @@ -10,4 +10,11 @@ namespace :spending_proposals do end end end + + desc "Updates all spending proposals to recalculate their tsv column" + task touch: :environment do + SpendingProposal.find_in_batches do |spending_propsal| + spending_propsal.each(&:save) + end + end end \ No newline at end of file From d526c2effaec769ba33abf509642a6c43e4847dc Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Wed, 30 Mar 2016 12:58:15 +0200 Subject: [PATCH 047/163] Improves styles for spending proposals show --- app/assets/stylesheets/participation.scss | 12 ++--- app/views/_votes.html.erb/_form.html.erb | 51 ---------------------- app/views/_votes.html.erb/new.html.erb | 27 ------------ app/views/_votes.html.erb/show.html.erb | 34 --------------- app/views/spending_proposals/show.html.erb | 4 +- 5 files changed, 6 insertions(+), 122 deletions(-) delete mode 100644 app/views/_votes.html.erb/_form.html.erb delete mode 100644 app/views/_votes.html.erb/new.html.erb delete mode 100644 app/views/_votes.html.erb/show.html.erb diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index eb2945deb..7e14626a3 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -335,7 +335,7 @@ // 03. Show participation // - - - - - - - - - - - - - - - - - - - - - - - - - -.debate-show, .proposal-show { +.debate-show, .proposal-show, .investment-project-show { .social-share-full .social-share-button { display:inline; @@ -350,12 +350,11 @@ vertical-align: rem-calc(10); } - .edit-debate, .edit-proposal { margin-bottom: 0; } - .debate-info, .proposal-info { + .debate-info, .proposal-info, .investment-project-info { clear: both; color: $text-medium; font-size: $small-font-size; @@ -613,24 +612,21 @@ .icon-debates, .icon-proposals, .icon-budget { font-size: rem-calc(18); line-height: $line-height; - position: absolute; + margin-left: rem-calc(6); top: 0; } .icon-debates { color: $debates; - left: rem-calc(48); } .icon-proposals { color: $proposals; - left: rem-calc(72); } .icon-budget { color: $budget; font-size: $small-font-size; - left: rem-calc(122); } .debate-info, .proposal-info, .investment-project-info { @@ -809,7 +805,7 @@ } } -.investment-project { +.investment-project, .investment-project-show { .supports { @include supports; diff --git a/app/views/_votes.html.erb/_form.html.erb b/app/views/_votes.html.erb/_form.html.erb deleted file mode 100644 index 0d6ef0402..000000000 --- a/app/views/_votes.html.erb/_form.html.erb +++ /dev/null @@ -1,51 +0,0 @@ -<%= form_for(@spending_proposal, url: form_url) do |f| %> - <%= render 'shared/errors', resource: @spending_proposal %> - -
-
- <%= f.label :title, t("spending_proposals.form.title") %> - <%= f.text_field :title, maxlength: SpendingProposal.title_max_length, placeholder: t("spending_proposals.form.title"), label: false %> -
- -
- <%= f.label :description, t("spending_proposals.form.description") %> - <%= f.cktext_area :description, maxlength: SpendingProposal.description_max_length, ckeditor: { language: I18n.locale }, label: false %> -
- -
- <%= f.label :external_url, t("spending_proposals.form.external_url") %> - <%= f.text_field :external_url, placeholder: t("spending_proposals.form.external_url"), label: false %> -
- -
- <%= f.label :geozone_id, t("spending_proposals.form.geozone") %> - <%= f.select :geozone_id, geozone_select_options, {include_blank: t("geozones.none"), label: false} %> -
- -
- <%= f.label :association_name, t("spending_proposals.form.association_name_label") %> - <%= f.text_field :association_name, placeholder: t("spending_proposals.form.association_name"), label: false %> -
- -
- <% if @spending_proposal.new_record? %> - <%= f.label :terms_of_service do %> - <%= f.check_box :terms_of_service, title: t('form.accept_terms_title'), label: false %> - - <%= t("form.accept_terms", - policy: link_to(t("form.policy"), "/privacy", target: "blank"), - conditions: link_to(t("form.conditions"), "/conditions", target: "blank")).html_safe %> - - <% end %> - <% end %> -
- -
- <%= f.simple_captcha input_html: { required: false } %> -
- -
- <%= f.submit(class: "button", value: t("spending_proposals.form.submit_buttons.#{action_name}")) %> -
-
-<% end %> \ No newline at end of file diff --git a/app/views/_votes.html.erb/new.html.erb b/app/views/_votes.html.erb/new.html.erb deleted file mode 100644 index a8d35338f..000000000 --- a/app/views/_votes.html.erb/new.html.erb +++ /dev/null @@ -1,27 +0,0 @@ -
- -
- <%= link_to spending_proposals_path, class: "back" do %> - - <%= t("spending_proposals.new.back_link") %> - <% end %> -

<%= t("spending_proposals.new.start_new") %>

-
- <%= link_to "/spending_proposals_info", title: t('shared.target_blank_html'), target: "_blank" do %> - <%= t("spending_proposals.new.more_info")%> - <% end %> -
- <%= render "spending_proposals/form", form_url: spending_proposals_url %> -
- -
- -

<%= t("spending_proposals.new.recommendations_title") %>

-
    -
  • <%= t("spending_proposals.new.recommendation_one") %>
  • -
  • <%= t("spending_proposals.new.recommendation_two") %>
  • -
  • <%= t("spending_proposals.new.recommendation_three") %>
  • -
-
- -
\ No newline at end of file diff --git a/app/views/_votes.html.erb/show.html.erb b/app/views/_votes.html.erb/show.html.erb deleted file mode 100644 index 1aaa3d805..000000000 --- a/app/views/_votes.html.erb/show.html.erb +++ /dev/null @@ -1,34 +0,0 @@ -<% provide :title do %><%= @spending_proposal.title %><% end %> - -
-
-
- -

<%= @spending_proposal.title %>

- -
- <%= render '/shared/author_info', resource: @spending_proposal %> - -  •  - <%= l @spending_proposal.created_at.to_date %> -  •  - <%= geozone_name(@spending_proposal) %> -
- - <%= safe_html_with_links @spending_proposal.description.html_safe %> - - <% if @spending_proposal.external_url.present? %> - - <% end %> - -
- -
- <%= render 'votes', - { spending_proposal: @spending_proposal, vote_url: vote_spending_proposal_path(@spending_proposal, value: 'yes') } %> -
- -
-
\ No newline at end of file diff --git a/app/views/spending_proposals/show.html.erb b/app/views/spending_proposals/show.html.erb index 38616f28a..c68a1eacc 100644 --- a/app/views/spending_proposals/show.html.erb +++ b/app/views/spending_proposals/show.html.erb @@ -1,12 +1,12 @@ <% provide :title do %><%= @spending_proposal.title %><% end %> -
+

<%= @spending_proposal.title %>

-
+
<%= render '/shared/author_info', resource: @spending_proposal %>  •  From 4fad2839477d34eb69934109852902cefd892113 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Wed, 30 Mar 2016 14:00:26 +0200 Subject: [PATCH 048/163] adds geozone and unfeasible filters to index --- .../spending_proposals_controller.rb | 22 ++++++-- .../spending_proposals/_sidebar.html.erb | 10 ++-- app/views/spending_proposals/index.html.erb | 8 +-- config/locales/activerecord.es.yml | 4 +- config/locales/en.yml | 4 ++ config/locales/es.yml | 4 ++ spec/features/spending_proposals_spec.rb | 50 ++++++++++++++++++- 7 files changed, 88 insertions(+), 14 deletions(-) diff --git a/app/controllers/spending_proposals_controller.rb b/app/controllers/spending_proposals_controller.rb index 24bbbc41a..bc69d6200 100644 --- a/app/controllers/spending_proposals_controller.rb +++ b/app/controllers/spending_proposals_controller.rb @@ -11,13 +11,11 @@ class SpendingProposalsController < ApplicationController respond_to :html, :js def index - @spending_proposals = search_terms.present? ? SpendingProposal.search(search_terms) : SpendingProposal.all - @spending_proposals = @spending_proposals.page(params[:page]).for_render + @spending_proposals = apply_filters_and_search(SpendingProposal).page(params[:page]).for_render end def new @spending_proposal = SpendingProposal.new - end def show @@ -53,8 +51,22 @@ class SpendingProposalsController < ApplicationController params.require(:spending_proposal).permit(:title, :description, :external_url, :geozone_id, :association_name, :terms_of_service, :captcha, :captcha_key) end - def search_terms - @search_terms ||= params[:search].presence + def set_geozone_name + if params[:geozone] == 'all' + @geozone_name = t('geozones.none') + else + @geozone_name = Geozone.find(params[:geozone]).name + end + end + + def apply_filters_and_search(target) + target = params[:unfeasible].present? ? target.unfeasible : target.not_unfeasible + if params[:geozone].present? + target = target.by_geozone(params[:geozone]) + set_geozone_name + end + target = target.search(params[:search]) if params[:search].present? + target end end diff --git a/app/views/spending_proposals/_sidebar.html.erb b/app/views/spending_proposals/_sidebar.html.erb index 7ab1ab525..8fc8693e8 100644 --- a/app/views/spending_proposals/_sidebar.html.erb +++ b/app/views/spending_proposals/_sidebar.html.erb @@ -2,10 +2,14 @@
- <% Geozone.names.each do |geozone| %> - <%= link_to geozone, spending_proposals_path(search: geozone) %> + <%= link_to t('geozones.all'), spending_proposals_path(geozone: nil) %> + <%= link_to t('geozones.none'), spending_proposals_path(geozone: 'all') %> + <% Geozone.all.each do |geozone| %> + <%= link_to geozone.name, spending_proposals_path(geozone: geozone.id) %> <% end %>
+ -
\ No newline at end of file +
+<%= link_to t('spending_proposals.index.sidebar.unfeasible'), spending_proposals_path(unfeasible: '1') %> \ No newline at end of file diff --git a/app/views/spending_proposals/index.html.erb b/app/views/spending_proposals/index.html.erb index 499948691..563b84e23 100644 --- a/app/views/spending_proposals/index.html.erb +++ b/app/views/spending_proposals/index.html.erb @@ -10,10 +10,12 @@
- <% if @search_terms %> + <%= content_tag(:h2, t("spending_proposals.index.unfeasible")) if params[:unfeasible].present? %> + <%= content_tag(:h2, t("spending_proposals.index.by_geozone", geozone: @geozone_name)) if @geozone_name.present? %> + <% if params[:search].present? %>

<%= page_entries_info @spending_proposals %> - <%= t("spending_proposals.index.search_results", count: @spending_proposals.size, search_term: @search_terms) %> + <%= t("spending_proposals.index.search_results", count: @spending_proposals.size, search_term: params[:search]) %>

<% end %>
@@ -26,7 +28,7 @@
-
diff --git a/config/locales/activerecord.es.yml b/config/locales/activerecord.es.yml index 50dd53006..79893cecd 100644 --- a/config/locales/activerecord.es.yml +++ b/config/locales/activerecord.es.yml @@ -38,8 +38,8 @@ es: one: "Propuesta ciudadana" other: "Propuestas ciudadanas" spending_proposal: - one: "Propuesta de gasto" - other: "Propuestas de gasto" + one: "Propuesta de inversión" + other: "Propuestas de inversión" attributes: comment: body: "Comentario" diff --git a/config/locales/en.yml b/config/locales/en.yml index 9b438215a..206f2fb76 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -154,6 +154,7 @@ en: verification/sms: phone geozones: none: All city + all: All scopes layouts: application: chrome: Google Chrome @@ -413,6 +414,8 @@ en: title: Spending proposal title index: title: Participatory budgeting + unfeasible: Unfeasible investment projects + by_geozone: "Investment projects with scope: %{geozone}" search_form: button: Search placeholder: Investment projects... @@ -423,6 +426,7 @@ en: sidebar: geozones: Scope of operation feasibility: Feasibility + unfeasible: Unfeasible start_spending_proposal: Create an investment project new: more_info: How do participatory budgeting works? diff --git a/config/locales/es.yml b/config/locales/es.yml index cf7141933..9e02d6962 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -154,6 +154,7 @@ es: verification/sms: el teléfono geozones: none: Toda la ciudad + all: Todos los ámbitos layouts: application: chrome: Google Chrome @@ -413,6 +414,8 @@ es: title: Título de la propuesta de gasto index: title: Presupuestos participativos + unfeasible: Propuestas de inversión no viables + by_geozone: "Propuestas de inversión con ámbito: %{geozone}" search_form: button: Buscar placeholder: Propuestas de inversión... @@ -423,6 +426,7 @@ es: sidebar: geozones: Ámbitos de actuación feasibility: Viabilidad + unfeasible: No viables start_spending_proposal: Crea una propuesta de inversión new: more_info: "¿Cómo funcionan los presupuestos participativos?" diff --git a/spec/features/spending_proposals_spec.rb b/spec/features/spending_proposals_spec.rb index b31eacec8..62dfee01e 100644 --- a/spec/features/spending_proposals_spec.rb +++ b/spec/features/spending_proposals_spec.rb @@ -5,7 +5,8 @@ feature 'Spending proposals' do let(:author) { create(:user, :level_two, username: 'Isabel') } scenario 'Index' do - spending_proposals = [create(:spending_proposal), create(:spending_proposal), create(:spending_proposal)] + spending_proposals = [create(:spending_proposal), create(:spending_proposal), create(:spending_proposal, feasible: true)] + unfeasible_spending_proposal = create(:spending_proposal, feasible: false) visit spending_proposals_path @@ -14,6 +15,7 @@ feature 'Spending proposals' do within('#investment-projects') do expect(page).to have_content spending_proposal.title expect(page).to have_css("a[href='#{spending_proposal_path(spending_proposal)}']", text: spending_proposal.title) + expect(page).to_not have_content(unfeasible_spending_proposal.title) end end end @@ -41,6 +43,52 @@ feature 'Spending proposals' do end end + context("Filters") do + scenario 'by geozone' do + geozone1 = create(:geozone) + spending_proposal1 = create(:spending_proposal, geozone: geozone1) + spending_proposal2 = create(:spending_proposal, geozone: create(:geozone)) + spending_proposal3 = create(:spending_proposal, geozone: geozone1) + spending_proposal4 = create(:spending_proposal) + + visit spending_proposals_path + + within(".geozone") do + click_link geozone1.name + end + + within("#investment-projects") do + expect(page).to have_css('.investment-project', count: 2) + + expect(page).to have_content(spending_proposal1.title) + expect(page).to have_content(spending_proposal3.title) + expect(page).to_not have_content(spending_proposal2.title) + expect(page).to_not have_content(spending_proposal4.title) + end + end + + scenario 'by unfeasibility' do + geozone1 = create(:geozone) + spending_proposal1 = create(:spending_proposal, feasible: false) + spending_proposal2 = create(:spending_proposal, feasible: true) + spending_proposal3 = create(:spending_proposal) + + visit spending_proposals_path + + within("#sidebar") do + click_link "Unfeasible" + end + + within("#investment-projects") do + expect(page).to have_css('.investment-project', count: 1) + + expect(page).to have_content(spending_proposal1.title) + expect(page).to_not have_content(spending_proposal2.title) + expect(page).to_not have_content(spending_proposal3.title) + end + end + end + scenario 'Create' do login_as(author) From c536a12e3d29c89a29c8ebed90a3e6b7324362d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Wed, 30 Mar 2016 18:47:40 +0200 Subject: [PATCH 049/163] adds voting to spending proposals index --- .../spending_proposals_controller.rb | 1 + .../_spending_proposal.html.erb | 5 ++- spec/features/votes_spec.rb | 42 ++++++++++++------- 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/app/controllers/spending_proposals_controller.rb b/app/controllers/spending_proposals_controller.rb index bc69d6200..9915b0b50 100644 --- a/app/controllers/spending_proposals_controller.rb +++ b/app/controllers/spending_proposals_controller.rb @@ -12,6 +12,7 @@ class SpendingProposalsController < ApplicationController def index @spending_proposals = apply_filters_and_search(SpendingProposal).page(params[:page]).for_render + set_spending_proposal_votes(@spending_proposals) end def new diff --git a/app/views/spending_proposals/_spending_proposal.html.erb b/app/views/spending_proposals/_spending_proposal.html.erb index 4437fba0b..091bc4878 100644 --- a/app/views/spending_proposals/_spending_proposal.html.erb +++ b/app/views/spending_proposals/_spending_proposal.html.erb @@ -46,7 +46,10 @@
- +
+ <%= render 'spending_proposals/votes', + { spending_proposal: spending_proposal, vote_url: vote_spending_proposal_path(spending_proposal, value: 'yes') } %> +
diff --git a/spec/features/votes_spec.rb b/spec/features/votes_spec.rb index caadf2637..632162c3c 100644 --- a/spec/features/votes_spec.rb +++ b/spec/features/votes_spec.rb @@ -365,25 +365,39 @@ feature 'Votes' do feature 'Spending Proposals' do background { login_as(@manuela) } - xscenario "Index shows user votes on proposals" do - proposal1 = create(:proposal) - proposal2 = create(:proposal) - proposal3 = create(:proposal) - create(:vote, voter: @manuela, votable: proposal1, vote_flag: true) + feature 'Index' do + scenario "Index shows user votes on proposals" do + spending_proposal1 = create(:spending_proposal) + spending_proposal2 = create(:spending_proposal) + spending_proposal3 = create(:spending_proposal) + create(:vote, voter: @manuela, votable: spending_proposal1, vote_flag: true) - visit proposals_path + visit spending_proposals_path - within("#proposals") do - within("#proposal_#{proposal1.id}_votes") do - expect(page).to have_content "You have already supported this proposal. Share it!" + within("#investment-projects") do + within("#spending_proposal_#{spending_proposal1.id}_votes") do + expect(page).to have_content "You have already supported this. Share it!" + end + + within("#spending_proposal_#{spending_proposal2.id}_votes") do + expect(page).to_not have_content "You have already supported this. Share it!" + end + + within("#spending_proposal_#{spending_proposal3.id}_votes") do + expect(page).to_not have_content "You have already supported this. Share it!" + end end + end - within("#proposal_#{proposal2.id}_votes") do - expect(page).to_not have_content "You have already supported this proposal. Share it!" - end + scenario 'Create from spending proposal index', :js do + spending_proposal = create(:spending_proposal) + visit spending_proposals_path - within("#proposal_#{proposal3.id}_votes") do - expect(page).to_not have_content "You have already supported this proposal. Share it!" + within('.supports') do + find('.in-favor a').click + + expect(page).to have_content "1 support" + expect(page).to have_content "You have already supported this. Share it!" end end end From dc8cd13230e1d92d5dfb413c9c63b3228192f99b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Wed, 30 Mar 2016 18:53:22 +0200 Subject: [PATCH 050/163] adds geozone info to spending proposals in index --- app/views/spending_proposals/_spending_proposal.html.erb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/views/spending_proposals/_spending_proposal.html.erb b/app/views/spending_proposals/_spending_proposal.html.erb index 091bc4878..7dff660fc 100644 --- a/app/views/spending_proposals/_spending_proposal.html.erb +++ b/app/views/spending_proposals/_spending_proposal.html.erb @@ -37,6 +37,9 @@ <%= t("shared.collective") %> <% end %> + +  •  + <%= geozone_name(spending_proposal) %>

<%= link_to spending_proposal.description, spending_proposal_path(spending_proposal) %>

From cb4ea3f5409a9d204eec5a86be2482dd7f2c1616 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Thu, 31 Mar 2016 10:53:21 +0200 Subject: [PATCH 051/163] Improves styles for investment project share --- app/assets/stylesheets/participation.scss | 6 +++++- app/assets/stylesheets/variables.scss | 1 + app/views/management/proposals/index.html.erb | 2 +- app/views/proposals/summary.html.erb | 2 +- app/views/spending_proposals/_votes.html.erb | 2 +- config/locales/es.yml | 2 +- 6 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index 7e14626a3..f769df41d 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -825,7 +825,7 @@ color: white; &:hover { - background: $proposals-border; + background: $budget-hover; color: white; cursor: pointer; } @@ -841,6 +841,10 @@ font-weight: bold; } + .supported { + color: $budget; + } + .not-logged, .organizations-votes, .anonymous-votes { diff --git a/app/assets/stylesheets/variables.scss b/app/assets/stylesheets/variables.scss index 6882442d1..5d59ebf8f 100644 --- a/app/assets/stylesheets/variables.scss +++ b/app/assets/stylesheets/variables.scss @@ -74,6 +74,7 @@ $proposals: #FFA42D; $proposals-border: #CC8425; $budget: #454372; +$budget-hover: #7571BF; $highlight: #E7F2FC; $featured: #FED900; diff --git a/app/views/management/proposals/index.html.erb b/app/views/management/proposals/index.html.erb index 18136e2ed..e7966f0c5 100644 --- a/app/views/management/proposals/index.html.erb +++ b/app/views/management/proposals/index.html.erb @@ -7,7 +7,7 @@
<% if @search_terms %> -

+

<%= page_entries_info @proposals %> <%= t("proposals.index.search_results", count: @proposals.size, search_term: @search_terms) %>

diff --git a/app/views/proposals/summary.html.erb b/app/views/proposals/summary.html.erb index 0ef9450a3..acf1d0255 100644 --- a/app/views/proposals/summary.html.erb +++ b/app/views/proposals/summary.html.erb @@ -1,6 +1,6 @@
-
+
<%= link_to :back, class: 'back left' do %> diff --git a/app/views/spending_proposals/_votes.html.erb b/app/views/spending_proposals/_votes.html.erb index 652df8954..175effe04 100644 --- a/app/views/spending_proposals/_votes.html.erb +++ b/app/views/spending_proposals/_votes.html.erb @@ -1,7 +1,7 @@
- <%= t("spending_proposals.spending_proposal.supports", count: spending_proposal.total_votes) %>  + <%= t("spending_proposals.spending_proposal.supports", count: spending_proposal.total_votes) %>
diff --git a/config/locales/es.yml b/config/locales/es.yml index 9e02d6962..2b4e31a8e 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -441,7 +441,7 @@ es: wrong_price_format: Solo puede incluir caracteres numéricos spending_proposal: spending_proposal: Propuesta de inversión - already_supported: Ya has apoyado este proyecto. Compartelo! + already_supported: Ya has apoyado este proyecto. ¡Compártelo! support: Apoyar support_title: Apoyar este proyecto supports: From 0c524a0733c4794c48a397615098c07820a10a21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Sat, 2 Apr 2016 21:48:22 +0200 Subject: [PATCH 052/163] updates dependencies --- Gemfile | 3 +-- Gemfile.lock | 22 ++++++++++------------ 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/Gemfile b/Gemfile index 2e3ed4b15..e925fb642 100644 --- a/Gemfile +++ b/Gemfile @@ -39,7 +39,7 @@ gem 'ckeditor', '~> 4.1.5' gem 'cancancan' gem 'social-share-button', git: 'https://github.com/huacnlee/social-share-button.git', ref: 'e46a6a3e82b86023bc' gem 'initialjs-rails', '0.2.0.1' -gem 'unicorn', '~> 5.0.1' +gem 'unicorn', '~> 5.1.0' gem 'paranoia' gem 'rinku', require: 'rails_rinku' gem 'savon' @@ -59,7 +59,6 @@ gem 'tolk' # Web interface for translations gem 'browser' gem 'turnout' gem 'redcarpet' -gem 'jwt', '~> 1.5.4' group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console diff --git a/Gemfile.lock b/Gemfile.lock index 24494af00..755561fb2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -234,7 +234,7 @@ GEM net-scp (1.2.1) net-ssh (>= 2.6.5) net-ssh (3.0.2) - newrelic_rpm (3.15.0.314) + newrelic_rpm (3.15.1.316) nokogiri (1.6.7.2) mini_portile2 (~> 2.0.0.rc2) nori (2.6.0) @@ -310,12 +310,12 @@ GEM activesupport (= 4.2.6) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - raindrops (0.15.0) - rake (11.1.1) + raindrops (0.16.0) + rake (11.1.2) redcarpet (3.3.4) referer-parser (0.3.0) request_store (1.3.0) - responders (2.1.1) + responders (2.1.2) railties (>= 4.2.0, < 5.1) rinku (1.7.3) rollbar (2.8.3) @@ -395,17 +395,16 @@ GEM safe_yaml (>= 0.8.6) turbolinks (2.5.3) coffee-rails - turnout (2.2.1) + turnout (2.3.0) rack (~> 1.3) rack-accept (~> 0.4) + tilt (>= 1.4, < 3) tzinfo (1.2.2) thread_safe (~> 0.1) - uglifier (2.7.2) - execjs (>= 0.3.0) - json (>= 1.8.0) - unicorn (5.0.1) + uglifier (3.0.0) + execjs (>= 0.3.0, < 3) + unicorn (5.1.0) kgio (~> 2.6) - rack raindrops (~> 0.7) uniform_notifier (1.9.0) user_agent_parser (2.3.0) @@ -465,7 +464,6 @@ DEPENDENCIES initialjs-rails (= 0.2.0.1) jquery-rails jquery-ui-rails - jwt (~> 1.5.4) kaminari launchy letter_opener_web (~> 1.3.0) @@ -495,7 +493,7 @@ DEPENDENCIES turbolinks turnout uglifier (>= 1.3.0) - unicorn (~> 5.0.1) + unicorn (~> 5.1.0) web-console (~> 3.0) whenever From d16ea0dfaafee8ea47fcd788b0fb30225f70a773 Mon Sep 17 00:00:00 2001 From: Ana Date: Mon, 4 Apr 2016 00:29:25 +0200 Subject: [PATCH 053/163] Translation problem fixed --- config/locales/activerecord.en.yml | 2 +- config/locales/activerecord.es.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/locales/activerecord.en.yml b/config/locales/activerecord.en.yml index faebcb449..2c7137b8e 100644 --- a/config/locales/activerecord.en.yml +++ b/config/locales/activerecord.en.yml @@ -37,7 +37,7 @@ en: proposal: one: "Citizen proposal" other: "Citizen proposals" - spending_proposal: + spendingproposal: one: "Spending proposal" other: "Spending proposals" attributes: diff --git a/config/locales/activerecord.es.yml b/config/locales/activerecord.es.yml index 79893cecd..42121809b 100644 --- a/config/locales/activerecord.es.yml +++ b/config/locales/activerecord.es.yml @@ -67,7 +67,7 @@ es: organization: name: "Nombre de organización" responsible_name: "Persona responsable del colectivo" - spending_proposal: + spendingproposal: administrator_id: "Administrador" errors: models: From ad003500fab17e687b1587e0023837dc78312a7c Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Mon, 4 Apr 2016 11:26:17 +0200 Subject: [PATCH 054/163] Adds share buttons on spending proposals show --- app/assets/stylesheets/participation.scss | 4 ++++ app/views/spending_proposals/show.html.erb | 24 ++++++++++++++++++---- config/locales/en.yml | 1 + config/locales/es.yml | 1 + 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index f769df41d..10cd6e65d 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -860,6 +860,10 @@ } } +.investment-project-show .supports { + border: 0; +} + .proposals-summary { .panel { diff --git a/app/views/spending_proposals/show.html.erb b/app/views/spending_proposals/show.html.erb index c68a1eacc..9caaa881a 100644 --- a/app/views/spending_proposals/show.html.erb +++ b/app/views/spending_proposals/show.html.erb @@ -25,10 +25,26 @@
-
- <%= render 'spending_proposals/votes', - { spending_proposal: @spending_proposal, vote_url: vote_spending_proposal_path(@spending_proposal, value: 'yes') } %> -
+
\ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 206f2fb76..9ddd5137e 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -438,6 +438,7 @@ en: back_link: Back show: author_deleted: User deleted + share: Share wrong_price_format: Only integer numbers spending_proposal: spending_proposal: Investment project diff --git a/config/locales/es.yml b/config/locales/es.yml index 2b4e31a8e..b826dfb19 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -438,6 +438,7 @@ es: back_link: Volver show: author_deleted: Usuario eliminado + share: Compartir wrong_price_format: Solo puede incluir caracteres numéricos spending_proposal: spending_proposal: Propuesta de inversión From 3ceee75850600bf6ec0847eec99e8357ee4527a0 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Mon, 4 Apr 2016 11:26:17 +0200 Subject: [PATCH 055/163] Adds share buttons on spending proposals show --- app/assets/stylesheets/participation.scss | 4 ++++ app/views/spending_proposals/show.html.erb | 24 ++++++++++++++++++---- config/locales/en.yml | 1 + config/locales/es.yml | 1 + 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index f769df41d..10cd6e65d 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -860,6 +860,10 @@ } } +.investment-project-show .supports { + border: 0; +} + .proposals-summary { .panel { diff --git a/app/views/spending_proposals/show.html.erb b/app/views/spending_proposals/show.html.erb index c68a1eacc..9caaa881a 100644 --- a/app/views/spending_proposals/show.html.erb +++ b/app/views/spending_proposals/show.html.erb @@ -25,10 +25,26 @@ -
- <%= render 'spending_proposals/votes', - { spending_proposal: @spending_proposal, vote_url: vote_spending_proposal_path(@spending_proposal, value: 'yes') } %> -
+
\ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 206f2fb76..9ddd5137e 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -438,6 +438,7 @@ en: back_link: Back show: author_deleted: User deleted + share: Share wrong_price_format: Only integer numbers spending_proposal: spending_proposal: Investment project diff --git a/config/locales/es.yml b/config/locales/es.yml index 2b4e31a8e..b826dfb19 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -438,6 +438,7 @@ es: back_link: Volver show: author_deleted: Usuario eliminado + share: Compartir wrong_price_format: Solo puede incluir caracteres numéricos spending_proposal: spending_proposal: Propuesta de inversión From 115868d20767cec46bd338f6438f16239511b554 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Mon, 4 Apr 2016 13:19:15 +0200 Subject: [PATCH 056/163] Fixes issue in i18n --- config/locales/activerecord.es.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/locales/activerecord.es.yml b/config/locales/activerecord.es.yml index 42121809b..6e459b3c5 100644 --- a/config/locales/activerecord.es.yml +++ b/config/locales/activerecord.es.yml @@ -37,7 +37,7 @@ es: proposal: one: "Propuesta ciudadana" other: "Propuestas ciudadanas" - spending_proposal: + spendingproposal: one: "Propuesta de inversión" other: "Propuestas de inversión" attributes: @@ -67,7 +67,7 @@ es: organization: name: "Nombre de organización" responsible_name: "Persona responsable del colectivo" - spendingproposal: + spending_proposal: administrator_id: "Administrador" errors: models: From b443cdc0381a85fe59a5511598daf26259ab700e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Mon, 4 Apr 2016 13:51:20 +0200 Subject: [PATCH 057/163] adds missing local variable passing --- app/views/spending_proposals/vote.js.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/spending_proposals/vote.js.erb b/app/views/spending_proposals/vote.js.erb index 4fa350aac..cc3e5a16d 100644 --- a/app/views/spending_proposals/vote.js.erb +++ b/app/views/spending_proposals/vote.js.erb @@ -1 +1 @@ -$("#<%= dom_id(@spending_proposal) %>_votes").html('<%= j render("spending_proposals/votes", spending_proposal: @spending_proposal) %>'); \ No newline at end of file +$("#<%= dom_id(@spending_proposal) %>_votes").html('<%= j render("spending_proposals/votes", spending_proposal: @spending_proposal, vote_url: vote_spending_proposal_path(@spending_proposal, value: "yes")) %>'); \ No newline at end of file From 3eca6b31bd5508a5fea258cfc88e63410d468b1c Mon Sep 17 00:00:00 2001 From: kikito Date: Mon, 4 Apr 2016 14:14:10 +0200 Subject: [PATCH 058/163] changes the format of the Spending proposal code --- app/models/spending_proposal.rb | 2 +- spec/models/spending_proposal_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/spending_proposal.rb b/app/models/spending_proposal.rb index 3e461518c..8532a7f8a 100644 --- a/app/models/spending_proposal.rb +++ b/app/models/spending_proposal.rb @@ -102,7 +102,7 @@ class SpendingProposal < ActiveRecord::Base end def code - "#{id}" + (administrator.present? ? "-A#{administrator.id}" : "") + "#{Setting["proposal_code_prefix"]}-#{created_at.strftime('%Y')}-#{id}" + (administrator.present? ? "-A#{administrator.id}" : "") end def send_unfeasible_email diff --git a/spec/models/spending_proposal_spec.rb b/spec/models/spending_proposal_spec.rb index ebe3573a4..df5b5bdd6 100644 --- a/spec/models/spending_proposal_spec.rb +++ b/spec/models/spending_proposal_spec.rb @@ -114,12 +114,12 @@ describe SpendingProposal do let(:spending_proposal) { create(:spending_proposal) } it "returns the proposal id" do - expect(spending_proposal.code).to eq("#{spending_proposal.id}") + expect(spending_proposal.code).to include("#{spending_proposal.id}") end it "returns the administrator id when assigned" do spending_proposal.administrator = create(:administrator) - expect(spending_proposal.code).to eq("#{spending_proposal.id}-A#{spending_proposal.administrator.id}") + expect(spending_proposal.code).to include("#{spending_proposal.id}-A#{spending_proposal.administrator.id}") end end end From 545e0a3d0efc11a5ab681d50bb283d9ece350039 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 4 Apr 2016 14:41:43 +0200 Subject: [PATCH 059/163] udpates translation keys --- config/locales/activerecord.en.yml | 2 +- config/locales/activerecord.es.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/locales/activerecord.en.yml b/config/locales/activerecord.en.yml index 2c7137b8e..faebcb449 100644 --- a/config/locales/activerecord.en.yml +++ b/config/locales/activerecord.en.yml @@ -37,7 +37,7 @@ en: proposal: one: "Citizen proposal" other: "Citizen proposals" - spendingproposal: + spending_proposal: one: "Spending proposal" other: "Spending proposals" attributes: diff --git a/config/locales/activerecord.es.yml b/config/locales/activerecord.es.yml index 6e459b3c5..79893cecd 100644 --- a/config/locales/activerecord.es.yml +++ b/config/locales/activerecord.es.yml @@ -37,7 +37,7 @@ es: proposal: one: "Propuesta ciudadana" other: "Propuestas ciudadanas" - spendingproposal: + spending_proposal: one: "Propuesta de inversión" other: "Propuestas de inversión" attributes: From 1e3516969495e6fb2bc3637dd10667f96c14e9c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Mon, 4 Apr 2016 14:43:49 +0200 Subject: [PATCH 060/163] fixes i18n calls --- app/mailers/mailer.rb | 2 +- config/locales/activerecord.en.yml | 6 +++--- spec/support/common_actions.rb | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/mailers/mailer.rb b/app/mailers/mailer.rb index fcc2a62b1..82abbb205 100644 --- a/app/mailers/mailer.rb +++ b/app/mailers/mailer.rb @@ -7,7 +7,7 @@ class Mailer < ApplicationMailer @comment = comment @commentable = comment.commentable with_user(@commentable.author) do - mail(to: @commentable.author.email, subject: t('mailers.comment.subject', commentable: t("activerecord.models.#{@commentable.class.name.downcase}", count: 1).downcase)) if @commentable.present? && @commentable.author.present? + mail(to: @commentable.author.email, subject: t('mailers.comment.subject', commentable: t("activerecord.models.#{@commentable.class.name.underscore}", count: 1).downcase)) if @commentable.present? && @commentable.author.present? end end diff --git a/config/locales/activerecord.en.yml b/config/locales/activerecord.en.yml index 2c7137b8e..fdd7e29de 100644 --- a/config/locales/activerecord.en.yml +++ b/config/locales/activerecord.en.yml @@ -67,6 +67,8 @@ en: organization: name: "Name of organisation" responsible_name: "Person responsible for the group" + spending_proposal: + administrator_id: "Administrator" errors: models: debate: @@ -76,6 +78,4 @@ en: proposal: attributes: tag_list: - less_than_or_equal_to: "tags must be less than or equal to %{count}" - spending_proposal: - administrator_id: "Administrator" + less_than_or_equal_to: "tags must be less than or equal to %{count}" \ No newline at end of file diff --git a/spec/support/common_actions.rb b/spec/support/common_actions.rb index f3669f253..5a211e5c5 100644 --- a/spec/support/common_actions.rb +++ b/spec/support/common_actions.rb @@ -63,7 +63,7 @@ module CommonActions commentable_path = commentable.is_a?(Proposal) ? proposal_path(commentable) : debate_path(commentable) visit commentable_path - fill_in "comment-body-#{commentable.class.name.downcase}_#{commentable.id}", with: 'Have you thought about...?' + fill_in "comment-body-#{commentable.class.name.underscore}_#{commentable.id}", with: 'Have you thought about...?' click_button 'Publish comment' expect(page).to have_content 'Have you thought about...?' From dea67a36ca60b608ebec5b3a077b17c834a666e4 Mon Sep 17 00:00:00 2001 From: kikito Date: Mon, 4 Apr 2016 14:56:16 +0200 Subject: [PATCH 061/163] fixes failing email spec --- spec/features/emails_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/emails_spec.rb b/spec/features/emails_spec.rb index 4d813493d..c6f0d3708 100644 --- a/spec/features/emails_spec.rb +++ b/spec/features/emails_spec.rb @@ -141,7 +141,7 @@ feature 'Emails' do spending_proposal.reload email = open_last_email - expect(email).to have_subject("Your investment project '#{spending_proposal.id}-A#{spending_proposal.administrator.id}' has been marked as unfeasible") + expect(email).to have_subject("Your investment project '#{spending_proposal.code}' has been marked as unfeasible") expect(email).to deliver_to(spending_proposal.author.email) expect(email).to have_body_text(spending_proposal.title) expect(email).to have_body_text(spending_proposal.code) From 27986c05c63d4e0edd77ab87654fc102dea029c3 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 4 Apr 2016 15:37:55 +0200 Subject: [PATCH 062/163] fixes typo --- config/locales/activerecord.en.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/locales/activerecord.en.yml b/config/locales/activerecord.en.yml index fdd7e29de..bfe14a8fc 100644 --- a/config/locales/activerecord.en.yml +++ b/config/locales/activerecord.en.yml @@ -37,7 +37,7 @@ en: proposal: one: "Citizen proposal" other: "Citizen proposals" - spendingproposal: + spending_proposal: one: "Spending proposal" other: "Spending proposals" attributes: From e53de93bee483acaccb756dacd871c15b703f739 Mon Sep 17 00:00:00 2001 From: kikito Date: Mon, 4 Apr 2016 18:16:27 +0200 Subject: [PATCH 063/163] removes the prefix from spending_proposal_code --- app/models/spending_proposal.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/spending_proposal.rb b/app/models/spending_proposal.rb index 8532a7f8a..f11dc71c3 100644 --- a/app/models/spending_proposal.rb +++ b/app/models/spending_proposal.rb @@ -102,7 +102,7 @@ class SpendingProposal < ActiveRecord::Base end def code - "#{Setting["proposal_code_prefix"]}-#{created_at.strftime('%Y')}-#{id}" + (administrator.present? ? "-A#{administrator.id}" : "") + "#{created_at.strftime('%Y')}-#{id}" + (administrator.present? ? "-A#{administrator.id}" : "") end def send_unfeasible_email From 871fc6e3beb30af8119bd27db6c3c279ebcf79df Mon Sep 17 00:00:00 2001 From: kikito Date: Mon, 4 Apr 2016 18:16:54 +0200 Subject: [PATCH 064/163] shows the sp ids in index/show --- app/views/spending_proposals/_spending_proposal.html.erb | 3 +++ app/views/spending_proposals/show.html.erb | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/views/spending_proposals/_spending_proposal.html.erb b/app/views/spending_proposals/_spending_proposal.html.erb index 7dff660fc..54ab4f41f 100644 --- a/app/views/spending_proposals/_spending_proposal.html.erb +++ b/app/views/spending_proposals/_spending_proposal.html.erb @@ -40,6 +40,9 @@  •  <%= geozone_name(spending_proposal) %> + +  •  + <%= spending_proposal.id %>

<%= link_to spending_proposal.description, spending_proposal_path(spending_proposal) %>

diff --git a/app/views/spending_proposals/show.html.erb b/app/views/spending_proposals/show.html.erb index 9caaa881a..99010a3dc 100644 --- a/app/views/spending_proposals/show.html.erb +++ b/app/views/spending_proposals/show.html.erb @@ -13,6 +13,8 @@ <%= l @spending_proposal.created_at.to_date %>  •  <%= geozone_name(@spending_proposal) %> +  •  + <%= @spending_proposal.id %>
<%= safe_html_with_links @spending_proposal.description.html_safe %> @@ -47,4 +49,4 @@ - \ No newline at end of file + From 6e89a21786b7ec7b923e9ba9031f29f2a92d712f Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Mon, 4 Apr 2016 14:04:18 +0200 Subject: [PATCH 065/163] Fixes commentable i18n --- config/locales/activerecord.en.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/locales/activerecord.en.yml b/config/locales/activerecord.en.yml index bfe14a8fc..f1de3c756 100644 --- a/config/locales/activerecord.en.yml +++ b/config/locales/activerecord.en.yml @@ -78,4 +78,4 @@ en: proposal: attributes: tag_list: - less_than_or_equal_to: "tags must be less than or equal to %{count}" \ No newline at end of file + less_than_or_equal_to: "tags must be less than or equal to %{count}" From ca99b2b52911eb1aea424dc25d60e11d157243b9 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Mon, 4 Apr 2016 18:35:28 +0200 Subject: [PATCH 066/163] Removes code on index, changes styles on show --- app/views/spending_proposals/_spending_proposal.html.erb | 3 --- app/views/spending_proposals/show.html.erb | 8 ++++++-- config/locales/en.yml | 1 + config/locales/es.yml | 1 + 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/views/spending_proposals/_spending_proposal.html.erb b/app/views/spending_proposals/_spending_proposal.html.erb index 54ab4f41f..7dff660fc 100644 --- a/app/views/spending_proposals/_spending_proposal.html.erb +++ b/app/views/spending_proposals/_spending_proposal.html.erb @@ -40,9 +40,6 @@  •  <%= geozone_name(spending_proposal) %> - -  •  - <%= spending_proposal.id %>

<%= link_to spending_proposal.description, spending_proposal_path(spending_proposal) %>

diff --git a/app/views/spending_proposals/show.html.erb b/app/views/spending_proposals/show.html.erb index 99010a3dc..6d642a421 100644 --- a/app/views/spending_proposals/show.html.erb +++ b/app/views/spending_proposals/show.html.erb @@ -13,10 +13,14 @@ <%= l @spending_proposal.created_at.to_date %>  •  <%= geozone_name(@spending_proposal) %> -  •  - <%= @spending_proposal.id %>
+
+

+ <%= t("spending_proposals.show.code") %> + <%= @spending_proposal.id %> +

+ <%= safe_html_with_links @spending_proposal.description.html_safe %> <% if @spending_proposal.external_url.present? %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 9ddd5137e..fa6a20cb1 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -438,6 +438,7 @@ en: back_link: Back show: author_deleted: User deleted + code: 'Investment project code:' share: Share wrong_price_format: Only integer numbers spending_proposal: diff --git a/config/locales/es.yml b/config/locales/es.yml index b826dfb19..e4fc6f281 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -438,6 +438,7 @@ es: back_link: Volver show: author_deleted: Usuario eliminado + code: 'Código propuesta de gasto:' share: Compartir wrong_price_format: Solo puede incluir caracteres numéricos spending_proposal: From 4c523906085d5ac4c7a7781fdc44fd497600ec69 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 4 Apr 2016 18:49:29 +0200 Subject: [PATCH 067/163] removes unused spec --- spec/features/spending_proposals_spec.rb | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/spec/features/spending_proposals_spec.rb b/spec/features/spending_proposals_spec.rb index 62dfee01e..718d8bbbe 100644 --- a/spec/features/spending_proposals_spec.rb +++ b/spec/features/spending_proposals_spec.rb @@ -166,25 +166,7 @@ feature 'Spending proposals' do expect(page).to have_content error_message end - scenario "Show (as admin)" do - user = create(:user) - admin = create(:administrator, user: user) - login_as(admin.user) - - spending_proposal = create(:spending_proposal, - geozone: create(:geozone), - association_name: 'People of the neighbourhood') - - visit spending_proposal_path(spending_proposal) - - expect(page).to have_content(spending_proposal.title) - expect(page).to have_content(spending_proposal.description) - expect(page).to have_content(spending_proposal.author.name) - expect(page).to have_content(spending_proposal.association_name) - expect(page).to have_content(spending_proposal.geozone.name) - end - - scenario "Show (as user)" do + scenario "Show" do user = create(:user) login_as(user) From 53502039dc7ce7016751b5dfb423db1de731e7c2 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 4 Apr 2016 18:49:46 +0200 Subject: [PATCH 068/163] adds specs for spending proposal code --- app/views/spending_proposals/show.html.erb | 2 +- spec/features/spending_proposals_spec.rb | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/views/spending_proposals/show.html.erb b/app/views/spending_proposals/show.html.erb index 6d642a421..497943820 100644 --- a/app/views/spending_proposals/show.html.erb +++ b/app/views/spending_proposals/show.html.erb @@ -16,7 +16,7 @@
-

+

<%= t("spending_proposals.show.code") %> <%= @spending_proposal.id %>

diff --git a/spec/features/spending_proposals_spec.rb b/spec/features/spending_proposals_spec.rb index 718d8bbbe..cb3a6d8d5 100644 --- a/spec/features/spending_proposals_spec.rb +++ b/spec/features/spending_proposals_spec.rb @@ -181,6 +181,9 @@ feature 'Spending proposals' do expect(page).to have_content(spending_proposal.author.name) expect(page).to have_content(spending_proposal.association_name) expect(page).to have_content(spending_proposal.geozone.name) + within("#spending_proposal_code") do + expect(page).to have_content(spending_proposal.id) + end end context "Destroy" do From be844b1ad6fae2610092f7a19a5f8b028251afa0 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Mon, 4 Apr 2016 20:50:15 +0200 Subject: [PATCH 069/163] Fixes header for management section --- app/views/layouts/management.html.erb | 84 +++++++++++++++------------ 1 file changed, 47 insertions(+), 37 deletions(-) diff --git a/app/views/layouts/management.html.erb b/app/views/layouts/management.html.erb index 75240f25d..6561573ee 100644 --- a/app/views/layouts/management.html.erb +++ b/app/views/layouts/management.html.erb @@ -16,55 +16,65 @@
- + -
- +
+ +
-
-
- <%= render "/management/menu" %> -
+
+
+
+ <%= render "/management/menu" %> +
- <%= render "management/account_info" %> + <%= render "management/account_info" %> -
- <% if notice %> -
- - <%= notice %> -
- <% end %> +
+ <% if notice %> +
+ + <%= notice %> +
+ <% end %> - <% if alert %> -
- - <%= alert %> -
- <% end %> + <% if alert %> +
+ + <%= alert %> +
+ <% end %> - <%= yield %> -
+ <%= yield %> +
+
From f18a1778ff8cf2ca28a4449d16019a5c1109e2ee Mon Sep 17 00:00:00 2001 From: Bertocq Date: Mon, 4 Apr 2016 20:56:29 +0200 Subject: [PATCH 070/163] Hashtag al compartir en redes sociales #65 @AyuntamientoMadrid/consul --- app/views/debates/show.html.erb | 2 +- app/views/proposals/_featured_votes.html.erb | 2 +- app/views/proposals/_votes.html.erb | 2 +- app/views/proposals/show.html.erb | 2 +- app/views/spending_proposals/_votes.html.erb | 2 +- app/views/spending_proposals/show.html.erb | 2 +- db/seeds.rb | 1 + 7 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/views/debates/show.html.erb b/app/views/debates/show.html.erb index 941530e58..b0aa58ce4 100644 --- a/app/views/debates/show.html.erb +++ b/app/views/debates/show.html.erb @@ -55,7 +55,7 @@

<%= t("debates.show.share") %>

diff --git a/app/views/proposals/show.html.erb b/app/views/proposals/show.html.erb index 76a344b87..0eed810de 100644 --- a/app/views/proposals/show.html.erb +++ b/app/views/proposals/show.html.erb @@ -88,7 +88,7 @@

<%= t("proposals.show.share") %>

diff --git a/app/views/spending_proposals/show.html.erb b/app/views/spending_proposals/show.html.erb index 497943820..492122264 100644 --- a/app/views/spending_proposals/show.html.erb +++ b/app/views/spending_proposals/show.html.erb @@ -43,7 +43,7 @@

<%= t("spending_proposals.show.share") %>

diff --git a/app/views/management/proposals/print.html.erb b/app/views/management/proposals/print.html.erb index 7399376f1..71220c74b 100644 --- a/app/views/management/proposals/print.html.erb +++ b/app/views/management/proposals/print.html.erb @@ -20,8 +20,8 @@ <%= render @proposals %>
-

<%= t("management.print.info") %>
- <%= t("management.print.note") %>

+

<%= t("management.print.proposals_info") %>
+ <%= t("management.print.proposals_note") %>

diff --git a/app/views/management/spending_proposals/index.html.erb b/app/views/management/spending_proposals/index.html.erb index e02d6920f..49e4151d2 100644 --- a/app/views/management/spending_proposals/index.html.erb +++ b/app/views/management/spending_proposals/index.html.erb @@ -8,12 +8,12 @@
- <%= content_tag(:h2, t("spending_proposals.index.unfeasible")) if params[:unfeasible].present? %> - <%= content_tag(:h2, t("spending_proposals.index.by_geozone", geozone: @geozone_name)) if @geozone_name.present? %> + <%= content_tag(:h2, t("management.spending_proposals.filters.unfeasible")) if params[:unfeasible].present? %> + <%= content_tag(:h2, t("management.spending_proposals.filters.by_geozone", geozone: @geozone_name)) if @geozone_name.present? %> <% if params[:search].present? %>

<%= page_entries_info @spending_proposals %> - <%= t("spending_proposals.index.search_results", count: @spending_proposals.size, search_term: params[:search]) %> + <%= t("management.spending_proposals.search_results", count: @spending_proposals.size, search_term: params[:search]) %>

<% end %>
diff --git a/app/views/management/spending_proposals/print.html.erb b/app/views/management/spending_proposals/print.html.erb new file mode 100644 index 000000000..46a012149 --- /dev/null +++ b/app/views/management/spending_proposals/print.html.erb @@ -0,0 +1,34 @@ +
+
+
+ +
+ <%= form_tag print_management_spending_proposals_path, method: :get, enforce_utf8: false do %> +
+ <%= select_tag :geozone, + options_for_select(geozone_select_options.unshift([t("geozones.none"), "all"]), params[:geozone]), + { label: false, + class: "js-submit-on-change" } %> +
+ <% end %> + + + <%= t('management.spending_proposals.print.print_button') %> + +
+ +
+ <%= content_tag(:h2, t("management.spending_proposals.filters.unfeasible"), class: "inline-block") if params[:unfeasible].present? %> + <%= content_tag(:h2, t("management.spending_proposals.filters.by_geozone", geozone: @geozone_name), class: "inline-block") if @geozone_name.present? %> + <%= content_tag(:h2, t("management.spending_proposals.search_results", count: @spending_proposals.size, search_term: params[:search]), class: "inline-block") if params[:search].present? %> +
+ + <%= render @spending_proposals %> + +
+

<%= t("management.print.spending_proposals_info") %>
+ <%= t("management.print.spending_proposals_note") %>

+
+
+
+
diff --git a/config/locales/management.en.yml b/config/locales/management.en.yml index 1e8e99196..3f9a447b0 100644 --- a/config/locales/management.en.yml +++ b/config/locales/management.en.yml @@ -41,6 +41,7 @@ en: print_proposals: Print proposals support_proposals: Support proposals create_spending_proposal: Create spending proposal + print_spending_proposals: Print spending proposals support_spending_proposals: Support spending proposals title: Management users: Users @@ -50,9 +51,11 @@ en: support_proposals: Support proposals vote_proposals: Vote proposals print: - info: Create yor proposal on http://decide.madrid.es - note: The proposals more supported will be voted. If are accepted by a majority, the city Council shall be carried out. + proposals_info: Create yor proposal on http://decide.madrid.es + proposals_note: The proposals more supported will be voted. If are accepted by a majority, the city Council shall be carried out. proposals_title: 'Proposals:' + spending_proposals_info: Participate at http://decide.madrid.es + spending_proposals_note: Participatory budget will be assigned to the most votes spending proposals. print_info: Print this info proposals: alert: @@ -64,6 +67,14 @@ en: alert: unverified_user: User is not verified create: Create spending proposal + filters: + unfeasible: Unfeasible investment projects + by_geozone: "Investment projects with scope: %{geozone}" + print: + print_button: Print + search_results: + one: " containing the term '%{search_term}'" + other: " containing the term '%{search_term}'" sessions: signed_out: Signed out successfully. signed_out_managed_user: User session signed out successfully. diff --git a/config/locales/management.es.yml b/config/locales/management.es.yml index f1de3cf88..540bad027 100644 --- a/config/locales/management.es.yml +++ b/config/locales/management.es.yml @@ -41,7 +41,8 @@ es: print_proposals: Imprimir propuestas support_proposals: Apoyar propuestas create_spending_proposal: Crear propuesta de inversión - support_spending_proposals: Apoyar propuestas de inversión + print_spending_proposals: Imprimir propts. de inversión + support_spending_proposals: Apoyar propts. de inversión title: Gestión users: Usuarios permissions: @@ -50,9 +51,11 @@ es: support_proposals: Apoyar propuestas vote_proposals: Participar en las votaciones finales print: - info: Haz tu propuesta en http://decide.madrid.es - note: Las propuestas más apoyadas serán llevadas a votación. Y si las acepta una mayoría, el Ayuntamiento las llevará a cabo. + proposals_info: Haz tu propuesta en http://decide.madrid.es + proposals_note: Las propuestas más apoyadas serán llevadas a votación. Y si las acepta una mayoría, el Ayuntamiento las llevará a cabo. proposals_title: 'Propuestas:' + spending_proposals_info: Participa en http://decide.madrid.es + spending_proposals_note: Los presupuestos participativos se invertirán en las propuestas de inversión más apoyadas. print_info: Imprimir esta información proposals: alert: @@ -64,6 +67,14 @@ es: alert: unverified_user: Este usuario no está verificado create: Crear propuesta de inversión + filters: + unfeasible: Propuestas de inversión no viables + by_geozone: "Propuestas de inversión con ámbito: %{geozone}" + print: + print_button: Imprimir + search_results: + one: " que contiene '%{search_term}'" + other: " que contienen '%{search_term}'" sessions: signed_out: Has cerrado la sesión correctamente. signed_out_managed_user: Se ha cerrado correctamente la sesión del usuario. diff --git a/spec/features/management/spending_proposals_spec.rb b/spec/features/management/spending_proposals_spec.rb index 9ee161fd8..760d2a07a 100644 --- a/spec/features/management/spending_proposals_spec.rb +++ b/spec/features/management/spending_proposals_spec.rb @@ -175,4 +175,50 @@ feature 'Spending Proposals' do end end + context "Printing" do + + scenario 'Printing spending proposals' do + 16.times { create(:spending_proposal, geozone_id: nil) } + + click_link "Print spending proposals" + + expect(page).to have_css('.investment-project', count: 15) + expect(page).to have_css("a[href='javascript:window.print();']", text: 'Print') + end + + scenario "Filtering spending proposals by geozone to be printed", :js do + district_9 = create(:geozone, name: "District Nine") + create(:spending_proposal, title: 'Change district 9', geozone: district_9, cached_votes_up: 10) + create(:spending_proposal, title: 'Destroy district 9', geozone: district_9, cached_votes_up: 100) + create(:spending_proposal, title: 'Nuke district 9', geozone: district_9, cached_votes_up: 1) + create(:spending_proposal, title: 'Add new districts to the city', geozone_id: nil) + + user = create(:user, :level_two) + login_managed_user(user) + + click_link "Print spending proposals" + + expect(page).to have_content "Investment projects with scope: All city" + + within '#investment-projects' do + expect(page).to have_content('Add new districts to the city') + expect(page).to_not have_content('Change district 9') + expect(page).to_not have_content('Destroy district 9') + expect(page).to_not have_content('Nuke district 9') + end + + select 'District Nine', from: 'geozone' + + expect(page).to have_content "Investment projects with scope: District Nine" + expect(current_url).to include("geozone=#{district_9.id}") + + within '#investment-projects' do + expect(page).to_not have_content('Add new districts to the city') + expect('Destroy district 9').to appear_before('Change district 9') + expect('Change district 9').to appear_before('Nuke district 9') + end + end + + end + end \ No newline at end of file From 1d931e7943bccf42dc93facaac1590600c2f6f2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Wed, 6 Apr 2016 19:05:00 +0200 Subject: [PATCH 087/163] removes unnecessary :js --- spec/features/management/proposals_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/management/proposals_spec.rb b/spec/features/management/proposals_spec.rb index f83c37a0c..e5279bac4 100644 --- a/spec/features/management/proposals_spec.rb +++ b/spec/features/management/proposals_spec.rb @@ -185,7 +185,7 @@ feature 'Proposals' do context "Printing" do - scenario 'Printing proposals', :js do + scenario 'Printing proposals' do 6.times { create(:proposal) } click_link "Print proposals" From 3c8416e8637fecc0e8a652a0bb48b6889aa6cc79 Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 6 Apr 2016 19:18:10 +0200 Subject: [PATCH 088/163] Adds responsible_name to spending_proposals --- ...60406163649_add_responsible_name_to_spending_proposals.rb | 5 +++++ db/schema.rb | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20160406163649_add_responsible_name_to_spending_proposals.rb diff --git a/db/migrate/20160406163649_add_responsible_name_to_spending_proposals.rb b/db/migrate/20160406163649_add_responsible_name_to_spending_proposals.rb new file mode 100644 index 000000000..5749400bb --- /dev/null +++ b/db/migrate/20160406163649_add_responsible_name_to_spending_proposals.rb @@ -0,0 +1,5 @@ +class AddResponsibleNameToSpendingProposals < ActiveRecord::Migration + def change + add_column :spending_proposals, :responsible_name, :string, limit: 60 + end +end diff --git a/db/schema.rb b/db/schema.rb index a031c51f5..4183e0246 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: 20160329160106) do +ActiveRecord::Schema.define(version: 20160406163649) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -314,6 +314,7 @@ ActiveRecord::Schema.define(version: 20160329160106) do t.datetime "unfeasible_email_sent_at" t.integer "cached_votes_up", default: 0 t.tsvector "tsv" + t.string "responsible_name", limit: 60 end add_index "spending_proposals", ["author_id"], name: "index_spending_proposals_on_author_id", using: :btree From 32a60515c6901d3f2164185c5b4dcc8511f0fd5d Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 6 Apr 2016 19:23:05 +0200 Subject: [PATCH 089/163] updates the sp responsible_name when creating/editing a sp --- app/models/spending_proposal.rb | 6 ++++++ spec/models/spending_proposal_spec.rb | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/app/models/spending_proposal.rb b/app/models/spending_proposal.rb index f11dc71c3..2ee2eb6e8 100644 --- a/app/models/spending_proposal.rb +++ b/app/models/spending_proposal.rb @@ -36,6 +36,8 @@ class SpendingProposal < ActiveRecord::Base scope :for_render, -> { includes(:geozone) } + before_validation :update_responsible_name + def description super.try :html_safe end @@ -120,4 +122,8 @@ class SpendingProposal < ActiveRecord::Base end end + def update_responsible_name + self.responsible_name = author.try(:username) + end + end diff --git a/spec/models/spending_proposal_spec.rb b/spec/models/spending_proposal_spec.rb index df5b5bdd6..d841abf06 100644 --- a/spec/models/spending_proposal_spec.rb +++ b/spec/models/spending_proposal_spec.rb @@ -261,4 +261,12 @@ describe SpendingProposal do end end + describe "responsible_name" do + it "gets updated with the user name" do + u = create(:user, username: "manolo") + sp = create(:spending_proposal, author: u) + expect(sp.responsible_name).to eq("manolo") + end + end + end From 58fb6e68ea79a65ff6defd6374e04483454c877f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Wed, 6 Apr 2016 19:25:27 +0200 Subject: [PATCH 090/163] cleans up routes: use blocks only when necessary --- config/routes.rb | 67 +++++++++++++++--------------------------------- 1 file changed, 20 insertions(+), 47 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 7bc31139e..92bdf8601 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -67,9 +67,7 @@ Rails.application.routes.draw do scope '/participatory_budget' do resources :spending_proposals, only: [:index, :new, :create, :show, :destroy], path: 'investment_projects' do - member do - post :vote - end + post :vote, on: :member end end @@ -78,19 +76,17 @@ Rails.application.routes.draw do resources :legislations, only: [:show] resources :annotations do - collection do - get :search - end + get :search, on: :collection end resources :users, only: [:show] resource :account, controller: "account", only: [:show, :update, :delete] do - collection { get :erase } + get :erase, on: :collection end resources :notifications, only: [:index, :show] do - collection { put :mark_all_as_read } + put :mark_all_as_read, on: :collection end resource :verification, controller: "verification", only: [:show] @@ -106,7 +102,7 @@ Rails.application.routes.draw do namespace :admin do root to: "dashboard#index" resources :organizations, only: :index do - collection { get :search } + get :search, on: :collection member do put :verify put :reject @@ -150,20 +146,20 @@ Rails.application.routes.draw do resources :tags, only: [:index, :create, :update, :destroy] resources :officials, only: [:index, :edit, :update, :destroy] do - collection { get :search} + get :search, on: :collection end resources :settings, only: [:index, :update] resources :moderators, only: [:index, :create, :destroy] do - collection { get :search } + get :search, on: :collection end resources :valuators, only: [:index, :create] do - collection { get :search } + get :search, on: :collection end resources :verifications, controller: :verifications, only: :index do - collection { get :search} + get :search, on: :collection end resource :activity, controller: :activity, only: :show @@ -185,30 +181,18 @@ Rails.application.routes.draw do end resources :debates, only: :index do - member do - put :hide - end - collection do - put :moderate - end + put :hide, on: :member + put :moderate, on: :collection end resources :proposals, only: :index do - member do - put :hide - end - collection do - put :moderate - end + put :hide, on: :member + put :moderate, on: :collection end resources :comments, only: :index do - member do - put :hide - end - collection do - put :moderate - end + put :hide, on: :member + put :moderate, on: :collection end end @@ -216,9 +200,7 @@ Rails.application.routes.draw do root to: "spending_proposals#index" resources :spending_proposals, only: [:index, :show, :edit] do - member do - patch :valuate - end + patch :valuate, on: :member end end @@ -226,30 +208,21 @@ Rails.application.routes.draw do root to: "dashboard#index" resources :document_verifications, only: [:index, :new, :create] do - collection do - post :check - end + post :check, on: :collection end resources :email_verifications, only: [:new, :create] resources :users, only: [:new, :create] do - collection do - delete :logout - end + delete :logout, on: :collection end get 'sign_in', to: 'sessions#create' resource :session, only: [:create, :destroy] resources :proposals, only: [:index, :new, :create, :show] do - member do - post :vote - end - - collection do - get :print - end + post :vote, on: :member + get :print, on: :collection end resources :spending_proposals, only: [:index, :new, :create, :show] do From 95b0e75427d424a998d383c16ed3f17659e29371 Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 6 Apr 2016 19:27:18 +0200 Subject: [PATCH 091/163] Rename method --- app/models/spending_proposal.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/spending_proposal.rb b/app/models/spending_proposal.rb index 2ee2eb6e8..f4657e9d4 100644 --- a/app/models/spending_proposal.rb +++ b/app/models/spending_proposal.rb @@ -36,7 +36,7 @@ class SpendingProposal < ActiveRecord::Base scope :for_render, -> { includes(:geozone) } - before_validation :update_responsible_name + before_validation :set_responsible_name def description super.try :html_safe @@ -122,7 +122,7 @@ class SpendingProposal < ActiveRecord::Base end end - def update_responsible_name + def set_responsible_name self.responsible_name = author.try(:username) end From 9a74b79eabaf6fc32781ebffc66fcc9602235e63 Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 6 Apr 2016 19:27:39 +0200 Subject: [PATCH 092/163] Fixes typo in rake task. Adds comment. --- lib/tasks/spending_proposals.rake | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/tasks/spending_proposals.rake b/lib/tasks/spending_proposals.rake index 42cde5424..365338d96 100644 --- a/lib/tasks/spending_proposals.rake +++ b/lib/tasks/spending_proposals.rake @@ -1,20 +1,21 @@ namespace :spending_proposals do desc "Sends an email to the authors of unfeasible spending proposals" task send_unfeasible_emails: :environment do - SpendingProposal.find_each do |spending_propsal| - if spending_propsal.unfeasible_email_pending? - spending_propsal.send_unfeasible_email - puts "email sent for proposal #{spending_propsal.title}" + SpendingProposal.find_each do |spending_proposal| + if spending_proposal.unfeasible_email_pending? + spending_proposal.send_unfeasible_email + puts "email sent for proposal #{spending_proposal.title}" else - puts "this proposal is feasible: #{spending_propsal.title}" + puts "this proposal is feasible: #{spending_proposal.title}" end end end - desc "Updates all spending proposals to recalculate their tsv column" + desc "Updates all spending proposals to recalculate their tsv and responsible_name columns" task touch: :environment do - SpendingProposal.find_in_batches do |spending_propsal| - spending_propsal.each(&:save) + SpendingProposal.find_in_batches do |spending_proposal| + spending_proposal.each(&:save) end end -end \ No newline at end of file + +end From d03864adb20a259fc75109feae0c9110df626522 Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 6 Apr 2016 18:08:00 +0200 Subject: [PATCH 093/163] replaces the select in the valuators index with a list of links + pending count --- .../spending_proposals_controller.rb | 21 +++++++++++++++++++ .../spending_proposals/index.html.erb | 16 +++++++------- .../valuation/spending_proposals_spec.rb | 6 +++--- 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/app/controllers/valuation/spending_proposals_controller.rb b/app/controllers/valuation/spending_proposals_controller.rb index c5f822b40..77a80b413 100644 --- a/app/controllers/valuation/spending_proposals_controller.rb +++ b/app/controllers/valuation/spending_proposals_controller.rb @@ -9,6 +9,7 @@ class Valuation::SpendingProposalsController < Valuation::BaseController load_and_authorize_resource def index + @geozone_filters = geozone_filters if current_user.valuator? @spending_proposals = SpendingProposal.scoped_filter(params_for_current_valuator, @current_filter).order(created_at: :desc).page(params[:page]) else @@ -31,6 +32,26 @@ class Valuation::SpendingProposalsController < Valuation::BaseController private + def geozone_filters + + spending_proposals = SpendingProposal.by_valuator(current_user.valuator.try(:id)).valuation_open.all.to_a + + [ { name: t('valuation.spending_proposals.index.geozone_filter_all'), + id: nil, + pending_count: spending_proposals.size + }, + { name: t('geozones.none'), + id: 'all', + pending_count: spending_proposals.count{|x| x.geozone_id.nil?} + } + ] + Geozone.all.order(name: :asc).collect do |g| + { name: g.name, + id: g.id, + pending_count: spending_proposals.count{|x| x.geozone_id == g.id} + } + end + end + def valuation_params params[:spending_proposal][:feasible] = nil if params[:spending_proposal][:feasible] == 'nil' diff --git a/app/views/valuation/spending_proposals/index.html.erb b/app/views/valuation/spending_proposals/index.html.erb index e6c05d6c7..9f5b13fab 100644 --- a/app/views/valuation/spending_proposals/index.html.erb +++ b/app/views/valuation/spending_proposals/index.html.erb @@ -1,14 +1,12 @@

<%= t("valuation.spending_proposals.index.title") %>

- <%= form_tag valuation_spending_proposals_path, method: :get, enforce_utf8: false do %> -
- <%= select_tag :geozone_id, - options_for_select(geozone_select_options.unshift([t("geozones.none"), "all"]), params[:geozone_id]), - { prompt: t("valuation.spending_proposals.index.geozone_filter_all"), - label: false, - class: "js-submit-on-change" } %> -
+ <% @geozone_filters.each do |filter| %> + + <%= link_to valuation_spending_proposals_path(geozone_id: filter[:id]) do %> + <%= filter[:name] %>(<%= filter[:pending_count] %>) + <% end %> + <% end %>
@@ -38,4 +36,4 @@ <% end %> -<%= paginate @spending_proposals %> \ No newline at end of file +<%= paginate @spending_proposals %> diff --git a/spec/features/valuation/spending_proposals_spec.rb b/spec/features/valuation/spending_proposals_spec.rb index 8af416dc2..6cb1acf1a 100644 --- a/spec/features/valuation/spending_proposals_spec.rb +++ b/spec/features/valuation/spending_proposals_spec.rb @@ -76,17 +76,17 @@ feature 'Valuation spending proposals' do expect(page).to have_link("Realocate visitors") expect(page).to have_link("Destroy the city") - select "District 9", from: "geozone_id" + click_link "District 9", exact: false expect(page).to have_link("Realocate visitors") expect(page).to_not have_link("Destroy the city") - select "All city", from: "geozone_id" + click_link "All city", exact: false expect(page).to have_link("Destroy the city") expect(page).to_not have_link("Realocate visitors") - select "All zones", from: "geozone_id" + click_link "All zones", exact: false expect(page).to have_link("Realocate visitors") expect(page).to have_link("Destroy the city") end From a887b78787488c7913967d8b6504c4d7cb489ad0 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Wed, 6 Apr 2016 23:48:40 +0200 Subject: [PATCH 094/163] Improves styles for valuation geozones select menu --- app/assets/stylesheets/admin.scss | 13 +++++++++++++ .../valuation/spending_proposals/index.html.erb | 15 +++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/app/assets/stylesheets/admin.scss b/app/assets/stylesheets/admin.scss index cfec260e1..1ccd7c880 100644 --- a/app/assets/stylesheets/admin.scss +++ b/app/assets/stylesheets/admin.scss @@ -355,3 +355,16 @@ body.admin { width: 100%; } } + +.admin-content .select-geozone { + + a { + display: block; + + &.active { + color: $brand; + font-weight: bold; + text-decoration: underline; + } + } +} diff --git a/app/views/valuation/spending_proposals/index.html.erb b/app/views/valuation/spending_proposals/index.html.erb index 9f5b13fab..8536ec424 100644 --- a/app/views/valuation/spending_proposals/index.html.erb +++ b/app/views/valuation/spending_proposals/index.html.erb @@ -1,12 +1,15 @@

<%= t("valuation.spending_proposals.index.title") %>

-
- <% @geozone_filters.each do |filter| %> - - <%= link_to valuation_spending_proposals_path(geozone_id: filter[:id]) do %> - <%= filter[:name] %>(<%= filter[:pending_count] %>) +
+ <% @geozone_filters.each_slice(8) do |slice| %> +
+ <% slice.each do |filter| %> + <%= link_to valuation_spending_proposals_path(geozone_id: filter[:id]), + class: "#{'active' if params[:geozone_id].to_s == filter[:id].to_s}" do %> + <%= filter[:name] %> (<%= filter[:pending_count] %>) + <% end %> <% end %> - +
<% end %>
From 3e8150ceae8b6924d51d3301a3356d41f5bff4b8 Mon Sep 17 00:00:00 2001 From: kikito Date: Thu, 7 Apr 2016 12:16:11 +0200 Subject: [PATCH 095/163] hides the not-pending sps in valuation --- app/controllers/valuation/spending_proposals_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/valuation/spending_proposals_controller.rb b/app/controllers/valuation/spending_proposals_controller.rb index 77a80b413..83d76e0a0 100644 --- a/app/controllers/valuation/spending_proposals_controller.rb +++ b/app/controllers/valuation/spending_proposals_controller.rb @@ -49,7 +49,7 @@ class Valuation::SpendingProposalsController < Valuation::BaseController id: g.id, pending_count: spending_proposals.count{|x| x.geozone_id == g.id} } - end + end.select{ |x| x[:pending_count] > 0 } end def valuation_params From 6f5a23bb4fd02147ed55a304cc823cabd37ede21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Fri, 8 Apr 2016 11:01:36 +0200 Subject: [PATCH 096/163] makes manager a HashWithIndifferentAccess --- lib/manager_authenticator.rb | 2 +- spec/support/common_actions.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/manager_authenticator.rb b/lib/manager_authenticator.rb index 3f0d58357..2d8e6f1f9 100644 --- a/lib/manager_authenticator.rb +++ b/lib/manager_authenticator.rb @@ -1,7 +1,7 @@ class ManagerAuthenticator def initialize(data={}) - @manager = {login: data[:login], user_key: data[:clave_usuario], date: data[:fecha_conexion]} + @manager = {login: data[:login], user_key: data[:clave_usuario], date: data[:fecha_conexion]}.with_indifferent_access end def auth diff --git a/spec/support/common_actions.rb b/spec/support/common_actions.rb index 5a211e5c5..f3d4a8697 100644 --- a/spec/support/common_actions.rb +++ b/spec/support/common_actions.rb @@ -27,7 +27,7 @@ module CommonActions def login_as_manager login, user_key, date = "JJB042", "31415926", Time.now.strftime("%Y%m%d%H%M%S") - allow_any_instance_of(ManagerAuthenticator).to receive(:auth).and_return({login: login, user_key: user_key, date: date}) + allow_any_instance_of(ManagerAuthenticator).to receive(:auth).and_return({login: login, user_key: user_key, date: date}.with_indifferent_access) visit management_sign_in_path(login: login, clave_usuario: user_key, fecha_conexion: date) end From ce477273da280fc78426d2e3e582c483f988412f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Fri, 8 Apr 2016 11:03:30 +0200 Subject: [PATCH 097/163] adds managers option to delete a level 2 account --- .../management/users_controller.rb | 6 +++++ .../document_verifications/new.html.erb | 11 ++++++++ config/locales/management.en.yml | 6 +++++ config/locales/management.es.yml | 6 +++++ config/routes.rb | 5 +++- spec/features/management/users_spec.rb | 27 ++++++++++++++++++- 6 files changed, 59 insertions(+), 2 deletions(-) diff --git a/app/controllers/management/users_controller.rb b/app/controllers/management/users_controller.rb index 53c432fd1..8ee04cfdf 100644 --- a/app/controllers/management/users_controller.rb +++ b/app/controllers/management/users_controller.rb @@ -18,6 +18,12 @@ class Management::UsersController < Management::BaseController end end + def erase + managed_user.erase(t("management.users.erased_by_manager", manager: current_manager['login'])) if current_manager.present? + destroy_session + redirect_to management_document_verifications_path, notice: t("management.users.erased_notice") + end + def logout destroy_session redirect_to management_root_url, notice: t("management.sessions.signed_out_managed_user") diff --git a/app/views/management/document_verifications/new.html.erb b/app/views/management/document_verifications/new.html.erb index 068d84f41..100c2592e 100644 --- a/app/views/management/document_verifications/new.html.erb +++ b/app/views/management/document_verifications/new.html.erb @@ -13,3 +13,14 @@ <%= f.hidden_field :document_number %> <%= f.submit t("management.document_verifications.verify"), class: "button success" %> <% end %> + + +<%= link_to t("management.document_verifications.erase_account_link"), "#", class: "delete js-toggle-link", data: { "toggle-selector" => "#erase-account-form" } %> + + diff --git a/config/locales/management.en.yml b/config/locales/management.en.yml index 3f9a447b0..fb9929924 100644 --- a/config/locales/management.en.yml +++ b/config/locales/management.en.yml @@ -24,6 +24,10 @@ en: title: User management under_age: You must be over 16 to verify your account. verify: Verify + erase_account_link: Delete user + erase_account_confirm: Are you sure you want to erase the account? This action can not be undone + erase_warning: This action can not be undone. Please make sure you want to erase this account. + erase_submit: Delete account email_label: Email email_verifications: already_verified: This user account is already verified. @@ -84,3 +88,5 @@ en: create_user_info: 'We will create an account with the following data:' create_user_submit: Create user create_user_success_html: We have sent an email to the email address %{email} in order to verify that it belongs to this user. It contains a link they have to click. Then they will have to set their access password before being able to log in to the website + erased_notice: User account deleted. + erased_by_manager: "Deleted by manager: %{manager}" diff --git a/config/locales/management.es.yml b/config/locales/management.es.yml index 540bad027..262108652 100644 --- a/config/locales/management.es.yml +++ b/config/locales/management.es.yml @@ -24,6 +24,10 @@ es: title: Gestión de usuarios under_age: Debes ser mayor de 16 años para verificar tu cuenta. verify: Verificar usuario + erase_account_link: Borrar cuenta + erase_account_confirm: ¿Seguro que quieres borrar a este usuario? Esta acción no se puede deshacer + erase_warning: Esta acción no se puede deshacer. Por favor asegurese de que quiere eliminar esta cuenta. + erase_submit: Borrar cuenta email_label: Email email_verifications: already_verified: Esta cuenta de usuario ya está verificada. @@ -84,3 +88,5 @@ es: create_user_info: 'Procedemos a crear un usuario con la siguiente información:' create_user_submit: Crear usuario create_user_success_html: Hemos enviado un correo electrónico a %{email} para verificar que es suya. El correo enviado contiene un link que el usuario deberá pulsar. Entonces podrá seleccionar una clave de acceso, y entrar en la web de participación. + erased_notice: Cuenta de usuario borrada. + erased_by_manager: "Borrada por el manager: %{manager}" diff --git a/config/routes.rb b/config/routes.rb index 92bdf8601..b38823a65 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -214,7 +214,10 @@ Rails.application.routes.draw do resources :email_verifications, only: [:new, :create] resources :users, only: [:new, :create] do - delete :logout, on: :collection + collection do + delete :logout + delete :erase + end end get 'sign_in', to: 'sessions#create' diff --git a/spec/features/management/users_spec.rb b/spec/features/management/users_spec.rb index 31e4bbeeb..83ac9248a 100644 --- a/spec/features/management/users_spec.rb +++ b/spec/features/management/users_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' feature 'users' do - scenario 'Creating a level 3 user from scratch' do + scenario 'Create a level 3 user from scratch' do login_as_manager @@ -42,4 +42,29 @@ feature 'users' do expect(page).to have_content "Your account has been confirmed." end + scenario 'Delete a level 2 user account from document verification page', :js do + level_2_user = create(:user, :level_two, document_number: 13579) + login_as_manager + + visit management_document_verifications_path + fill_in 'document_verification_document_number', with: '13579' + click_button 'Check' + + expect(page).to_not have_content "This user account is already verified." + expect(page).to have_content "This user can participate in the website with the following permissions" + + click_link "Delete user" + click_link "Delete account" + + expect(page).to have_content "User account deleted." + + expect(level_2_user.reload.erase_reason).to eq "Deleted by manager: JJB042" + + visit management_document_verifications_path + fill_in 'document_verification_document_number', with: '13579' + click_button 'Check' + + expect(page).to have_content "no user account associated to it" + end + end \ No newline at end of file From e4e87bf548e306fcfd1aa7a57cedf8d3655ea5fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Fri, 8 Apr 2016 11:38:58 +0200 Subject: [PATCH 098/163] moves user deletion link to a partial --- .../management/document_verifications/new.html.erb | 11 +---------- .../management/users/_erase_user_account.html.erb | 9 +++++++++ config/locales/management.en.yml | 8 ++++---- config/locales/management.es.yml | 8 ++++---- 4 files changed, 18 insertions(+), 18 deletions(-) create mode 100644 app/views/management/users/_erase_user_account.html.erb diff --git a/app/views/management/document_verifications/new.html.erb b/app/views/management/document_verifications/new.html.erb index 100c2592e..1c1b5778d 100644 --- a/app/views/management/document_verifications/new.html.erb +++ b/app/views/management/document_verifications/new.html.erb @@ -14,13 +14,4 @@ <%= f.submit t("management.document_verifications.verify"), class: "button success" %> <% end %> - -<%= link_to t("management.document_verifications.erase_account_link"), "#", class: "delete js-toggle-link", data: { "toggle-selector" => "#erase-account-form" } %> - - +<%= render 'management/users/erase_user_account' %> \ No newline at end of file diff --git a/app/views/management/users/_erase_user_account.html.erb b/app/views/management/users/_erase_user_account.html.erb new file mode 100644 index 000000000..af2e3b75b --- /dev/null +++ b/app/views/management/users/_erase_user_account.html.erb @@ -0,0 +1,9 @@ +<%= link_to t("management.users.erase_account_link"), "#", class: "delete js-toggle-link", data: { "toggle-selector" => "#erase-account-form" } %> + + \ No newline at end of file diff --git a/config/locales/management.en.yml b/config/locales/management.en.yml index fb9929924..252d77938 100644 --- a/config/locales/management.en.yml +++ b/config/locales/management.en.yml @@ -24,10 +24,6 @@ en: title: User management under_age: You must be over 16 to verify your account. verify: Verify - erase_account_link: Delete user - erase_account_confirm: Are you sure you want to erase the account? This action can not be undone - erase_warning: This action can not be undone. Please make sure you want to erase this account. - erase_submit: Delete account email_label: Email email_verifications: already_verified: This user account is already verified. @@ -90,3 +86,7 @@ en: create_user_success_html: We have sent an email to the email address %{email} in order to verify that it belongs to this user. It contains a link they have to click. Then they will have to set their access password before being able to log in to the website erased_notice: User account deleted. erased_by_manager: "Deleted by manager: %{manager}" + erase_account_link: Delete user + erase_account_confirm: Are you sure you want to erase the account? This action can not be undone + erase_warning: This action can not be undone. Please make sure you want to erase this account. + erase_submit: Delete account diff --git a/config/locales/management.es.yml b/config/locales/management.es.yml index 262108652..4b3b9ae59 100644 --- a/config/locales/management.es.yml +++ b/config/locales/management.es.yml @@ -24,10 +24,6 @@ es: title: Gestión de usuarios under_age: Debes ser mayor de 16 años para verificar tu cuenta. verify: Verificar usuario - erase_account_link: Borrar cuenta - erase_account_confirm: ¿Seguro que quieres borrar a este usuario? Esta acción no se puede deshacer - erase_warning: Esta acción no se puede deshacer. Por favor asegurese de que quiere eliminar esta cuenta. - erase_submit: Borrar cuenta email_label: Email email_verifications: already_verified: Esta cuenta de usuario ya está verificada. @@ -90,3 +86,7 @@ es: create_user_success_html: Hemos enviado un correo electrónico a %{email} para verificar que es suya. El correo enviado contiene un link que el usuario deberá pulsar. Entonces podrá seleccionar una clave de acceso, y entrar en la web de participación. erased_notice: Cuenta de usuario borrada. erased_by_manager: "Borrada por el manager: %{manager}" + erase_account_link: Borrar cuenta + erase_account_confirm: ¿Seguro que quieres borrar a este usuario? Esta acción no se puede deshacer + erase_warning: Esta acción no se puede deshacer. Por favor asegurese de que quiere eliminar esta cuenta. + erase_submit: Borrar cuenta From 83e58f0cc9f72e165d8e9ce44597dea667048ced Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Fri, 8 Apr 2016 11:43:26 +0200 Subject: [PATCH 099/163] adds account section to management for now it only has the option to delete account --- .../management/account_controller.rb | 19 +++++++++++ app/views/management/_menu.html.erb | 7 ++++ app/views/management/account/show.html.erb | 3 ++ config/locales/management.en.yml | 6 ++++ config/locales/management.es.yml | 6 ++++ config/routes.rb | 2 ++ spec/features/management/account_spec.rb | 32 +++++++++++++++++++ spec/features/management/users_spec.rb | 9 +++--- 8 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 app/controllers/management/account_controller.rb create mode 100644 app/views/management/account/show.html.erb create mode 100644 spec/features/management/account_spec.rb diff --git a/app/controllers/management/account_controller.rb b/app/controllers/management/account_controller.rb new file mode 100644 index 000000000..b3b79a8e9 --- /dev/null +++ b/app/controllers/management/account_controller.rb @@ -0,0 +1,19 @@ +class Management::AccountController < Management::BaseController + + before_action :check_verified_user + + def show + end + + private + def check_verified_user + unless current_user.level_two_or_three_verified? + redirect_to management_document_verifications_path, alert: t("management.account.alert.unverified_user") + end + end + + def current_user + managed_user + end + +end diff --git a/app/views/management/_menu.html.erb b/app/views/management/_menu.html.erb index 0106865d2..00e3b0516 100644 --- a/app/views/management/_menu.html.erb +++ b/app/views/management/_menu.html.erb @@ -13,6 +13,13 @@ <% end %> +
  • > + <%= link_to management_account_path do %> + + <%= t("management.menu.edit_user_accounts") %> + <% end %> +
  • +
  • > <%= link_to new_management_proposal_path do %> diff --git a/app/views/management/account/show.html.erb b/app/views/management/account/show.html.erb new file mode 100644 index 000000000..09287ee3e --- /dev/null +++ b/app/views/management/account/show.html.erb @@ -0,0 +1,3 @@ +

    <%= t("management.account.show.title") %>

    + +<%= render 'management/users/erase_user_account' %> diff --git a/config/locales/management.en.yml b/config/locales/management.en.yml index 252d77938..2c13d4d19 100644 --- a/config/locales/management.en.yml +++ b/config/locales/management.en.yml @@ -1,6 +1,11 @@ --- en: management: + account: + alert: + unverified_user: No verified user logged in yet + show: + title: User account account_info: change_user: Change user document_number_label: 'Document number:' @@ -45,6 +50,7 @@ en: support_spending_proposals: Support spending proposals title: Management users: Users + edit_user_accounts: Edit user account permissions: create_proposals: Create proposals debates: Engage in debates diff --git a/config/locales/management.es.yml b/config/locales/management.es.yml index 4b3b9ae59..04a7ba352 100644 --- a/config/locales/management.es.yml +++ b/config/locales/management.es.yml @@ -1,6 +1,11 @@ --- es: management: + account: + alert: + unverified_user: Solo se pueden editar cuentas de usuarios verificados + show: + title: Cuenta de usuario account_info: change_user: Cambiar usuario document_number_label: 'Número de documento:' @@ -45,6 +50,7 @@ es: support_spending_proposals: Apoyar propts. de inversión title: Gestión users: Usuarios + edit_user_accounts: Editar cuenta de usuario permissions: create_proposals: Crear nuevas propuestas debates: Participar en debates diff --git a/config/routes.rb b/config/routes.rb index b38823a65..dd4281788 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -220,6 +220,8 @@ Rails.application.routes.draw do end end + resource :account, controller: "account", only: [:show] + get 'sign_in', to: 'sessions#create' resource :session, only: [:create, :destroy] diff --git a/spec/features/management/account_spec.rb b/spec/features/management/account_spec.rb new file mode 100644 index 000000000..3b9951d41 --- /dev/null +++ b/spec/features/management/account_spec.rb @@ -0,0 +1,32 @@ +require 'rails_helper' + +feature 'Account' do + + background do + login_as_manager + end + + scenario "Should not allow unverified users to create spending proposals" do + user = create(:user) + login_managed_user(user) + + click_link "Edit user account" + + expect(page).to have_content "No verified user logged in yet" + end + + scenario 'Delete a user account', :js do + user = create(:user, :level_two) + login_managed_user(user) + + visit management_account_path + + click_link "Delete user" + click_link "Delete account" + + expect(page).to have_content "User account deleted." + + expect(user.reload.erase_reason).to eq "Deleted by manager: JJB042" + end + +end \ No newline at end of file diff --git a/spec/features/management/users_spec.rb b/spec/features/management/users_spec.rb index 83ac9248a..021edaaad 100644 --- a/spec/features/management/users_spec.rb +++ b/spec/features/management/users_spec.rb @@ -1,11 +1,13 @@ require 'rails_helper' -feature 'users' do +feature 'Users' do + + background do + login_as_manager + end scenario 'Create a level 3 user from scratch' do - login_as_manager - visit management_document_verifications_path fill_in 'document_verification_document_number', with: '1234' click_button 'Check' @@ -44,7 +46,6 @@ feature 'users' do scenario 'Delete a level 2 user account from document verification page', :js do level_2_user = create(:user, :level_two, document_number: 13579) - login_as_manager visit management_document_verifications_path fill_in 'document_verification_document_number', with: '13579' From 473cca418dfae958ec1ee55bf5a6f7228aba290b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Fri, 8 Apr 2016 11:47:56 +0200 Subject: [PATCH 100/163] updates management's dashboard index --- app/views/management/dashboard/index.html.erb | 10 +--------- config/locales/management.en.yml | 1 + config/locales/management.es.yml | 1 + 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/app/views/management/dashboard/index.html.erb b/app/views/management/dashboard/index.html.erb index 4145592d8..e32a46d0e 100644 --- a/app/views/management/dashboard/index.html.erb +++ b/app/views/management/dashboard/index.html.erb @@ -1,14 +1,6 @@

    <%= t("management.dashboard.index.title") %>

    -

    Desde aquí puedes gestionar usuarios a través de las siguientes acciones:

    - -

    Usuarios

    - -

    Crear propuesta

    - -

    Apoyar propuesta

    - -

    Imprimir propuestas

    +

    <%= t("management.dashboard.index.info") %>

    diff --git a/config/locales/management.en.yml b/config/locales/management.en.yml index 2c13d4d19..74a58ac26 100644 --- a/config/locales/management.en.yml +++ b/config/locales/management.en.yml @@ -17,6 +17,7 @@ en: dashboard: index: title: Management + info: Here you can manage users through all actions listed in the left menu. document_number: Document number document_type_label: Document type document_verifications: diff --git a/config/locales/management.es.yml b/config/locales/management.es.yml index 04a7ba352..c4545e675 100644 --- a/config/locales/management.es.yml +++ b/config/locales/management.es.yml @@ -17,6 +17,7 @@ es: dashboard: index: title: Gestión + info: Desde aquí puedes gestionar usuarios a través de las acciones listadas en el menú de la izquierda. document_number: Número de documento document_type_label: Tipo de documento document_verifications: From 991b189610b2087c6bf5b6c2605cbecba8dac58a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Fri, 8 Apr 2016 12:16:09 +0200 Subject: [PATCH 101/163] refactors triplicated code --- app/controllers/management/account_controller.rb | 12 +++--------- app/controllers/management/base_controller.rb | 10 ++++++++++ app/controllers/management/proposals_controller.rb | 12 +++--------- .../management/spending_proposals_controller.rb | 12 +++--------- 4 files changed, 19 insertions(+), 27 deletions(-) diff --git a/app/controllers/management/account_controller.rb b/app/controllers/management/account_controller.rb index b3b79a8e9..85b9feea4 100644 --- a/app/controllers/management/account_controller.rb +++ b/app/controllers/management/account_controller.rb @@ -1,19 +1,13 @@ class Management::AccountController < Management::BaseController - before_action :check_verified_user + before_action :only_verified_users def show end private - def check_verified_user - unless current_user.level_two_or_three_verified? - redirect_to management_document_verifications_path, alert: t("management.account.alert.unverified_user") - end - end - - def current_user - managed_user + def only_verified_users + check_verified_user t("management.account.alert.unverified_user") end end diff --git a/app/controllers/management/base_controller.rb b/app/controllers/management/base_controller.rb index bced745b4..f01bbebbc 100644 --- a/app/controllers/management/base_controller.rb +++ b/app/controllers/management/base_controller.rb @@ -20,6 +20,16 @@ class Management::BaseController < ActionController::Base @managed_user ||= Verification::Management::ManagedUser.find(session[:document_type], session[:document_number]) end + def current_user + managed_user + end + + def check_verified_user(alert_msg) + unless current_user.level_two_or_three_verified? + redirect_to management_document_verifications_path, alert: alert_msg + end + end + def set_locale if params[:locale] && I18n.available_locales.include?(params[:locale].to_sym) session[:locale] = params[:locale] diff --git a/app/controllers/management/proposals_controller.rb b/app/controllers/management/proposals_controller.rb index 6e01a8c77..3f4284a06 100644 --- a/app/controllers/management/proposals_controller.rb +++ b/app/controllers/management/proposals_controller.rb @@ -2,7 +2,7 @@ class Management::ProposalsController < Management::BaseController include HasOrders include CommentableActions - before_action :check_verified_user, except: :print + before_action :only_verified_users, except: :print before_action :set_proposal, only: [:vote, :show] before_action :parse_search_terms, only: :index before_action :load_categories, only: [:new, :edit] @@ -40,14 +40,8 @@ class Management::ProposalsController < Management::BaseController Proposal end - def check_verified_user - unless current_user.level_two_or_three_verified? - redirect_to management_document_verifications_path, alert: t("management.proposals.alert.unverified_user") - end - end - - def current_user - managed_user + def only_verified_users + check_verified_user t("management.proposals.alert.unverified_user") end ### Duplicated in application_controller. Move to a concern. diff --git a/app/controllers/management/spending_proposals_controller.rb b/app/controllers/management/spending_proposals_controller.rb index 18d013c57..49378ca63 100644 --- a/app/controllers/management/spending_proposals_controller.rb +++ b/app/controllers/management/spending_proposals_controller.rb @@ -1,6 +1,6 @@ class Management::SpendingProposalsController < Management::BaseController - before_action :check_verified_user, except: :print + before_action :only_verified_users, except: :print before_action :set_spending_proposal, only: [:vote, :show] def index @@ -48,14 +48,8 @@ class Management::SpendingProposalsController < Management::BaseController params.require(:spending_proposal).permit(:title, :description, :external_url, :geozone_id, :terms_of_service, :captcha, :captcha_key) end - def check_verified_user - unless current_user.level_two_or_three_verified? - redirect_to management_document_verifications_path, alert: t("management.spending_proposals.alert.unverified_user") - end - end - - def current_user - managed_user + def only_verified_users + check_verified_user t("management.spending_proposals.alert.unverified_user") end # This should not be necessary. Maybe we could create a specific show view for managers. From 61b2c087b6cd558eeaa2bd916a48e5bd1f62474f Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 8 Apr 2016 17:45:20 +0200 Subject: [PATCH 102/163] changes the responsible_name from username to document_number --- app/models/spending_proposal.rb | 2 +- spec/models/spending_proposal_spec.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/spending_proposal.rb b/app/models/spending_proposal.rb index f4657e9d4..c49b745e1 100644 --- a/app/models/spending_proposal.rb +++ b/app/models/spending_proposal.rb @@ -123,7 +123,7 @@ class SpendingProposal < ActiveRecord::Base end def set_responsible_name - self.responsible_name = author.try(:username) + self.responsible_name = author.try(:document_number) end end diff --git a/spec/models/spending_proposal_spec.rb b/spec/models/spending_proposal_spec.rb index d841abf06..3d32e383b 100644 --- a/spec/models/spending_proposal_spec.rb +++ b/spec/models/spending_proposal_spec.rb @@ -262,10 +262,10 @@ describe SpendingProposal do end describe "responsible_name" do - it "gets updated with the user name" do - u = create(:user, username: "manolo") + it "gets updated with the document_number" do + u = create(:user, document_number: "123456") sp = create(:spending_proposal, author: u) - expect(sp.responsible_name).to eq("manolo") + expect(sp.responsible_name).to eq("123456") end end From 5fec3b9858bf97ec729b94077aca7c90dfcbbb81 Mon Sep 17 00:00:00 2001 From: kikito Date: Mon, 11 Apr 2016 12:21:11 +0200 Subject: [PATCH 103/163] persists responsible name, even if the user is erased --- app/models/spending_proposal.rb | 2 +- spec/models/spending_proposal_spec.rb | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/models/spending_proposal.rb b/app/models/spending_proposal.rb index c49b745e1..69d4d839f 100644 --- a/app/models/spending_proposal.rb +++ b/app/models/spending_proposal.rb @@ -123,7 +123,7 @@ class SpendingProposal < ActiveRecord::Base end def set_responsible_name - self.responsible_name = author.try(:document_number) + self.responsible_name = author.try(:document_number) if author.try(:document_number).present? end end diff --git a/spec/models/spending_proposal_spec.rb b/spec/models/spending_proposal_spec.rb index 3d32e383b..ba18287e6 100644 --- a/spec/models/spending_proposal_spec.rb +++ b/spec/models/spending_proposal_spec.rb @@ -262,10 +262,18 @@ describe SpendingProposal do end describe "responsible_name" do + let(:user) { create(:user, document_number: "123456") } + let!(:spending_proposal) { create(:spending_proposal, author: user) } + it "gets updated with the document_number" do - u = create(:user, document_number: "123456") - sp = create(:spending_proposal, author: u) - expect(sp.responsible_name).to eq("123456") + expect(spending_proposal.responsible_name).to eq("123456") + end + + it "does not get updated if the user is erased" do + user.erase + expect(user.document_number).to be_blank + spending_proposal.touch + expect(spending_proposal.responsible_name).to eq("123456") end end From 3087b2dac9fadda4085c23b5def49cfe10020924 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Mon, 11 Apr 2016 16:12:03 +0200 Subject: [PATCH 104/163] changes default order in valuation/sps to votes up --- .../valuation/spending_proposals_controller.rb | 3 +-- db/schema.rb | 10 +++++----- .../features/valuation/spending_proposals_spec.rb | 15 +++++++++++++++ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/app/controllers/valuation/spending_proposals_controller.rb b/app/controllers/valuation/spending_proposals_controller.rb index 83d76e0a0..d3bc585b1 100644 --- a/app/controllers/valuation/spending_proposals_controller.rb +++ b/app/controllers/valuation/spending_proposals_controller.rb @@ -11,7 +11,7 @@ class Valuation::SpendingProposalsController < Valuation::BaseController def index @geozone_filters = geozone_filters if current_user.valuator? - @spending_proposals = SpendingProposal.scoped_filter(params_for_current_valuator, @current_filter).order(created_at: :desc).page(params[:page]) + @spending_proposals = SpendingProposal.scoped_filter(params_for_current_valuator, @current_filter).order(cached_votes_up: :desc).page(params[:page]) else @spending_proposals = SpendingProposal.none.page(params[:page]) end @@ -33,7 +33,6 @@ class Valuation::SpendingProposalsController < Valuation::BaseController private def geozone_filters - spending_proposals = SpendingProposal.by_valuator(current_user.valuator.try(:id)).valuation_open.all.to_a [ { name: t('valuation.spending_proposals.index.geozone_filter_all'), diff --git a/db/schema.rb b/db/schema.rb index 4183e0246..e86f4db3b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -296,8 +296,8 @@ ActiveRecord::Schema.define(version: 20160406163649) do t.text "description" t.integer "author_id" t.string "external_url" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.integer "geozone_id" t.integer "price", limit: 8 t.boolean "feasible" @@ -305,14 +305,14 @@ ActiveRecord::Schema.define(version: 20160406163649) do t.text "price_explanation" t.text "feasible_explanation" t.text "internal_comments" - t.boolean "valuation_finished", default: false + t.boolean "valuation_finished", default: false t.text "explanations_log" t.integer "administrator_id" - t.integer "valuation_assignments_count", default: 0 + t.integer "valuation_assignments_count", default: 0 t.integer "price_first_year", limit: 8 t.string "time_scope" t.datetime "unfeasible_email_sent_at" - t.integer "cached_votes_up", default: 0 + t.integer "cached_votes_up", default: 0 t.tsvector "tsv" t.string "responsible_name", limit: 60 end diff --git a/spec/features/valuation/spending_proposals_spec.rb b/spec/features/valuation/spending_proposals_spec.rb index 6cb1acf1a..98037607c 100644 --- a/spec/features/valuation/spending_proposals_spec.rb +++ b/spec/features/valuation/spending_proposals_spec.rb @@ -37,6 +37,21 @@ feature 'Valuation spending proposals' do expect(page).to_not have_content(spending_proposal2.title) end + scenario 'Index orders spending proposals by votes' do + spending_proposal10 = create(:spending_proposal, cached_votes_up: 10) + spending_proposal100 = create(:spending_proposal, cached_votes_up: 100) + spending_proposal1 = create(:spending_proposal, cached_votes_up: 1) + + spending_proposal1.valuators << @valuator + spending_proposal10.valuators << @valuator + spending_proposal100.valuators << @valuator + + visit valuation_spending_proposals_path + + expect(spending_proposal100.title).to appear_before(spending_proposal10.title) + expect(spending_proposal10.title).to appear_before(spending_proposal1.title) + end + scenario 'Index shows assignments info' do spending_proposal1 = create(:spending_proposal) spending_proposal2 = create(:spending_proposal) From 3b754fd998741b230a9ac5e686178dcf86aaf219 Mon Sep 17 00:00:00 2001 From: kikito Date: Mon, 11 Apr 2016 18:28:28 +0200 Subject: [PATCH 105/163] Adds two new fields to user --- db/migrate/20160411161531_add_genre_and_dob_to_users.rb | 6 ++++++ db/schema.rb | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20160411161531_add_genre_and_dob_to_users.rb diff --git a/db/migrate/20160411161531_add_genre_and_dob_to_users.rb b/db/migrate/20160411161531_add_genre_and_dob_to_users.rb new file mode 100644 index 000000000..aa8100fa3 --- /dev/null +++ b/db/migrate/20160411161531_add_genre_and_dob_to_users.rb @@ -0,0 +1,6 @@ +class AddGenreAndDobToUsers < ActiveRecord::Migration + def change + add_column :users, :genre, :string, index: true, limit: 10 + add_column :users, :date_of_birth, :datetime, index: true + end +end diff --git a/db/schema.rb b/db/schema.rb index e86f4db3b..cd05a0d2f 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: 20160406163649) do +ActiveRecord::Schema.define(version: 20160411161531) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -422,6 +422,8 @@ ActiveRecord::Schema.define(version: 20160406163649) do t.string "oauth_email" t.integer "geozone_id" t.string "redeemable_code" + t.string "genre", limit: 10 + t.datetime "date_of_birth" end add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree From 9cc831bbc10873e8fc2e9384a5694f79d2b80082 Mon Sep 17 00:00:00 2001 From: kikito Date: Mon, 11 Apr 2016 18:41:33 +0200 Subject: [PATCH 106/163] adds genre to the census api response --- lib/census_api.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/census_api.rb b/lib/census_api.rb index 737f7f873..9bcde62be 100644 --- a/lib/census_api.rb +++ b/lib/census_api.rb @@ -49,6 +49,10 @@ class CensusApi data[:datos_vivienda][:item][:codigo_distrito] end + def genre # "Varón" or "Mujer" + data[:datos_habitante][:item][:descripcion_sexo] + end + private def data @@ -86,7 +90,7 @@ class CensusApi end def stubbed_response_body - {:get_habita_datos_response=>{:get_habita_datos_return=>{:hay_errores=>false, :datos_habitante=>{:item=>{:fecha_nacimiento_string=>"31-12-1980", :identificador_documento=>"12345678Z", }}, :datos_vivienda=>{:item=>{:codigo_postal=>"28013", :codigo_distrito=>"01"}}}}} + {get_habita_datos_response: {get_habita_datos_return: {hay_errores: false, datos_habitante: { item: {fecha_nacimiento_string: "31-12-1980", identificador_documento: "12345678Z", description_sexo: "Varón" }}, datos_vivienda: {item: {codigo_postal: "28013", codigo_distrito: "01"}}}}} end def is_dni?(document_type) From 622909703217b15b20f359319fcf6acf1d8ded91 Mon Sep 17 00:00:00 2001 From: kikito Date: Tue, 12 Apr 2016 13:38:01 +0200 Subject: [PATCH 107/163] Fixes typo --- lib/census_api.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/census_api.rb b/lib/census_api.rb index 9bcde62be..c53e703fb 100644 --- a/lib/census_api.rb +++ b/lib/census_api.rb @@ -90,7 +90,7 @@ class CensusApi end def stubbed_response_body - {get_habita_datos_response: {get_habita_datos_return: {hay_errores: false, datos_habitante: { item: {fecha_nacimiento_string: "31-12-1980", identificador_documento: "12345678Z", description_sexo: "Varón" }}, datos_vivienda: {item: {codigo_postal: "28013", codigo_distrito: "01"}}}}} + {get_habita_datos_response: {get_habita_datos_return: {hay_errores: false, datos_habitante: { item: {fecha_nacimiento_string: "31-12-1980", identificador_documento: "12345678Z", descripcion_sexo: "Varón" }}, datos_vivienda: {item: {codigo_postal: "28013", codigo_distrito: "01"}}}}} end def is_dni?(document_type) From 2c51115d6d7a31742a468a8908e612d7efde04c9 Mon Sep 17 00:00:00 2001 From: kikito Date: Tue, 12 Apr 2016 13:38:39 +0200 Subject: [PATCH 108/163] Residence Verification now fills up the date of birth and genre --- app/models/verification/residence.rb | 11 +++++++++++ spec/models/residence_spec.rb | 6 +++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/models/verification/residence.rb b/app/models/verification/residence.rb index 0c1ed5f9a..1f5ce4bfd 100644 --- a/app/models/verification/residence.rb +++ b/app/models/verification/residence.rb @@ -31,6 +31,8 @@ class Verification::Residence user.update(document_number: document_number, document_type: document_type, geozone: self.geozone, + date_of_birth: date_of_birth.to_datetime, + genre: genre, residence_verified_at: Time.now) end @@ -75,6 +77,15 @@ class Verification::Residence @census_api_response.district_code end + def genre + case @census_api_response.genre + when "Varón" + "male" + when "Mujer" + "female" + end + end + private def call_census_api diff --git a/spec/models/residence_spec.rb b/spec/models/residence_spec.rb index fbc33d39c..faa81b5c3 100644 --- a/spec/models/residence_spec.rb +++ b/spec/models/residence_spec.rb @@ -85,7 +85,7 @@ describe Verification::Residence do describe "save" do - it "should store document number, document type, and geozone" do + it "should store document number, document type, geozone, date of birth and genre" do user = create(:user) residence.user = user residence.save @@ -93,6 +93,10 @@ describe Verification::Residence do user.reload expect(user.document_number).to eq('12345678Z') expect(user.document_type).to eq("1") + expect(user.date_of_birth.year).to eq(1980) + expect(user.date_of_birth.month).to eq(12) + expect(user.date_of_birth.day).to eq(31) + expect(user.genre).to eq('male') expect(user.geozone).to eq(geozone) end From 0ae97eada8b1401fd2e6b33e9f5c85cd369bcfc0 Mon Sep 17 00:00:00 2001 From: kikito Date: Tue, 12 Apr 2016 17:06:50 +0200 Subject: [PATCH 109/163] adds rake task to assign demographic info to users --- lib/tasks/users.rake | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/tasks/users.rake b/lib/tasks/users.rake index 0ce4cdfee..50f96e592 100644 --- a/lib/tasks/users.rake +++ b/lib/tasks/users.rake @@ -40,5 +40,23 @@ namespace :users do end end + desc "Associates demographic information to users" + task assign_demographic: :environment do + User.residence_verified.where(genre: nil).find_each do |u| + begin + response = CensusApi.new.call(u.document_type, u.document_number) + if response.valid? + u.genre = response.genre == 'Varón' ? 'male' : 'female' + u.date_of_birth = response.date_of_birth.to_datetime + u.save + print "." + else + print "X" + end + rescue + puts "Could not assign genre/dob for user: #{u.id}" + end + end + end end From bcc687d9479426ad4068fb544baf53c5b2bd5b3b Mon Sep 17 00:00:00 2001 From: rgarcia Date: Tue, 12 Apr 2016 17:17:02 +0200 Subject: [PATCH 110/163] adds filtering of spending proposals by valuator --- .../admin/spending_proposals/index.html.erb | 9 ++++ config/locales/admin.en.yml | 1 + config/locales/admin.es.yml | 1 + .../features/admin/spending_proposals_spec.rb | 46 +++++++++++++++++++ 4 files changed, 57 insertions(+) diff --git a/app/views/admin/spending_proposals/index.html.erb b/app/views/admin/spending_proposals/index.html.erb index f50dea628..a4a1a68c6 100644 --- a/app/views/admin/spending_proposals/index.html.erb +++ b/app/views/admin/spending_proposals/index.html.erb @@ -9,6 +9,15 @@ label: false, class: "js-submit-on-change" } %>
  • + +
    + <%= select_tag :valuator_id, + options_for_select(valuator_select_options, params[:valuator_id]), + { prompt: t("admin.spending_proposals.index.valuator_filter_all"), + label: false, + class: "js-submit-on-change" } %> +
    +
    <%= select_tag :geozone_id, options_for_select(geozone_select_options.unshift([t("geozones.none"), "all"]), params[:geozone_id]), diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml index 33d3c8434..3c4c2f24e 100755 --- a/config/locales/admin.en.yml +++ b/config/locales/admin.en.yml @@ -155,6 +155,7 @@ en: index: geozone_filter_all: All zones administrator_filter_all: All administrators + valuator_filter_all: All valuators tags_filter_all: All tags filters: valuation_open: Open diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml index ec0fa5483..5d7017336 100644 --- a/config/locales/admin.es.yml +++ b/config/locales/admin.es.yml @@ -155,6 +155,7 @@ es: index: geozone_filter_all: Todos los ámbitos de actuación administrator_filter_all: Todos los administradores + valuator_filter_all: Todos los evaluadores tags_filter_all: Todas las etiquetas filters: valuation_open: Abiertas diff --git a/spec/features/admin/spending_proposals_spec.rb b/spec/features/admin/spending_proposals_spec.rb index fcfec8638..a14ff0316 100644 --- a/spec/features/admin/spending_proposals_spec.rb +++ b/spec/features/admin/spending_proposals_spec.rb @@ -143,6 +143,52 @@ feature 'Admin spending proposals' do end + scenario "Filtering by valuator", :js do + user = create(:user, username: 'Valuator 1') + valuator = create(:valuator, user: user) + + spending_proposal = create(:spending_proposal, title: "Realocate visitors") + spending_proposal.valuators << valuator + + create(:spending_proposal, title: "Destroy the city") + + visit admin_spending_proposals_path + expect(page).to have_link("Realocate visitors") + expect(page).to have_link("Destroy the city") + + select "Valuator 1", from: "valuator_id" + + expect(page).to have_content('There is 1 spending proposal') + expect(page).to_not have_link("Destroy the city") + expect(page).to have_link("Realocate visitors") + + select "All valuators", from: "valuator_id" + + expect(page).to have_content('There are 2 spending proposals') + expect(page).to have_link("Destroy the city") + expect(page).to have_link("Realocate visitors") + + select "Valuator 1", from: "valuator_id" + expect(page).to have_content('There is 1 spending proposal') + click_link("Realocate visitors") + click_link("Back") + + expect(page).to have_content('There is 1 spending proposal') + expect(page).to_not have_link("Destroy the city") + expect(page).to have_link("Realocate visitors") + + click_link("Realocate visitors") + click_on("Edit classification") + expect(page).to have_button("Update") + click_on("Back") + expect(page).to_not have_button("Update") + click_on("Back") + + expect(page).to have_content('There is 1 spending proposal') + expect(page).to_not have_link("Destroy the city") + expect(page).to have_link("Realocate visitors") + end + scenario "Current filter is properly highlighted" do filters_links = {'valuation_open' => 'Open', 'without_admin' => 'Without assigned admin', From eb78f01fb209a14a9c77c2858dcefb1f962ef814 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Tue, 12 Apr 2016 17:21:50 +0200 Subject: [PATCH 111/163] improves valuator select layout --- app/views/admin/spending_proposals/index.html.erb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/admin/spending_proposals/index.html.erb b/app/views/admin/spending_proposals/index.html.erb index a4a1a68c6..1ad804c51 100644 --- a/app/views/admin/spending_proposals/index.html.erb +++ b/app/views/admin/spending_proposals/index.html.erb @@ -2,7 +2,7 @@
    <%= form_tag admin_spending_proposals_path, method: :get, enforce_utf8: false do %> -
    +
    <%= select_tag :administrator_id, options_for_select(admin_select_options, params[:administrator_id]), { prompt: t("admin.spending_proposals.index.administrator_filter_all"), @@ -10,7 +10,7 @@ class: "js-submit-on-change" } %>
    -
    +
    <%= select_tag :valuator_id, options_for_select(valuator_select_options, params[:valuator_id]), { prompt: t("admin.spending_proposals.index.valuator_filter_all"), @@ -18,14 +18,14 @@ class: "js-submit-on-change" } %>
    -
    +
    <%= select_tag :geozone_id, options_for_select(geozone_select_options.unshift([t("geozones.none"), "all"]), params[:geozone_id]), { prompt: t("admin.spending_proposals.index.geozone_filter_all"), label: false, class: "js-submit-on-change" } %>
    -
    +
    <%= select_tag :tag_name, options_for_select(spending_proposal_tags_select_options, params[:tag_name]), { prompt: t("admin.spending_proposals.index.tags_filter_all"), From 4f724ef3bfcc299082113d19755fb09657df0f3e Mon Sep 17 00:00:00 2001 From: kikito Date: Tue, 12 Apr 2016 18:18:25 +0200 Subject: [PATCH 112/163] Modifies census_api to parse genre and dob --- lib/census_api.rb | 12 ++++++++++-- spec/lib/census_api_spec.rb | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/census_api.rb b/lib/census_api.rb index c53e703fb..2b8c7d7a2 100644 --- a/lib/census_api.rb +++ b/lib/census_api.rb @@ -38,7 +38,10 @@ class CensusApi end def date_of_birth - data[:datos_habitante][:item][:fecha_nacimiento_string] + str = data[:datos_habitante][:item][:fecha_nacimiento_string] + day, month, year = str.match(/(\d\d?)\D(\d\d?)\D(\d\d\d?\d?)/)[1..3] + return nil unless day.present? && month.present? && year.present? + Date.new(year.to_i, month.to_i, day.to_i) end def postal_code @@ -50,7 +53,12 @@ class CensusApi end def genre # "Varón" or "Mujer" - data[:datos_habitante][:item][:descripcion_sexo] + case data[:datos_habitante][:item][:descripcion_sexo] + when "Varón" + "male" + when "Mujer" + "female" + end end private diff --git a/spec/lib/census_api_spec.rb b/spec/lib/census_api_spec.rb index a49133d23..fb14f39c5 100644 --- a/spec/lib/census_api_spec.rb +++ b/spec/lib/census_api_spec.rb @@ -29,7 +29,7 @@ describe CensusApi do describe '#call' do let(:invalid_body) { {get_habita_datos_response: {get_habita_datos_return: {datos_habitante: {}}}} } - let(:valid_body){ {get_habita_datos_response: {get_habita_datos_return: {datos_habitante: {item: {fecha_nacimiento_string: "1/1/1980"}}}}} } + let(:valid_body){ {get_habita_datos_response: {get_habita_datos_return: {datos_habitante: {item: {fecha_nacimiento_string: "1-1-1980"}}}}} } it "returns the response for the first valid variant" do allow(api).to receive(:get_response_body).with(1, "00123456").and_return(invalid_body) @@ -39,7 +39,7 @@ describe CensusApi do response = api.call(1, "123456") expect(response).to be_valid - expect(response.date_of_birth).to eq('1/1/1980') + expect(response.date_of_birth).to eq(Date.new(1980,1,1)) end it "returns the last failed response" do From 7987a3410b6a1c3249cfc4af2657b3a7a875bb5e Mon Sep 17 00:00:00 2001 From: kikito Date: Tue, 12 Apr 2016 18:19:05 +0200 Subject: [PATCH 113/163] Updates residence to handle CensusAPI's new response --- app/models/verification/residence.rb | 9 ++------- lib/active_model/dates.rb | 6 +----- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/app/models/verification/residence.rb b/app/models/verification/residence.rb index 1f5ce4bfd..661659a01 100644 --- a/app/models/verification/residence.rb +++ b/app/models/verification/residence.rb @@ -78,12 +78,7 @@ class Verification::Residence end def genre - case @census_api_response.genre - when "Varón" - "male" - when "Mujer" - "female" - end + @census_api_response.genre end private @@ -95,7 +90,7 @@ class Verification::Residence def residency_valid? @census_api_response.valid? && @census_api_response.postal_code == postal_code && - @census_api_response.date_of_birth == date_to_string(date_of_birth) + @census_api_response.date_of_birth == date_of_birth end def clean_document_number diff --git a/lib/active_model/dates.rb b/lib/active_model/dates.rb index a519e3840..5dd8e971c 100644 --- a/lib/active_model/dates.rb +++ b/lib/active_model/dates.rb @@ -13,13 +13,9 @@ module ActiveModel::Dates attrs.except("#{field}(1i)", "#{field}(2i)", "#{field}(3i)") end - def date_to_string(date) - date.strftime("%d-%m-%Y") - end - def string_to_date(value) day, month, year = value.split("-") Date.new(year.to_i, month.to_i, day.to_i) end -end \ No newline at end of file +end From 708b77721c06cc667580b1b6841f830bd86fa997 Mon Sep 17 00:00:00 2001 From: kikito Date: Tue, 12 Apr 2016 18:22:38 +0200 Subject: [PATCH 114/163] aligns rake task with Census API response --- lib/tasks/users.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/users.rake b/lib/tasks/users.rake index 50f96e592..18dad53bc 100644 --- a/lib/tasks/users.rake +++ b/lib/tasks/users.rake @@ -46,7 +46,7 @@ namespace :users do begin response = CensusApi.new.call(u.document_type, u.document_number) if response.valid? - u.genre = response.genre == 'Varón' ? 'male' : 'female' + u.genre = response.genre u.date_of_birth = response.date_of_birth.to_datetime u.save print "." From 3880ef9e24f9e136f4e6e430d098dcfea1873d7d Mon Sep 17 00:00:00 2001 From: kikito Date: Tue, 12 Apr 2016 18:35:23 +0200 Subject: [PATCH 115/163] aligns document verification with census API --- app/models/verification/management/document.rb | 4 ++-- lib/active_model/dates.rb | 5 ----- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/app/models/verification/management/document.rb b/app/models/verification/management/document.rb index ee9e5462d..481073397 100644 --- a/app/models/verification/management/document.rb +++ b/app/models/verification/management/document.rb @@ -32,7 +32,7 @@ class Verification::Management::Document end def under_sixteen?(response) - 16.years.ago < string_to_date(response.date_of_birth) + 16.years.ago < response.date_of_birth end def verified? @@ -43,4 +43,4 @@ class Verification::Management::Document user.update(verified_at: Time.now) if user? end -end \ No newline at end of file +end diff --git a/lib/active_model/dates.rb b/lib/active_model/dates.rb index 5dd8e971c..f9605ddbd 100644 --- a/lib/active_model/dates.rb +++ b/lib/active_model/dates.rb @@ -13,9 +13,4 @@ module ActiveModel::Dates attrs.except("#{field}(1i)", "#{field}(2i)", "#{field}(3i)") end - def string_to_date(value) - day, month, year = value.split("-") - Date.new(year.to_i, month.to_i, day.to_i) - end - end From 20c403e37b59dfc94857ef62ddd905ac34204c64 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Tue, 12 Apr 2016 18:39:14 +0200 Subject: [PATCH 116/163] uses valuator description in select --- app/helpers/valuation_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/helpers/valuation_helper.rb b/app/helpers/valuation_helper.rb index 9e3a054c1..1d74e94fa 100644 --- a/app/helpers/valuation_helper.rb +++ b/app/helpers/valuation_helper.rb @@ -2,9 +2,9 @@ module ValuationHelper def valuator_select_options(valuator=nil) if valuator.present? - Valuator.where.not(id: valuator.id).order('users.username asc').includes(:user).collect { |v| [ v.name, v.id ] }.prepend([valuator.name, valuator.id]) + Valuator.where.not(id: valuator.id).order('users.username asc').includes(:user).collect { |v| [ v.description_or_email, v.id ] }.prepend([valuator.description_or_email, valuator.id]) else - Valuator.all.order('users.username asc').includes(:user).collect { |v| [ v.name, v.id ] } + Valuator.all.order('users.username asc').includes(:user).collect { |v| [ v.description_or_email, v.id ] } end end From efc81158991c9164cba7c41dd4f4c185e3190e7c Mon Sep 17 00:00:00 2001 From: rgarcia Date: Tue, 12 Apr 2016 18:49:48 +0200 Subject: [PATCH 117/163] fixes specs --- spec/features/admin/spending_proposals_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/features/admin/spending_proposals_spec.rb b/spec/features/admin/spending_proposals_spec.rb index a14ff0316..16a140de6 100644 --- a/spec/features/admin/spending_proposals_spec.rb +++ b/spec/features/admin/spending_proposals_spec.rb @@ -144,8 +144,8 @@ feature 'Admin spending proposals' do end scenario "Filtering by valuator", :js do - user = create(:user, username: 'Valuator 1') - valuator = create(:valuator, user: user) + user = create(:user) + valuator = create(:valuator, user: user, description: 'Valuator 1') spending_proposal = create(:spending_proposal, title: "Realocate visitors") spending_proposal.valuators << valuator From 5f60376c1dc7788a83a659f2d02ea1bbc3dc943c Mon Sep 17 00:00:00 2001 From: rgarcia Date: Tue, 12 Apr 2016 19:12:28 +0200 Subject: [PATCH 118/163] changes order in valuator select --- app/helpers/valuation_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/helpers/valuation_helper.rb b/app/helpers/valuation_helper.rb index 1d74e94fa..0983ea567 100644 --- a/app/helpers/valuation_helper.rb +++ b/app/helpers/valuation_helper.rb @@ -2,9 +2,9 @@ module ValuationHelper def valuator_select_options(valuator=nil) if valuator.present? - Valuator.where.not(id: valuator.id).order('users.username asc').includes(:user).collect { |v| [ v.description_or_email, v.id ] }.prepend([valuator.description_or_email, valuator.id]) + Valuator.where.not(id: valuator.id).order("description ASC").order("users.email ASC").includes(:user).collect { |v| [ v.description_or_email, v.id ] }.prepend([valuator.description_or_email, valuator.id]) else - Valuator.all.order('users.username asc').includes(:user).collect { |v| [ v.description_or_email, v.id ] } + Valuator.all.order("description ASC").order("users.email ASC").includes(:user).collect { |v| [ v.description_or_email, v.id ] } end end From 3a5928e83f6fa23dbb30432dba32be76c695476b Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 13 Apr 2016 12:06:43 +0200 Subject: [PATCH 119/163] aligns document verification with Madrid --- app/models/verification/management/document.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/verification/management/document.rb b/app/models/verification/management/document.rb index 481073397..fcbc19ca4 100644 --- a/app/models/verification/management/document.rb +++ b/app/models/verification/management/document.rb @@ -32,7 +32,7 @@ class Verification::Management::Document end def under_sixteen?(response) - 16.years.ago < response.date_of_birth + 16.years.ago.beginning_of_day < response.date_of_birth.beginning_of_day end def verified? From d7f9862290aa47b267432dba07aae850dd2d2126 Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 13 Apr 2016 12:06:50 +0200 Subject: [PATCH 120/163] fixes failing specs --- .../verification/management/document_spec.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/spec/models/verification/management/document_spec.rb b/spec/models/verification/management/document_spec.rb index b4140f7ed..35fd89855 100644 --- a/spec/models/verification/management/document_spec.rb +++ b/spec/models/verification/management/document_spec.rb @@ -3,35 +3,35 @@ require 'rails_helper' describe Verification::Management::Document do describe "#valid_age?" do it "returns false when the user is younger than sixteen years old" do - census_response = double(date_of_birth: "31-12-#{16.years.ago.year}") + census_response = double(date_of_birth: Date.new(16.years.ago.year, 12, 31)) expect(Verification::Management::Document.new.valid_age?(census_response)).to be false end it "returns true when the user is sixteen years old" do - census_response = double(date_of_birth: 16.years.ago.strftime("%d-%m-%Y")) + census_response = double(date_of_birth: Date.new(16.years.ago.year, 16.years.ago.month, 16.years.ago.day)) expect(Verification::Management::Document.new.valid_age?(census_response)).to be true end it "returns true when the user is older than sixteen years old" do - census_response = double(date_of_birth: "31-12-#{33.years.ago.year}") + census_response = double(date_of_birth: Date.new(33.years.ago.year, 12, 31)) expect(Verification::Management::Document.new.valid_age?(census_response)).to be true end end describe "#under_sixteen?" do it "returns true when the user is younger than sixteen years old" do - census_response = double(date_of_birth: "31-12-#{16.years.ago.year}") + census_response = double(date_of_birth: Date.new(16.years.ago.year, 12, 31)) expect(Verification::Management::Document.new.under_sixteen?(census_response)).to be true end it "returns false when the user is sixteen years old" do - census_response = double(date_of_birth: 16.years.ago.strftime("%d-%m-%Y")) + census_response = double(date_of_birth: Date.new(16.years.ago.year, 16.years.ago.month, 16.years.ago.day)) expect(Verification::Management::Document.new.under_sixteen?(census_response)).to be false end it "returns false when the user is older than sixteen years old" do - census_response = double(date_of_birth: "31-12-#{33.years.ago.year}") + census_response = double(date_of_birth: Date.new(33.years.ago.year, 12, 31)) expect(Verification::Management::Document.new.under_sixteen?(census_response)).to be false end end -end \ No newline at end of file +end From b0b810d4843d752c5954ecce3e8fb9dc1ba7b1df Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 13 Apr 2016 13:32:24 +0200 Subject: [PATCH 121/163] Adds a spec so that admins can edit Spending Proposal regular fields --- spec/features/admin/spending_proposals_spec.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/spec/features/admin/spending_proposals_spec.rb b/spec/features/admin/spending_proposals_spec.rb index 16a140de6..144ff9b31 100644 --- a/spec/features/admin/spending_proposals_spec.rb +++ b/spec/features/admin/spending_proposals_spec.rb @@ -330,6 +330,24 @@ feature 'Admin spending proposals' do context "Edit" do + scenario "Change title, description or geozone" do + spending_proposal = create(:spending_proposal) + create(:geozone, name: "Barbate") + + visit admin_spending_proposal_path(spending_proposal) + click_link 'Edit' + + fill_in 'spending_proposal_title', with: 'Potatoes' + fill_in 'spending_proposal_description', with: 'Carrots' + select 'Barbate', from: 'spending_proposal[geozone_id]' + + click_button 'Update' + + expect(page).to have_content 'Potatoes' + expect(page).to have_content 'Carrots' + expect(page).to have_content 'Barbate' + end + scenario "Add administrator" do spending_proposal = create(:spending_proposal) administrator = create(:administrator, user: create(:user, username: 'Marta', email: 'marta@admins.org')) From d794c1b79d706a35600a80b21091a4072253adc0 Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 13 Apr 2016 13:54:57 +0200 Subject: [PATCH 122/163] Adds fields to admin/spendingproposals/edit view & controller --- .../admin/spending_proposals_controller.rb | 2 +- .../admin/spending_proposals/edit.html.erb | 74 +++++++++++++------ 2 files changed, 52 insertions(+), 24 deletions(-) diff --git a/app/controllers/admin/spending_proposals_controller.rb b/app/controllers/admin/spending_proposals_controller.rb index 61f9aa78d..9b2b86875 100644 --- a/app/controllers/admin/spending_proposals_controller.rb +++ b/app/controllers/admin/spending_proposals_controller.rb @@ -33,7 +33,7 @@ class Admin::SpendingProposalsController < Admin::BaseController private def spending_proposal_params - params.require(:spending_proposal).permit(:administrator_id, :tag_list, valuator_ids: []) + params.require(:spending_proposal).permit(:title, :description, :external_url, :geozone_id, :association_name, :administrator_id, :tag_list, valuator_ids: []) end end diff --git a/app/views/admin/spending_proposals/edit.html.erb b/app/views/admin/spending_proposals/edit.html.erb index 59180eb16..1fd86da59 100644 --- a/app/views/admin/spending_proposals/edit.html.erb +++ b/app/views/admin/spending_proposals/edit.html.erb @@ -2,43 +2,71 @@ <%= t("admin.spending_proposals.show.back") %> <% end %> -<%= render 'written_by_author' %> - -

    <%= t("admin.spending_proposals.edit.classification") %>

    - <%= form_for @spending_proposal, url: admin_spending_proposal_path(@spending_proposal) do |f| %> <% SpendingProposal.filter_params(params).each do |filter_name, filter_value| %> - <%= hidden_field_tag filter_name, filter_value %> + <%= hidden_field_tag filter_name, filter_value %> <% end %> - <%= f.select(:administrator_id, - @admins.collect{ |a| [a.name_and_email, a.id ] }, - { include_blank: t("admin.spending_proposals.edit.undefined") }, - class: "small-12 medium-6") %> +
    +
    + <%= f.text_field :title, maxlength: SpendingProposal.title_max_length %> +
    - <%= f.label :tag_list, t("admin.spending_proposals.edit.tags") %> -
    - <% @tags.each do |tag| %> - <%= tag.name %> - <% end %> +
    + <%= f.cktext_area :description, maxlength: SpendingProposal.description_max_length, ckeditor: { language: I18n.locale } %> +
    + +
    + <%= f.text_field :external_url %> +
    + +
    + <%= f.select :geozone_id, geozone_select_options, include_blank: t("geozones.none") %> +
    + +
    + <%= f.text_field :association_name, placeholder: t("spending_proposals.form.association_name") %> +
    - <%= f.text_field :tag_list, value: @spending_proposal.tag_list.to_s, - label: false, - placeholder: t("admin.spending_proposals.edit.tags_placeholder"), - class: 'js-tag-list' %> - <%= f.label :valuator_ids, t("admin.spending_proposals.edit.assigned_valuators") %> +

    <%= t("admin.spending_proposals.edit.classification") %>

    - <%= f.collection_check_boxes :valuator_ids, @valuators, :id, :email do |b| %> - <%= b.label(title: valuator_label(b.object)) { b.check_box + truncate(b.object.description_or_email, length: 60) } %> - <% end %> +
    + +
    + <%= f.select(:administrator_id, + @admins.collect{ |a| [a.name_and_email, a.id ] }, + { include_blank: t("admin.spending_proposals.edit.undefined") }) %> +
    + + +
    + <%= f.label :tag_list, t("admin.spending_proposals.edit.tags") %> +
    + <% @tags.each do |tag| %> + <%= tag.name %> + <% end %> +
    + <%= f.text_field :tag_list, value: @spending_proposal.tag_list.to_s, + label: false, + placeholder: t("admin.spending_proposals.edit.tags_placeholder"), + class: 'js-tag-list' %> +
    + +
    + <%= f.label :valuator_ids, t("admin.spending_proposals.edit.assigned_valuators") %> + + <%= f.collection_check_boxes :valuator_ids, @valuators, :id, :email do |b| %> + <%= b.label(title: valuator_label(b.object)) { b.check_box + truncate(b.object.description_or_email, length: 60) } %> + <% end %> +
    +

    <%= f.submit(class: "button", value: t("admin.spending_proposals.edit.submit_button")) %>

    - <% end %>
    From c2b205da892672ae8dcd2cf9198d4742c2b4e85c Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 13 Apr 2016 13:55:29 +0200 Subject: [PATCH 123/163] Makes redirect in spending proposal go back to the full page after editing --- app/controllers/admin/spending_proposals_controller.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/controllers/admin/spending_proposals_controller.rb b/app/controllers/admin/spending_proposals_controller.rb index 9b2b86875..e7d1cc45c 100644 --- a/app/controllers/admin/spending_proposals_controller.rb +++ b/app/controllers/admin/spending_proposals_controller.rb @@ -21,10 +21,8 @@ class Admin::SpendingProposalsController < Admin::BaseController def update if @spending_proposal.update(spending_proposal_params) - path = admin_spending_proposal_path( @spending_proposal, - { anchor: 'classification' }.merge(SpendingProposal.filter_params(params))) - - redirect_to path, notice: t("flash.actions.update.spending_proposal") + redirect_to admin_spending_proposal_path(@spending_proposal, SpendingProposal.filter_params(params)), + notice: t("flash.actions.update.spending_proposal") else render :edit end From 64ec5290b9895e5f7b54bdb5c1750cc20ee729ae Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 13 Apr 2016 13:55:59 +0200 Subject: [PATCH 124/163] Adds a new edit link to spending proposals/show and moves the others down --- .../admin/spending_proposals/show.html.erb | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/app/views/admin/spending_proposals/show.html.erb b/app/views/admin/spending_proposals/show.html.erb index bbcf4b4fc..c54816071 100644 --- a/app/views/admin/spending_proposals/show.html.erb +++ b/app/views/admin/spending_proposals/show.html.erb @@ -4,13 +4,13 @@ <%= render 'written_by_author' %> -

    <%= t("admin.spending_proposals.show.classification") %>

    +<%= link_to t("admin.spending_proposals.show.edit"), + edit_admin_spending_proposal_path(@spending_proposal, + SpendingProposal.filter_params(params)) %> -

    - <%= link_to t("admin.spending_proposals.show.edit_classification"), - edit_admin_spending_proposal_path(@spending_proposal, - {anchor: 'form'}.merge(SpendingProposal.filter_params(params))) %> -

    +
    + +

    <%= t("admin.spending_proposals.show.classification") %>

    <%= t("admin.spending_proposals.show.assigned_admin") %>: <%= @spending_proposal.administrator.try(:name_and_email) || t("admin.spending_proposals.show.undefined") %> @@ -31,12 +31,19 @@ <% end %>

    +

    + <%= link_to t("admin.spending_proposals.show.edit_classification"), + edit_admin_spending_proposal_path(@spending_proposal, + {anchor: 'classification'}.merge(SpendingProposal.filter_params(params))) %> +

    +

    <%= t("admin.spending_proposals.show.dossier") %>

    +<%= render 'valuation/spending_proposals/written_by_valuators' %> +

    <%= link_to t("admin.spending_proposals.show.edit_dossier"), edit_valuation_spending_proposal_path(@spending_proposal) %>

    -<%= render 'valuation/spending_proposals/written_by_valuators' %> From 2e0eaa80ca564275328f5a742c72857681e4d389 Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 13 Apr 2016 13:56:15 +0200 Subject: [PATCH 125/163] i18n --- config/locales/activerecord.en.yml | 7 ++++++- config/locales/activerecord.es.yml | 5 +++++ config/locales/admin.en.yml | 3 ++- config/locales/admin.es.yml | 1 + 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/config/locales/activerecord.en.yml b/config/locales/activerecord.en.yml index f1de3c756..91c035dfb 100644 --- a/config/locales/activerecord.en.yml +++ b/config/locales/activerecord.en.yml @@ -68,7 +68,12 @@ en: name: "Name of organisation" responsible_name: "Person responsible for the group" spending_proposal: - administrator_id: "Administrator" + administrator_id: "Administrador" + association_name: "Association name" + description: "Description" + external_url: "Link to additional documentation" + geozone_id: "Scope of operation" + title: "Title" errors: models: debate: diff --git a/config/locales/activerecord.es.yml b/config/locales/activerecord.es.yml index 79893cecd..a7644f02e 100644 --- a/config/locales/activerecord.es.yml +++ b/config/locales/activerecord.es.yml @@ -69,6 +69,11 @@ es: responsible_name: "Persona responsable del colectivo" spending_proposal: administrator_id: "Administrador" + association_name: "Nombre de la asociación" + description: "Descripción" + external_url: "Enlace a documentación adicional" + geozone_id: "Ámbito de actuación" + title: "Título" errors: models: debate: diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml index 3c4c2f24e..96023f69c 100755 --- a/config/locales/admin.en.yml +++ b/config/locales/admin.en.yml @@ -173,6 +173,7 @@ en: back: Back classification: Clasification heading: "Investment project %{id}" + edit: Edit edit_classification: Edit classification association_name: Association by: By @@ -237,4 +238,4 @@ en: index: phone_not_given: Phone not given sms_code_not_confirmed: Has not confirmed the sms code - title: Incomplete verifications \ No newline at end of file + title: Incomplete verifications diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml index 5d7017336..345a3716c 100644 --- a/config/locales/admin.es.yml +++ b/config/locales/admin.es.yml @@ -173,6 +173,7 @@ es: back: Volver classification: Clasificación heading: Propuesta de inversión %{id} + edit: Editar edit_classification: Editar clasificación association_name: Asociación by: Autor From 89d269e4f52fcd3621bcc67213713c5d74b138da Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 13 Apr 2016 14:13:30 +0200 Subject: [PATCH 126/163] fixes flacky test: "$ is undefined" --- spec/support/phantomjs_ext/disable_js_fx.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/support/phantomjs_ext/disable_js_fx.js b/spec/support/phantomjs_ext/disable_js_fx.js index 2b97f0a0f..eae828ac8 100644 --- a/spec/support/phantomjs_ext/disable_js_fx.js +++ b/spec/support/phantomjs_ext/disable_js_fx.js @@ -1,3 +1,5 @@ document.addEventListener("DOMContentLoaded", function() { - $.fx.off = true; + if (typeof $ !== 'undefined') { + $.fx.off = true; + } }); From ba67396539e04075f8f2e0e311a47f0a5f8cbb23 Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 13 Apr 2016 14:25:14 +0200 Subject: [PATCH 127/163] Adds migration for renaming genre to gender --- db/migrate/20160413122359_rename_genre_to_gender.rb | 5 +++++ db/schema.rb | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20160413122359_rename_genre_to_gender.rb diff --git a/db/migrate/20160413122359_rename_genre_to_gender.rb b/db/migrate/20160413122359_rename_genre_to_gender.rb new file mode 100644 index 000000000..f0bccfc28 --- /dev/null +++ b/db/migrate/20160413122359_rename_genre_to_gender.rb @@ -0,0 +1,5 @@ +class RenameGenreToGender < ActiveRecord::Migration + def change + rename_column :users, :genre, :gender + end +end diff --git a/db/schema.rb b/db/schema.rb index cd05a0d2f..6bee6d425 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: 20160411161531) do +ActiveRecord::Schema.define(version: 20160413122359) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -422,7 +422,7 @@ ActiveRecord::Schema.define(version: 20160411161531) do t.string "oauth_email" t.integer "geozone_id" t.string "redeemable_code" - t.string "genre", limit: 10 + t.string "gender", limit: 10 t.datetime "date_of_birth" end From 1b1f2bc2c977350c170c9946d94d32139424a1a9 Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 13 Apr 2016 14:27:27 +0200 Subject: [PATCH 128/163] renames genre to gender in code --- app/models/verification/residence.rb | 6 +++--- lib/census_api.rb | 2 +- lib/tasks/users.rake | 6 +++--- spec/models/residence_spec.rb | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/models/verification/residence.rb b/app/models/verification/residence.rb index 661659a01..5756af2b3 100644 --- a/app/models/verification/residence.rb +++ b/app/models/verification/residence.rb @@ -32,7 +32,7 @@ class Verification::Residence document_type: document_type, geozone: self.geozone, date_of_birth: date_of_birth.to_datetime, - genre: genre, + gender: gender, residence_verified_at: Time.now) end @@ -77,8 +77,8 @@ class Verification::Residence @census_api_response.district_code end - def genre - @census_api_response.genre + def gender + @census_api_response.gender end private diff --git a/lib/census_api.rb b/lib/census_api.rb index 2b8c7d7a2..ee8107ea1 100644 --- a/lib/census_api.rb +++ b/lib/census_api.rb @@ -52,7 +52,7 @@ class CensusApi data[:datos_vivienda][:item][:codigo_distrito] end - def genre # "Varón" or "Mujer" + def gender # "Varón" or "Mujer" case data[:datos_habitante][:item][:descripcion_sexo] when "Varón" "male" diff --git a/lib/tasks/users.rake b/lib/tasks/users.rake index 18dad53bc..c56df2dd0 100644 --- a/lib/tasks/users.rake +++ b/lib/tasks/users.rake @@ -42,11 +42,11 @@ namespace :users do desc "Associates demographic information to users" task assign_demographic: :environment do - User.residence_verified.where(genre: nil).find_each do |u| + User.residence_verified.where(gender: nil).find_each do |u| begin response = CensusApi.new.call(u.document_type, u.document_number) if response.valid? - u.genre = response.genre + u.gender = response.gender u.date_of_birth = response.date_of_birth.to_datetime u.save print "." @@ -54,7 +54,7 @@ namespace :users do print "X" end rescue - puts "Could not assign genre/dob for user: #{u.id}" + puts "Could not assign gender/dob for user: #{u.id}" end end end diff --git a/spec/models/residence_spec.rb b/spec/models/residence_spec.rb index faa81b5c3..ce151eaee 100644 --- a/spec/models/residence_spec.rb +++ b/spec/models/residence_spec.rb @@ -85,7 +85,7 @@ describe Verification::Residence do describe "save" do - it "should store document number, document type, geozone, date of birth and genre" do + it "should store document number, document type, geozone, date of birth and gender" do user = create(:user) residence.user = user residence.save @@ -96,7 +96,7 @@ describe Verification::Residence do expect(user.date_of_birth.year).to eq(1980) expect(user.date_of_birth.month).to eq(12) expect(user.date_of_birth.day).to eq(31) - expect(user.genre).to eq('male') + expect(user.gender).to eq('male') expect(user.geozone).to eq(geozone) end From edb56b24cec2a9ed9c48f187c41cad6ae46b7ba1 Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 13 Apr 2016 14:30:58 +0200 Subject: [PATCH 129/163] removes lying comment --- lib/census_api.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/census_api.rb b/lib/census_api.rb index ee8107ea1..678a748c6 100644 --- a/lib/census_api.rb +++ b/lib/census_api.rb @@ -52,7 +52,7 @@ class CensusApi data[:datos_vivienda][:item][:codigo_distrito] end - def gender # "Varón" or "Mujer" + def gender case data[:datos_habitante][:item][:descripcion_sexo] when "Varón" "male" From 005bd2696595e6b357d692b420c1841bf214a6f3 Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 13 Apr 2016 18:52:53 +0200 Subject: [PATCH 130/163] does not require phones to be Spanish any more --- app/models/verification/sms.rb | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/app/models/verification/sms.rb b/app/models/verification/sms.rb index ba484c4f3..19e0bf041 100644 --- a/app/models/verification/sms.rb +++ b/app/models/verification/sms.rb @@ -5,13 +5,8 @@ class Verification::Sms validates_presence_of :phone validates :phone, length: { is: 9 } - validate :spanish_phone validate :uniqness_phone - def spanish_phone - errors.add(:phone, :invalid) unless phone.start_with?('6', '7') - end - def uniqness_phone errors.add(:phone, :taken) if User.where(confirmed_phone: phone).any? end @@ -40,4 +35,4 @@ class Verification::Sms def generate_confirmation_code rand.to_s[2..5] end -end \ No newline at end of file +end From 92ecd7c983e664f35462b73a457925e60eb6b9c2 Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 13 Apr 2016 19:27:04 +0200 Subject: [PATCH 131/163] replaces length 9 validation by format validation: only numbers, spaces and plus sign allowed --- app/models/verification/sms.rb | 2 +- spec/models/sms_spec.rb | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/models/verification/sms.rb b/app/models/verification/sms.rb index 19e0bf041..1a013f1d8 100644 --- a/app/models/verification/sms.rb +++ b/app/models/verification/sms.rb @@ -4,7 +4,7 @@ class Verification::Sms attr_accessor :user, :phone, :confirmation_code validates_presence_of :phone - validates :phone, length: { is: 9 } + validates :phone, format: { with: /\A[\d \+]+\z/ } validate :uniqness_phone def uniqness_phone diff --git a/spec/models/sms_spec.rb b/spec/models/sms_spec.rb index f52ff3c6e..83723cb3c 100644 --- a/spec/models/sms_spec.rb +++ b/spec/models/sms_spec.rb @@ -7,9 +7,16 @@ describe Verification::Sms do end it "should validate uniqness of phone" do - user = create(:user, confirmed_phone: "699999999") + create(:user, confirmed_phone: "699999999") sms = Verification::Sms.new(phone: "699999999") expect(sms).to_not be_valid end -end \ No newline at end of file + it "only allows spaces, numbers and the + sign" do + expect(build(:verification_sms, phone: "0034 666666666")).to be_valid + expect(build(:verification_sms, phone: "+34 666666666")).to be_valid + expect(build(:verification_sms, phone: "hello there")).to_not be_valid + expect(build(:verification_sms, phone: "555; DROP TABLE USERS")).to_not be_valid + end + +end From fa2fe873ff47da8d6a312d04bce8de144727ea2c Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Thu, 14 Apr 2016 00:14:35 +0200 Subject: [PATCH 132/163] Fixes styles for progress meter proposals supports --- app/assets/stylesheets/participation.scss | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index 10cd6e65d..1773ef8da 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -164,10 +164,12 @@ .progress { background-color: rgba(255,255,255,.8); - height: rem-calc(12); + height: $line-height/2; .meter { background: $votes-like; + display: block; + height: $line-height/2; } } From 455cd15c40ed6a05c4413d9a5e5dcead6a6d05c7 Mon Sep 17 00:00:00 2001 From: Ana Date: Thu, 14 Apr 2016 13:43:17 +0200 Subject: [PATCH 133/163] Version PhantomJS updated --- README.md | 4 ++-- README_ES.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 251a0f8e3..9582baa02 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ bin/rails s ``` -Prerequisites for testing: install PhantomJS >= 2.0 +Prerequisites for testing: install PhantomJS >= 1.9.8 Run the tests with: @@ -62,4 +62,4 @@ Code published under AFFERO GPL v3 (see [LICENSE-AGPLv3.txt](LICENSE-AGPLv3.txt) ## Contributions -See [CONTRIBUTING_EN.md](CONTRIBUTING_EN.md) \ No newline at end of file +See [CONTRIBUTING_EN.md](CONTRIBUTING_EN.md) diff --git a/README_ES.md b/README_ES.md index c3fd3cdff..654272d60 100644 --- a/README_ES.md +++ b/README_ES.md @@ -47,7 +47,7 @@ Para ejecutar la aplicación en local: bin/rails s ``` -Prerequisitos para los tests: tener instalado PhantomJS >= 2.0 +Prerequisitos para los tests: tener instalado PhantomJS >= 1.9.8 Para ejecutar los tests: From e55a4c9f2371ba087bfad67748bcb1441b339be2 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Thu, 14 Apr 2016 16:38:39 +0200 Subject: [PATCH 134/163] Renters videos on proposals show --- app/views/proposals/show.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/proposals/show.html.erb b/app/views/proposals/show.html.erb index 1a5de351b..6550ece24 100644 --- a/app/views/proposals/show.html.erb +++ b/app/views/proposals/show.html.erb @@ -51,7 +51,7 @@
    <%= @proposal.summary %>
    <% if @proposal.video_url.present? %> -
    +
    From c5a1b3d1ee8548b05f18515fac0b0716766561e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Fri, 15 Apr 2016 11:02:15 +0200 Subject: [PATCH 135/163] adds info to readme about the seed verified user --- README.md | 8 ++++---- README_ES.md | 9 +++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index a5bb81ff8..2cdaddb19 100644 --- a/README.md +++ b/README.md @@ -61,10 +61,10 @@ You can use the default admin user from the seeds file: **user:** admin@madrid.es **pass:** 12345678 -But for some actions like voting, you will need to verify him, opening a console with `rails console` and then: -``` -User.first.update_attributes(verified_at: Date.today, residence_verified_at: Date.today, level_two_verified_at: Date.today) -``` +But for some actions like voting, you will need a verified user, the seeds file also includes one: + + **user:** verified@madrid.es + **pass:** 12345678 ### OAuth diff --git a/README_ES.md b/README_ES.md index 96772ba77..e0392bc51 100644 --- a/README_ES.md +++ b/README_ES.md @@ -60,10 +60,11 @@ Puedes usar el usuario administrador por defecto del fichero seeds: **user:** admin@madrid.es **pass:** 12345678 -Pero para ciertas acciones, como apoyar, necesitarás verificarle, abre una consola con `rails console` y escribe: -``` -User.first.update_attributes(verified_at: Date.today, residence_verified_at: Date.today, level_two_verified_at: Date.today) -``` +Pero para ciertas acciones, como apoyar, necesitarás un usuario verificado, el fichero seeds proporciona uno: + + **user:** verified@madrid.es + **pass:** 12345678 + ### OAuth From 7d32f2a4b0a33b7f9485b7b85be1dd927d3d0733 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Fri, 15 Apr 2016 13:09:54 +0200 Subject: [PATCH 136/163] Adds label and placeholder for international numbers verification --- app/views/verification/sms/new.html.erb | 5 +++-- config/locales/verification.en.yml | 2 ++ config/locales/verification.es.yml | 2 ++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/views/verification/sms/new.html.erb b/app/views/verification/sms/new.html.erb index 6019c89cd..4af6a4dfb 100644 --- a/app/views/verification/sms/new.html.erb +++ b/app/views/verification/sms/new.html.erb @@ -28,9 +28,10 @@ <%= render "shared/errors", resource: @sms %>
    - <%= f.label t("verification.sms.new.phone") %> + <%= f.label :phone, t("verification.sms.new.phone"), class: "inline-block" %> + <%= t("verification.sms.new.phone_format_html") %>

    <%= t("verification.sms.new.phone_note") %>

    - <%= f.text_field :phone, label: false %> + <%= f.text_field :phone, label: false, placeholder: t("verification.sms.new.phone_placeholder") %>
    <%= f.submit t("verification.sms.new.submit_button"), class: "button success" %> diff --git a/config/locales/verification.en.yml b/config/locales/verification.en.yml index 24c9ae928..8b7617f1a 100755 --- a/config/locales/verification.en.yml +++ b/config/locales/verification.en.yml @@ -83,7 +83,9 @@ en: title: Security code confirmation new: phone: Enter your mobile phone number to receive the code + phone_format_html: "(Example: 612345678 or +34612345678)" phone_note: We only user your phone for send to you a code, we never contact to you. + phone_placeholder: "Example: 612345678 or +34612345678" submit_button: Send title: Send confirmation code update: diff --git a/config/locales/verification.es.yml b/config/locales/verification.es.yml index be676ab0f..7c27584a7 100644 --- a/config/locales/verification.es.yml +++ b/config/locales/verification.es.yml @@ -83,7 +83,9 @@ es: title: SMS de confirmación new: phone: Introduce tu teléfono móvil para recibir el código + phone_format_html: "(Ejemplo: 612345678 ó +34612345678)" phone_note: Sólo usaremos tu teléfono para enviarte un código, nunca te contactaremos. + phone_placeholder: "Ejemplo: 612345678 ó +34612345678" submit_button: Enviar title: SMS de confirmación update: From 3adcd9c304c3754646f3141002f47f024cc8af84 Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 15 Apr 2016 17:16:13 +0200 Subject: [PATCH 137/163] Adds physical votes to sps table --- ...0160415150524_add_physical_votes_to_spending_proposals.rb | 5 +++++ db/schema.rb | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20160415150524_add_physical_votes_to_spending_proposals.rb diff --git a/db/migrate/20160415150524_add_physical_votes_to_spending_proposals.rb b/db/migrate/20160415150524_add_physical_votes_to_spending_proposals.rb new file mode 100644 index 000000000..a90b1d1a7 --- /dev/null +++ b/db/migrate/20160415150524_add_physical_votes_to_spending_proposals.rb @@ -0,0 +1,5 @@ +class AddPhysicalVotesToSpendingProposals < ActiveRecord::Migration + def change + add_column :spending_proposals, :physical_votes, :integer, default: 0 + end +end diff --git a/db/schema.rb b/db/schema.rb index 6bee6d425..35d28fc78 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: 20160413122359) do +ActiveRecord::Schema.define(version: 20160415150524) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -315,6 +315,7 @@ ActiveRecord::Schema.define(version: 20160413122359) do t.integer "cached_votes_up", default: 0 t.tsvector "tsv" t.string "responsible_name", limit: 60 + t.integer "physical_votes", default: 0 end add_index "spending_proposals", ["author_id"], name: "index_spending_proposals_on_author_id", using: :btree From d9ec2e2cf341a46ec2b0271499e4b2752dd871a1 Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 15 Apr 2016 17:16:35 +0200 Subject: [PATCH 138/163] Calculates SP.total_votes using physical_votes --- app/models/spending_proposal.rb | 2 +- spec/models/spending_proposal_spec.rb | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/models/spending_proposal.rb b/app/models/spending_proposal.rb index 69d4d839f..66c6cb2ad 100644 --- a/app/models/spending_proposal.rb +++ b/app/models/spending_proposal.rb @@ -100,7 +100,7 @@ class SpendingProposal < ActiveRecord::Base end def total_votes - cached_votes_up + cached_votes_up + physical_votes end def code diff --git a/spec/models/spending_proposal_spec.rb b/spec/models/spending_proposal_spec.rb index ba18287e6..e3b7629d7 100644 --- a/spec/models/spending_proposal_spec.rb +++ b/spec/models/spending_proposal_spec.rb @@ -277,4 +277,15 @@ describe SpendingProposal do end end + describe "total votes" do + it "takes into account physical votes in addition to web votes" do + sp = create(:spending_proposal) + sp.register_vote(create(:user, :level_two), true) + expect(sp.total_votes).to eq(1) + sp.physical_votes = 10 + expect(sp.total_votes).to eq(11) + end + end + + end From 5a785ca7ce53c60397516512eb7a73b6b7d922be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Fri, 15 Apr 2016 17:57:02 +0200 Subject: [PATCH 139/163] adds voting on sps as admin feature flag --- config/locales/settings.en.yml | 4 +++- config/locales/settings.es.yml | 4 +++- db/seeds.rb | 7 +++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/config/locales/settings.en.yml b/config/locales/settings.en.yml index 756debb24..32874e32b 100755 --- a/config/locales/settings.en.yml +++ b/config/locales/settings.en.yml @@ -15,4 +15,6 @@ en: per_page_code: "Code to be included on every page" feature: debates: Debates - spending_proposals: Spending proposals + spending_proposals: Investment projects + spending_proposal_features: + voting_allowed: Voting on investment projects diff --git a/config/locales/settings.es.yml b/config/locales/settings.es.yml index 36d4edf63..aa5dea14e 100644 --- a/config/locales/settings.es.yml +++ b/config/locales/settings.es.yml @@ -15,4 +15,6 @@ es: per_page_code: "Código a incluir en cada página" feature: debates: Debates - spending_proposals: Propuestas de gasto + spending_proposals: Propuestas de inversión + spending_proposal_features: + voting_allowed: Votaciones sobre propuestas de inversión. \ No newline at end of file diff --git a/db/seeds.rb b/db/seeds.rb index 143a4af48..067349837 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -22,6 +22,9 @@ Setting["max_votes_for_debate_edit"] = 1000 # Max votes where a proposal is still editable Setting["max_votes_for_proposal_edit"] = 1000 +# Max length for comments +Setting['comments_body_max_length'] = 1000 + # Prefix for the Proposal codes Setting["proposal_code_prefix"] = 'MAD' @@ -59,5 +62,5 @@ Setting['feature.facebook_login'] = true Setting['feature.google_login'] = true Setting['feature.public_stats'] = true -# Max length for comments -Setting['comments_body_max_length'] = 1000 +# Spending proposals feature flags +Setting['feature.spending_proposal_features.voting_allowed'] = true From e6a9cb4fcc79d4e3f12fed36819e8648305635bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Fri, 15 Apr 2016 23:01:00 +0200 Subject: [PATCH 140/163] disable voting on sps if setting disabled refactors hover messages on sps votes --- app/assets/javascripts/votes.js.coffee | 2 + app/assets/stylesheets/participation.scss | 9 ++-- app/models/spending_proposal.rb | 10 ++++- app/models/user.rb | 5 +++ app/views/spending_proposals/_votes.html.erb | 31 ++++++-------- config/locales/en.yml | 6 +++ config/locales/es.yml | 6 +++ spec/features/votes_spec.rb | 20 +++++++++ spec/models/spending_proposal_spec.rb | 43 ++++++++++++++++++++ spec/support/common_actions.rb | 5 +++ 10 files changed, 111 insertions(+), 26 deletions(-) diff --git a/app/assets/javascripts/votes.js.coffee b/app/assets/javascripts/votes.js.coffee index 43469909d..e4223c644 100644 --- a/app/assets/javascripts/votes.js.coffee +++ b/app/assets/javascripts/votes.js.coffee @@ -5,11 +5,13 @@ App.Votes = $("div.anonymous-votes", votes).show(); $("div.organizations-votes", votes).show(); $("div.not-logged", votes).show(); + $("div.no-supports-allowed", votes).show(); $("div.logged", votes).hide(); , -> $("div.anonymous-votes", votes).hide(); $("div.organizations-votes", votes).hide(); $("div.not-logged", votes).hide(); + $("div.no-supports-allowed", votes).hide(); $("div.logged", votes).show(); initialize: -> diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index 1773ef8da..0873e7c7c 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -240,7 +240,7 @@ } } - .anonymous-votes, .organizations-votes { + .anonymous-votes, .organizations-votes, .no-supports-allowed { background: $warning-bg; color: $warning-color; height: 100%; @@ -847,16 +847,13 @@ color: $budget; } - .not-logged, - .organizations-votes, - .anonymous-votes { + .no-supports-allowed { background: rgba(69,67,114,.96); color: white; padding: rem-calc(12); } - .anonymous-votes p, .anonymous-votes a, - .organizations-votes p { + .no-supports-allowed p, .no-supports-allowed a { color: white; } } diff --git a/app/models/spending_proposal.rb b/app/models/spending_proposal.rb index 66c6cb2ad..7a3dda7c6 100644 --- a/app/models/spending_proposal.rb +++ b/app/models/spending_proposal.rb @@ -112,8 +112,16 @@ class SpendingProposal < ActiveRecord::Base update(unfeasible_email_sent_at: Time.now) end + def reason_for_not_being_votable_by(user) + return :not_logged_in unless user + return :not_verified unless user.can?(:vote, SpendingProposal) + return :unfeasible if unfeasible? + return :organization if user.organization? + return :not_voting_allowed if Setting["feature.spending_proposal_features.voting_allowed"].blank? + end + def votable_by?(user) - user && user.level_two_or_three_verified? + reason_for_not_being_votable_by(user).blank? end def register_vote(user, vote_value) diff --git a/app/models/user.rb b/app/models/user.rb index bc4b0f120..f7980c796 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -222,6 +222,11 @@ class User < ActiveRecord::Base self.update(registering_with_oauth: true, email: nil) end + def ability + @ability ||= Ability.new(self) + end + delegate :can?, :cannot?, to: :ability + private def clean_document_number self.document_number = self.document_number.gsub(/[^a-z0-9]+/i, "").upcase unless self.document_number.blank? diff --git a/app/views/spending_proposals/_votes.html.erb b/app/views/spending_proposals/_votes.html.erb index ed8e61b2d..8dbc2aa3f 100644 --- a/app/views/spending_proposals/_votes.html.erb +++ b/app/views/spending_proposals/_votes.html.erb @@ -18,25 +18,18 @@ <% end %>
    - <% if user_signed_in? && current_user.organization? %> - - <% elsif user_signed_in? && !spending_proposal.votable_by?(current_user)%> - - <% elsif !user_signed_in? %> - + <% reason = spending_proposal.reason_for_not_being_votable_by(current_user) %> + + <% if reason.present? && !voted_for?(@spending_proposal_votes, spending_proposal) %> + <% end %> <% if voted_for?(@spending_proposal_votes, spending_proposal) && setting['twitter_handle'] %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 639aa3fb9..8609c079c 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -500,6 +500,12 @@ en: unauthenticated: You must %{signin} or %{signup} to continue. verified_only: Only verified users can vote on proposals; %{verify_account}. verify_account: verify your account + spending_proposals: + not_logged_in: You must %{signin} or %{signup} to continue. + not_verified: Only verified users can vote on proposals; %{verify_account}. + organization: Organisations are not permitted to vote + unfeasible: Unfeasible investment projects can not be supported + not_voting_allowed: Voting phase is closed welcome: debates: alt: Icon debates diff --git a/config/locales/es.yml b/config/locales/es.yml index c39ef965a..a15528d5a 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -500,6 +500,12 @@ es: unauthenticated: Necesitas %{signin} o %{signup} para continuar. verified_only: Las propuestas sólo pueden ser votadas por usuarios verificados, %{verify_account}. verify_account: verifica tu cuenta + spending_proposals: + not_logged_in: Necesitas %{signin} o %{signup} para continuar. + not_verified: Las propuestas de inversión sólo pueden ser apoyadas por usuarios verificados, %{verify_account}. + organization: Las organizaciones no pueden votar. + unfeasible: No se pueden votar propuestas inviables. + not_voting_allowed: El periodo de votación está cerrado. welcome: debates: alt: Icono debates diff --git a/spec/features/votes_spec.rb b/spec/features/votes_spec.rb index 632162c3c..2ae64effe 100644 --- a/spec/features/votes_spec.rb +++ b/spec/features/votes_spec.rb @@ -435,4 +435,24 @@ feature 'Votes' do end end end + + scenario 'Disable voting on spending proposals', :js do + login_as(@manuela) + Setting["feature.spending_proposal_features.voting_allowed"] = nil + spending_proposal = create(:spending_proposal) + + visit spending_proposals_path + + within("#spending_proposal_#{spending_proposal.id}") do + find("div.supports").hover + expect_message_voting_not_allowed + end + + visit spending_proposal_path(spending_proposal) + + within("#spending_proposal_#{spending_proposal.id}") do + find("div.supports").hover + expect_message_voting_not_allowed + end + end end diff --git a/spec/models/spending_proposal_spec.rb b/spec/models/spending_proposal_spec.rb index e3b7629d7..5bff7cadd 100644 --- a/spec/models/spending_proposal_spec.rb +++ b/spec/models/spending_proposal_spec.rb @@ -261,6 +261,49 @@ describe SpendingProposal do end end + describe 'Supports' do + let(:user) { create(:user, :level_two) } + let(:luser) { create(:user) } + let(:district) { create(:geozone) } + let(:city_sp) { create(:spending_proposal) } + let(:district_sp) { create(:spending_proposal, geozone: district) } + + describe '#reason_for_not_being_votable_by' do + it "rejects not logged in users" do + expect(city_sp.reason_for_not_being_votable_by(nil)).to eq(:not_logged_in) + expect(district_sp.reason_for_not_being_votable_by(nil)).to eq(:not_logged_in) + end + + it "rejects not verified users" do + expect(city_sp.reason_for_not_being_votable_by(luser)).to eq(:not_verified) + expect(district_sp.reason_for_not_being_votable_by(luser)).to eq(:not_verified) + end + + it "rejects unfeasible spending proposals" do + unfeasible = create(:spending_proposal, feasible: false, valuation_finished: true) + expect(unfeasible.reason_for_not_being_votable_by(user)).to eq(:unfeasible) + end + + it "rejects organizations" do + create(:organization, user: user) + expect(city_sp.reason_for_not_being_votable_by(user)).to eq(:organization) + expect(district_sp.reason_for_not_being_votable_by(user)).to eq(:organization) + end + + it "rejects votes when voting is not allowed (via admin setting)" do + Setting["feature.spending_proposal_features.voting_allowed"] = nil + expect(city_sp.reason_for_not_being_votable_by(user)).to eq(:not_voting_allowed) + expect(district_sp.reason_for_not_being_votable_by(user)).to eq(:not_voting_allowed) + end + + it "accepts valid votes when voting is allowed" do + Setting["feature.spending_proposal_features.voting_allowed"] = true + expect(city_sp.reason_for_not_being_votable_by(user)).to be_nil + expect(district_sp.reason_for_not_being_votable_by(user)).to be_nil + end + end + end + describe "responsible_name" do let(:user) { create(:user, document_number: "123456") } let!(:spending_proposal) { create(:spending_proposal, author: user) } diff --git a/spec/support/common_actions.rb b/spec/support/common_actions.rb index f3d4a8697..762119130 100644 --- a/spec/support/common_actions.rb +++ b/spec/support/common_actions.rb @@ -174,6 +174,11 @@ module CommonActions expect(page).to have_selector('.in-favor a', visible: false) end + def expect_message_voting_not_allowed + expect(page).to have_content 'Voting phase is closed' + expect(page).to have_selector('.in-favor a', visible: false) + end + def create_featured_proposals [create(:proposal, :with_confidence_score, cached_votes_up: 100), create(:proposal, :with_confidence_score, cached_votes_up: 90), From 3a6d9d639a8914aa188c3f3ce07059fdc8553df5 Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Sat, 16 Apr 2016 11:13:01 +0200 Subject: [PATCH 141/163] Fix typo in README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2cdaddb19..e6181f38c 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ To test authentication services with external OAuth suppliers - right now Twitte In the case of Google, verify that the APIs *Contacts API* and *Google+ API* are enabled for the application. -## Licence +## License Code published under AFFERO GPL v3 (see [LICENSE-AGPLv3.txt](LICENSE-AGPLv3.txt)) From fc0ea93cefede4c001208edc8259bc4659352e91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Sun, 17 Apr 2016 10:55:42 +0200 Subject: [PATCH 142/163] adds setting to dev_seeds --- db/dev_seeds.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/db/dev_seeds.rb b/db/dev_seeds.rb index ffbc8237d..e4365d244 100644 --- a/db/dev_seeds.rb +++ b/db/dev_seeds.rb @@ -13,6 +13,7 @@ Setting.create(key: 'max_votes_for_debate_edit', value: '1000') Setting.create(key: 'max_votes_for_proposal_edit', value: '1000') Setting.create(key: 'proposal_code_prefix', value: 'MAD') Setting.create(key: 'votes_for_proposal_success', value: '100') +Setting.create(key: 'comments_body_max_length', value: '1000') Setting.create(key: 'blog_url', value: '/blog') Setting.create(key: 'url', value: 'http://localhost:3000') @@ -20,11 +21,11 @@ Setting.create(key: 'org_name', value: 'Consul') Setting.create(key: 'place_name', value: 'City') Setting.create(key: 'feature.debates', value: "true") Setting.create(key: 'feature.spending_proposals', value: "true") +Setting.create(key: 'feature.spending_proposal_features.voting_allowed', value: "true") Setting.create(key: 'feature.twitter_login', value: "true") Setting.create(key: 'feature.facebook_login', value: "true") Setting.create(key: 'feature.google_login', value: "true") -Setting.create(key: 'comments_body_max_length', value: '1000') puts "Creating Geozones" ('A'..'Z').each{ |i| Geozone.create(name: "District #{i}") } From 11bcdf02110801159e15fc2a883df03a6f94a3ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Mon, 18 Apr 2016 12:04:18 +0200 Subject: [PATCH 143/163] changes reasons order, :not_voting_allowed first --- app/models/spending_proposal.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/spending_proposal.rb b/app/models/spending_proposal.rb index 7a3dda7c6..d8ae2acf0 100644 --- a/app/models/spending_proposal.rb +++ b/app/models/spending_proposal.rb @@ -113,11 +113,11 @@ class SpendingProposal < ActiveRecord::Base end def reason_for_not_being_votable_by(user) + return :not_voting_allowed if Setting["feature.spending_proposal_features.voting_allowed"].blank? return :not_logged_in unless user return :not_verified unless user.can?(:vote, SpendingProposal) return :unfeasible if unfeasible? return :organization if user.organization? - return :not_voting_allowed if Setting["feature.spending_proposal_features.voting_allowed"].blank? end def votable_by?(user) From c9393390200f6aa7b8d7d3ec001301c4a81ae65a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Mon, 18 Apr 2016 12:04:50 +0200 Subject: [PATCH 144/163] shows voting button for sps only if voting allowed --- app/assets/stylesheets/participation.scss | 6 ++++++ app/views/spending_proposals/_votes.html.erb | 16 +++++++++------- spec/support/common_actions.rb | 2 +- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index 0873e7c7c..270005f88 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -870,6 +870,12 @@ } } +.investment-project .supports .total-supports.no-button, +.investment-project-show .supports .total-supports.no-button { + display: block; + margin-top: $line-height*1.5; +} + // 05. Featured // - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/app/views/spending_proposals/_votes.html.erb b/app/views/spending_proposals/_votes.html.erb index 8dbc2aa3f..85220d6c9 100644 --- a/app/views/spending_proposals/_votes.html.erb +++ b/app/views/spending_proposals/_votes.html.erb @@ -1,15 +1,19 @@
    - + <% reason = spending_proposal.reason_for_not_being_votable_by(current_user) %> + <% voting_allowed = true unless reason.presence == :not_voting_allowed %> + <% user_voted_for = voted_for?(@spending_proposal_votes, spending_proposal) %> + + <%= t("spending_proposals.spending_proposal.supports", count: spending_proposal.total_votes) %>
    - <% if voted_for?(@spending_proposal_votes, spending_proposal) %> + <% if user_voted_for %>
    <%= t("spending_proposals.spending_proposal.already_supported") %>
    - <% else %> + <% elsif voting_allowed %> <%= link_to vote_url, class: "button button-support small expanded", title: t('spending_proposals.spending_proposal.support_title'), method: "post", remote: true do %> @@ -18,9 +22,7 @@ <% end %>
    - <% reason = spending_proposal.reason_for_not_being_votable_by(current_user) %> - - <% if reason.present? && !voted_for?(@spending_proposal_votes, spending_proposal) %> + <% if reason.present? && !user_voted_for %> <% end %> - <% if voted_for?(@spending_proposal_votes, spending_proposal) && setting['twitter_handle'] %> + <% if user_voted_for && setting['twitter_handle'] %> diff --git a/spec/support/common_actions.rb b/spec/support/common_actions.rb index 762119130..340d7c8a7 100644 --- a/spec/support/common_actions.rb +++ b/spec/support/common_actions.rb @@ -176,7 +176,7 @@ module CommonActions def expect_message_voting_not_allowed expect(page).to have_content 'Voting phase is closed' - expect(page).to have_selector('.in-favor a', visible: false) + expect(page).to_not have_selector('.in-favor a') end def create_featured_proposals From f2e0059c96ad40faf59865b7916b7259b02a6479 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 18 Apr 2016 19:58:01 +0200 Subject: [PATCH 145/163] activates newsletter by default --- db/migrate/20160418172919_activate_newsletter_by_default.rb | 5 +++++ db/schema.rb | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20160418172919_activate_newsletter_by_default.rb diff --git a/db/migrate/20160418172919_activate_newsletter_by_default.rb b/db/migrate/20160418172919_activate_newsletter_by_default.rb new file mode 100644 index 000000000..cdee85f1b --- /dev/null +++ b/db/migrate/20160418172919_activate_newsletter_by_default.rb @@ -0,0 +1,5 @@ +class ActivateNewsletterByDefault < ActiveRecord::Migration + def change + change_column :users, :newsletter, :boolean, default: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 35d28fc78..223a14d47 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: 20160415150524) do +ActiveRecord::Schema.define(version: 20160418172919) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -416,7 +416,7 @@ ActiveRecord::Schema.define(version: 20160415150524) do t.string "erase_reason" t.datetime "erased_at" t.boolean "public_activity", default: true - t.boolean "newsletter", default: false + t.boolean "newsletter", default: true t.integer "notifications_count", default: 0 t.boolean "registering_with_oauth", default: false t.string "locale" From 08db8a6b1741cf2145b778e81eec063393ef7d4e Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 18 Apr 2016 20:08:05 +0200 Subject: [PATCH 146/163] fixes specs --- spec/models/user_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index c63959a64..4d1b269ec 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -79,8 +79,8 @@ describe User do end describe 'subscription_to_website_newsletter' do - it 'should be false by default' do - expect(subject.newsletter).to eq(false) + it 'should be true by default' do + expect(subject.newsletter).to eq(true) end end end From 42502cecb73906ee04de22ede3f6ec7aecffe834 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Tue, 19 Apr 2016 00:08:12 +0200 Subject: [PATCH 147/163] Fixes youtu.be embedded videos --- app/helpers/embed_videos_helper.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/app/helpers/embed_videos_helper.rb b/app/helpers/embed_videos_helper.rb index b53aeef21..b48799bf5 100644 --- a/app/helpers/embed_videos_helper.rb +++ b/app/helpers/embed_videos_helper.rb @@ -1,30 +1,30 @@ module EmbedVideosHelper def embedded_video_code - link = @proposal.video_url + link = @proposal.video_url if link.match(/vimeo.*/) server = "Vimeo" elsif link.match(/youtu*.*/) server = "YouTube" - end - + end + if server == "Vimeo" regExp = /vimeo.*(staffpicks\/|channels\/|videos\/|video\/|\/)([^#\&\?]*).*/ src = "https://player.vimeo.com/video/" elsif server == "YouTube" - regExp = /youtu.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/ - src = "https://www.youtube.com/embed/" + regExp = /youtu.*(be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/ + src = "https://www.youtube.com/embed/" end - - if regExp + + if regExp match = link.match(regExp) end if match and match[2] '' - else + else '' end - end + end end \ No newline at end of file From 84a743878612d44afe8fcfe998764cfce7fff537 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Tue, 19 Apr 2016 00:08:50 +0200 Subject: [PATCH 148/163] Improves styles for long proposals show texts --- app/assets/stylesheets/participation.scss | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index 270005f88..d897a2a28 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -339,6 +339,10 @@ .debate-show, .proposal-show, .investment-project-show { + p { + word-wrap: break-word; + } + .social-share-full .social-share-button { display:inline; } From 038a520987b56a86a6502b8f0e2e8b992e45933b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Tue, 19 Apr 2016 13:05:08 +0200 Subject: [PATCH 149/163] updates dependencies and specs --- Gemfile | 2 +- Gemfile.lock | 30 +++++++++---------- .../admin/spending_proposals/show.html.erb | 2 +- spec/features/admin/tags_spec.rb | 4 +-- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Gemfile b/Gemfile index e925fb642..628f8c10d 100644 --- a/Gemfile +++ b/Gemfile @@ -74,7 +74,7 @@ group :development, :test do gem 'quiet_assets' gem 'letter_opener_web', '~> 1.3.0' gem 'i18n-tasks' - gem 'capistrano', '3.4.0', require: false + gem 'capistrano', '3.4.1', require: false gem "capistrano-bundler", '1.1.4', require: false gem "capistrano-rails", '1.1.6', require: false gem "capistrano-rvm", require: false diff --git a/Gemfile.lock b/Gemfile.lock index 755561fb2..6d41a3669 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -76,9 +76,9 @@ GEM bullet (5.0.0) activesupport (>= 3.0.0) uniform_notifier (~> 1.9.0) - byebug (8.2.2) + byebug (8.2.4) cancancan (1.13.1) - capistrano (3.4.0) + capistrano (3.4.1) i18n rake (>= 10.0.0) sshkit (~> 1.3) @@ -91,9 +91,9 @@ GEM capistrano-rvm (0.1.2) capistrano (~> 3.0) sshkit (~> 1.2) - capistrano3-delayed-job (1.6.0) + capistrano3-delayed-job (1.7.0) capistrano (>= 3.0.0) - capybara (2.6.2) + capybara (2.7.0) addressable mime-types (>= 1.16) nokogiri (>= 1.3.3) @@ -125,7 +125,7 @@ GEM tins (~> 1.6.0) daemons (1.2.3) dalli (2.7.6) - database_cleaner (1.5.1) + database_cleaner (1.5.2) debug_inspector (0.0.2) delayed_job (4.1.1) activesupport (>= 3.0, < 5.0) @@ -154,16 +154,16 @@ GEM errbase (0.0.3) erubis (2.7.0) execjs (2.6.0) - factory_girl (4.5.0) + factory_girl (4.7.0) activesupport (>= 3.0.0) - factory_girl_rails (4.6.0) - factory_girl (~> 4.5.0) + factory_girl_rails (4.7.0) + factory_girl (~> 4.7.0) railties (>= 3.0.0) faker (1.6.3) i18n (~> 0.5) faraday (0.9.2) multipart-post (>= 1.2, < 3) - foundation-rails (6.2.0.1) + foundation-rails (6.2.1.0) railties (>= 3.1.0) sass (>= 3.3.0, < 3.5) sprockets-es6 (>= 0.9.0) @@ -233,7 +233,7 @@ GEM multipart-post (2.0.0) net-scp (1.2.1) net-ssh (>= 2.6.5) - net-ssh (3.0.2) + net-ssh (3.1.1) newrelic_rpm (3.15.1.316) nokogiri (1.6.7.2) mini_portile2 (~> 2.0.0.rc2) @@ -343,7 +343,7 @@ GEM rspec-support (3.4.1) ruby-progressbar (1.7.5) safe_yaml (1.0.4) - sass (3.4.21) + sass (3.4.22) sass-rails (5.0.4) railties (>= 4.0.0, < 5.0) sass (~> 3.1) @@ -365,10 +365,10 @@ GEM json (~> 1.8) simplecov-html (~> 0.10.0) simplecov-html (0.10.0) - spring (1.6.4) + spring (1.7.1) spring-commands-rspec (1.0.4) spring (>= 0.9.1) - sprockets (3.5.2) + sprockets (3.6.0) concurrent-ruby (~> 1.0) rack (> 1, < 3) sprockets-es6 (0.9.0) @@ -379,7 +379,7 @@ GEM actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) - sshkit (1.8.1) + sshkit (1.9.0) net-scp (>= 1.1.2) net-ssh (>= 2.8.0) term-ansicolor (1.3.2) @@ -438,7 +438,7 @@ DEPENDENCIES bullet byebug cancancan - capistrano (= 3.4.0) + capistrano (= 3.4.1) capistrano-bundler (= 1.1.4) capistrano-rails (= 1.1.6) capistrano-rvm diff --git a/app/views/admin/spending_proposals/show.html.erb b/app/views/admin/spending_proposals/show.html.erb index c54816071..64313e030 100644 --- a/app/views/admin/spending_proposals/show.html.erb +++ b/app/views/admin/spending_proposals/show.html.erb @@ -1,4 +1,4 @@ -<%= link_to admin_spending_proposals_path(SpendingProposal.filter_params(params)) do %> +<%= link_to admin_spending_proposals_path(SpendingProposal.filter_params(params)), data: {no_turbolink: true} do %> <%= t("admin.spending_proposals.show.back") %> <% end %> diff --git a/spec/features/admin/tags_spec.rb b/spec/features/admin/tags_spec.rb index 74579c1b8..b944cdd9e 100644 --- a/spec/features/admin/tags_spec.rb +++ b/spec/features/admin/tags_spec.rb @@ -33,7 +33,7 @@ feature 'Admin tags' do scenario 'Update' do visit admin_tags_path featured_checkbox = find("#tag_featured_#{@tag1.id}") - expect(featured_checkbox.checked?).to be_nil + expect(featured_checkbox.checked?).to be_blank within("#edit_tag_#{@tag1.id}") do check "tag_featured_#{@tag1.id}" @@ -42,7 +42,7 @@ feature 'Admin tags' do visit admin_tags_path featured_checkbox = find("#tag_featured_#{@tag1.id}") - expect(featured_checkbox.checked?).to eq('checked') + expect(featured_checkbox.checked?).to eq(true) end scenario 'Delete' do From 87d2d74f6630d1540284ecbfe514235f5d5fdac3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Tue, 19 Apr 2016 13:27:16 +0200 Subject: [PATCH 150/163] updates devise & ahoy --- Gemfile | 4 +-- Gemfile.lock | 35 +++++++++++++--------- app/views/debates/show.html.erb | 2 +- app/views/proposals/show.html.erb | 2 +- app/views/spending_proposals/show.html.erb | 2 +- 5 files changed, 26 insertions(+), 19 deletions(-) diff --git a/Gemfile b/Gemfile index 628f8c10d..ab00df68e 100644 --- a/Gemfile +++ b/Gemfile @@ -19,7 +19,7 @@ gem 'jquery-ui-rails' # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks gem 'turbolinks' -gem 'devise', '~> 3.5.6' +gem 'devise', '~> 3.5.7' # Use ActiveModel has_secure_password # gem 'bcrypt', '~> 3.1.7' gem 'omniauth' @@ -52,7 +52,7 @@ gem 'newrelic_rpm', '~> 3.14' gem 'whenever', require: false gem 'pg_search' -gem 'ahoy_matey', '~> 1.2.1' +gem 'ahoy_matey', '~> 1.4.0' gem 'groupdate' # group temporary data gem 'tolk' # Web interface for translations diff --git a/Gemfile.lock b/Gemfile.lock index 6d41a3669..12cb537d3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -49,14 +49,15 @@ GEM activerecord (>= 3.2, < 5) acts_as_votable (0.10.0) addressable (2.4.0) - ahoy_matey (1.2.1) + ahoy_matey (1.4.0) addressable - browser (>= 0.4.0) - errbase + browser (~> 2.0) geocoder - rails + rack-attack + railties referer-parser (>= 0.3.0) request_store + safely_block user_agent_parser uuidtools akami (1.3.1) @@ -70,8 +71,8 @@ GEM babel-transpiler (0.7.0) babel-source (>= 4.0, < 6) execjs (~> 2.0) - bcrypt (3.1.10) - browser (1.1.0) + bcrypt (3.1.11) + browser (2.0.3) builder (3.2.2) bullet (5.0.0) activesupport (>= 3.0.0) @@ -132,7 +133,7 @@ GEM delayed_job_active_record (4.1.0) activerecord (>= 3.0, < 5) delayed_job (>= 3.0, < 5) - devise (3.5.6) + devise (3.5.7) bcrypt (~> 3.0) orm_adapter (~> 0.1) railties (>= 3.2.6, < 5) @@ -176,7 +177,7 @@ GEM fuubar (2.0.0) rspec (~> 3.0) ruby-progressbar (~> 1.4) - geocoder (1.3.1) + geocoder (1.3.4) globalid (0.3.6) activesupport (>= 4.1.0) groupdate (2.5.2) @@ -223,9 +224,11 @@ GEM railties (>= 3.2) loofah (2.0.3) nokogiri (>= 1.5.9) - mail (2.6.3) - mime-types (>= 1.16, < 3) - mime-types (2.99.1) + mail (2.6.4) + mime-types (>= 1.16, < 4) + mime-types (3.0) + mime-types-data (~> 3.2015) + mime-types-data (3.2016.0221) mini_portile2 (2.0.0) minitest (5.8.4) multi_json (1.11.2) @@ -284,6 +287,8 @@ GEM rack (1.6.4) rack-accept (0.4.5) rack (>= 0.4) + rack-attack (4.4.1) + rack rack-test (0.6.3) rack (>= 1.0) rails (4.2.6) @@ -314,7 +319,7 @@ GEM rake (11.1.2) redcarpet (3.3.4) referer-parser (0.3.0) - request_store (1.3.0) + request_store (1.3.1) responders (2.1.2) railties (>= 4.2.0, < 5.1) rinku (1.7.3) @@ -343,6 +348,8 @@ GEM rspec-support (3.4.1) ruby-progressbar (1.7.5) safe_yaml (1.0.4) + safely_block (0.1.0) + errbase sass (3.4.22) sass-rails (5.0.4) railties (>= 4.0.0, < 5.0) @@ -432,7 +439,7 @@ PLATFORMS DEPENDENCIES acts-as-taggable-on acts_as_votable - ahoy_matey (~> 1.2.1) + ahoy_matey (~> 1.4.0) ancestry browser bullet @@ -451,7 +458,7 @@ DEPENDENCIES dalli database_cleaner delayed_job_active_record (~> 4.1.0) - devise (~> 3.5.6) + devise (~> 3.5.7) devise-async email_spec factory_girl_rails diff --git a/app/views/debates/show.html.erb b/app/views/debates/show.html.erb index b0aa58ce4..cfce656a2 100644 --- a/app/views/debates/show.html.erb +++ b/app/views/debates/show.html.erb @@ -56,7 +56,7 @@

    <%= t("debates.show.share") %>

    @@ -103,12 +103,6 @@ <%= spending_proposals_chart_tag id: "spending_proposals" %>
    -
    - <% @event_types.each do |event, count| %> -

    <%= event.titleize %> (<%= count %>)

    - <%= events_chart_tag event %> - <% end %> -
    From 4a013a65bc66f76bc8017002115d6870b35b73eb Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Tue, 19 Apr 2016 23:45:03 +0200 Subject: [PATCH 163/163] Fixes subnavigation layout --- app/views/layouts/_header.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index d791fe7b9..921532119 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -44,7 +44,7 @@
    -