Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upstream #1060

Merged
merged 21 commits into from
Dec 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
56a7c46
adds timestamps to polls
voodoorai2000 Dec 13, 2017
c14f9be
Add 'publication_date' attribute to Budget::Investment::Milestone
aitbw Dec 12, 2017
6d57d76
Admins can add a 'publication date' to milestones
aitbw Dec 13, 2017
03ae14c
End-users will be shown a milestone's publication date if available
aitbw Dec 13, 2017
1e1028d
Adapt existing milestone-related specs to fit the new requirement
aitbw Dec 13, 2017
01a8c55
Make Budget::Investment::Milestone class Documentable.
Dec 14, 2017
ff50dc1
Add feature specs to test new admin features and documents' show in u…
Dec 14, 2017
7399e5f
Update unreleased section of Changelog
bertocq Dec 14, 2017
50b4f50
Merge branch 'master' into aperez-dates-for-milestones
bertocq Dec 14, 2017
2b52d26
refactors notifications into concerns and shared examples
voodoorai2000 Dec 14, 2017
e675cee
Merge branch 'master' into aperez-dates-for-milestones
decabeza Dec 14, 2017
09b5447
Merge pull request #2191 from wairbut-m2c/iagirre-add-documents-to-mi…
decabeza Dec 14, 2017
1737f85
Merge branch 'master' into aperez-dates-for-milestones
decabeza Dec 14, 2017
76a3dd5
Merge branch 'master' into aperez-dates-for-milestones
decabeza Dec 14, 2017
b4782f7
delete unnecessary parenthesis
decabeza Dec 14, 2017
a46863a
Merge pull request #2188 from wairbut-m2c/aperez-dates-for-milestones
decabeza Dec 14, 2017
23eaffc
Merge remote-tracking branch 'upstream/master' into upstream
decabeza Dec 14, 2017
9ba8ca7
Merge pull request #2187 from consul/notifications
voodoorai2000 Dec 14, 2017
3f7484d
fixes conflicts with upstream
voodoorai2000 Dec 14, 2017
bf86eea
Merge branch 'master' into upstream
voodoorai2000 Dec 15, 2017
1e1ab12
Merge pull request #1061 from AyuntamientoMadrid/notifications
voodoorai2000 Dec 15, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http:https://semver.org/spec/v2.0.0.
### Changed
- Design improvements https://github.com/consul/consul/pull/2170
- Adds timestamps to polls https://github.com/consul/consul/pull/2180 (Run `rake polls:initialize_timestamps` to initialize attributes created_at and updated_at with the current time for all existing polls, or manually through console set correct values)
- Improved Community design https://github.com/consul/consul/pull/1904

### Deprecated

Expand Down
3 changes: 2 additions & 1 deletion app/assets/stylesheets/participation.scss
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,8 @@
.draft-panels,
.debate-questions,
.communities-show,
.topic-show {
.topic-show,
.milestone-content {

p {
word-wrap: break-word;
Expand Down
19 changes: 11 additions & 8 deletions app/controllers/admin/budget_investment_milestones_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def create
@milestone = Budget::Investment::Milestone.new(milestone_params)
@milestone.investment = @investment
if @milestone.save
redirect_to admin_budget_budget_investment_path(@investment.budget, @investment), notice: t('admin.milestones.create.notice')
redirect_to admin_budget_budget_investment_path(@investment.budget, @investment),
notice: t('admin.milestones.create.notice')
else
render :new
end
Expand All @@ -25,32 +26,34 @@ def edit

def update
if @milestone.update(milestone_params)
redirect_to admin_budget_budget_investment_path(@investment.budget, @investment), notice: t('admin.milestones.update.notice')
redirect_to admin_budget_budget_investment_path(@investment.budget, @investment),
notice: t('admin.milestones.update.notice')
else
render :edit
end
end

def destroy
@milestone.destroy
redirect_to admin_budget_budget_investment_path(@investment.budget, @investment), notice: t('admin.milestones.delete.notice')
redirect_to admin_budget_budget_investment_path(@investment.budget, @investment),
notice: t('admin.milestones.delete.notice')
end

private

def milestone_params
params.require(:budget_investment_milestone)
.permit(:title, :description, :budget_investment_id,
image_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy])
.permit(:title, :description, :publication_date, :budget_investment_id,
image_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy],
documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy])
end

def load_budget_investment
@investment = Budget::Investment.find params[:budget_investment_id]
@investment = Budget::Investment.find(params[:budget_investment_id])
end

def load_budget_investment_milestone
@milestone = Budget::Investment::Milestone.find params[:id]
@milestone = Budget::Investment::Milestone.find(params[:id])
end


end
1 change: 1 addition & 0 deletions app/models/budget/investment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Investment < ActiveRecord::Base
acts_as_paranoid column: :hidden_at
include ActsAsParanoidAliases
include Relationable
include Notifiable

belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
belongs_to :heading
Expand Down
5 changes: 5 additions & 0 deletions app/models/budget/investment/milestone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ class Budget
class Investment
class Milestone < ActiveRecord::Base
include Imageable
include Documentable
documentable max_documents_allowed: 3,
max_file_size: 3.megabytes,
accepted_content_types: [ "application/pdf" ]

belongs_to :investment

validates :title, presence: true
validates :investment, presence: true
validates :publication_date, presence: true

def self.title_max_length
80
Expand Down
3 changes: 2 additions & 1 deletion app/models/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ class Comment < ActiveRecord::Base
include Flaggable
include HasPublicAuthor
include Graphqlable
include Notifiable

COMMENTABLE_TYPES = %w(Debate Proposal Budget::Investment Poll::Question Legislation::Question Legislation::Proposal Legislation::Annotation Topic SpendingProposal ProbeOption Poll).freeze
COMMENTABLE_TYPES = %w(Debate Proposal Budget::Investment Poll Poll::Question Topic Legislation::Question Legislation::Annotation Legislation::Proposal SpendingProposal ProbeOption).freeze

acts_as_paranoid column: :hidden_at
include ActsAsParanoidAliases
Expand Down
35 changes: 35 additions & 0 deletions app/models/concerns/notifiable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module Notifiable
extend ActiveSupport::Concern

def notifiable_title
case self.class.name
when "ProposalNotification"
proposal.title
when "Comment"
commentable.title
else
title
end
end

def notifiable_available?
case self.class.name
when "ProposalNotification"
check_availability(proposal)
when "Comment"
check_availability(commentable)
else
check_availability(self)
end
end

def check_availability(resource)
resource.present? &&
resource.try(:hidden_at) == nil &&
resource.try(:retired_at) == nil
end

def linkable_resource
is_a?(ProposalNotification) ? proposal : self
end
end
1 change: 1 addition & 0 deletions app/models/debate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Debate < ActiveRecord::Base
include HasPublicAuthor
include Graphqlable
include Relationable
include Notifiable

acts_as_votable
acts_as_paranoid column: :hidden_at
Expand Down
1 change: 1 addition & 0 deletions app/models/legislation/proposal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Legislation::Proposal < ActiveRecord::Base
include Followable
include Communitable
include Documentable
include Notifiable

documentable max_documents_allowed: 3,
max_file_size: 3.megabytes,
Expand Down
1 change: 1 addition & 0 deletions app/models/legislation/question.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class Legislation::Question < ActiveRecord::Base
acts_as_paranoid column: :hidden_at
include ActsAsParanoidAliases
include Notifiable

belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
belongs_to :process, class_name: 'Legislation::Process', foreign_key: 'legislation_process_id'
Expand Down
21 changes: 5 additions & 16 deletions app/models/notification.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class Notification < ActiveRecord::Base

belongs_to :user, counter_cache: true
belongs_to :notifiable, polymorphic: true

Expand All @@ -7,6 +8,9 @@ class Notification < ActiveRecord::Base
scope :not_emailed, -> { where(emailed_at: nil) }
scope :for_render, -> { includes(:notifiable) }

delegate :notifiable_title, :notifiable_available?, :check_availability, :linkable_resource,
to: :notifiable, allow_nil: true

def timestamp
notifiable.created_at
end
Expand All @@ -25,17 +29,6 @@ def self.add(user_id, notifiable)
end
end

def notifiable_title
case notifiable.class.name
when "ProposalNotification"
notifiable.proposal.title
when "Comment"
notifiable.commentable.title
else
notifiable.title
end
end

def notifiable_action
case notifiable_type
when "ProposalNotification"
Expand All @@ -47,8 +40,4 @@ def notifiable_action
end
end

def linkable_resource
notifiable.is_a?(ProposalNotification) ? notifiable.proposal : notifiable
end

end
end
1 change: 1 addition & 0 deletions app/models/poll.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class Poll < ActiveRecord::Base
include Imageable
acts_as_paranoid column: :hidden_at
include ActsAsParanoidAliases
include Notifiable

RECOUNT_DURATION = 1.week

Expand Down
1 change: 1 addition & 0 deletions app/models/proposal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Proposal < ActiveRecord::Base
include Communitable
include Imageable
include Mappable
include Notifiable
include Documentable
documentable max_documents_allowed: 3,
max_file_size: 3.megabytes,
Expand Down
6 changes: 5 additions & 1 deletion app/models/proposal_notification.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class ProposalNotification < ActiveRecord::Base

include Graphqlable
include Notifiable

belongs_to :author, class_name: 'User', foreign_key: 'author_id'
belongs_to :proposal
Expand Down Expand Up @@ -35,4 +35,8 @@ def public_for_api?
return true
end

def notifiable
proposal
end

end
1 change: 1 addition & 0 deletions app/models/topic.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class Topic < ActiveRecord::Base
acts_as_paranoid column: :hidden_at
include ActsAsParanoidAliases
include Notifiable

belongs_to :community
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
Expand Down
9 changes: 9 additions & 0 deletions app/views/admin/budget_investment_milestones/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@

<%= f.text_field :title, maxlength: Budget::Investment::Milestone.title_max_length %>
<%= f.text_area :description, rows: 5 %>
<%= f.text_field :publication_date,
value: @milestone.publication_date.present? ? l(@milestone.publication_date.to_date) : nil,
class: "js-calendar-full" %>

<%= render 'images/admin_image', imageable: @milestone, f: f %>

<hr>
<div class="documents">
<%= render 'documents/nested_documents', documentable: @milestone, f: f %>
</div>

<%= f.submit nil, class: "button success" %>
<% end %>
39 changes: 28 additions & 11 deletions app/views/admin/budget_investments/_milestones.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,53 @@
<th><%= t("admin.milestones.index.table_id") %></th>
<th><%= t("admin.milestones.index.table_title") %></th>
<th><%= t("admin.milestones.index.table_description") %></th>
<th><%= t("admin.milestones.index.table_publication_date") %></th>
<th><%= t("admin.milestones.index.image") %></th>
<th><%= t("admin.milestones.index.documents") %></th>
<th><%= t("admin.milestones.index.table_actions") %></th>
</tr>
</thead>
<tbody>
<% @investment.milestones.each do |milestone| %>
<tr id="<%= dom_id(milestone) %>" class="milestone">
<td><%= milestone.id %></td>
<td>
<%= milestone.id %>
</td>
<td>
<%= link_to milestone.title, edit_admin_budget_budget_investment_budget_investment_milestone_path(@investment.budget, @investment, milestone) %>
<%= link_to milestone.title,
edit_admin_budget_budget_investment_budget_investment_milestone_path(@investment.budget,
@investment,
milestone) %>
</td>
<td class="small"><%= milestone.description %></td>
<% if milestone.publication_date.present? %>
<td class="small"><%= l(milestone.publication_date.to_date) %></td>
<% end %>
<td class="small">
<%= milestone.description %>
<%= link_to t("admin.milestones.index.show_image"),
milestone.image_url(:large),
target: :_blank if milestone.image.present? %>
</td>
<td class="small">
<%= link_to t("admin.milestones.index.show_image"), milestone.image_url(:large), target: :_blank if milestone.image.present? %>
<% if milestone.documents.present? %>
<% milestone.documents.each do |document| %>
<%= link_to document.title,
document.attachment.url,
target: "_blank",
rel: "" %><br>
<% end %>
<% end %>
</td>
<td>
<%= link_to t("admin.milestones.index.delete"), admin_budget_budget_investment_budget_investment_milestone_path(@investment.budget, @investment, milestone),
<%= link_to t("admin.milestones.index.delete"),
admin_budget_budget_investment_budget_investment_milestone_path(@investment.budget,
@investment,
milestone),
method: :delete,
class: 'button hollow alert expanded' %>
class: "button hollow alert expanded" %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% else %>
<p>
<%= t('admin.milestones.index.no_milestones') %>
</p>
<p><%= t("admin.milestones.index.no_milestones") %></p>
<% end %>
25 changes: 21 additions & 4 deletions app/views/budgets/investments/_milestones.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,28 @@
<li>
<div class="milestone-content">
<h3><%= milestone.title %></h3>
<span class="milestone-date">
<strong><%= t("budgets.investments.show.milestone_publish_date", publish_date: l(milestone.created_at.to_date)) %></strong>
</span>
<%= image_tag(milestone.image_url(:large), {alt: milestone.image.title, class: "margin", id: "image_#{milestone.id}"}) if milestone.image.present? %>
<% if milestone.publication_date.present? %>
<span class="milestone-date">
<strong><%= t("budgets.investments.show.milestone_publication_date",
publication_date: l(milestone.publication_date.to_date)) %></strong>
</span>
<% end %>
<%= image_tag(milestone.image_url(:large), { alt: milestone.image.title, class: "margin", id: "image_#{milestone.id}" }) if milestone.image.present? %>
<p><%= milestone.description %></p>
<% if milestone.documents.present? %>
<div class="document-link text-center">
<p>
<span class="icon-document"></span>&nbsp;
<strong><%= t('proposals.show.title_external_url') %></strong>
</p>
<% milestone.documents.each do |document| %>
<%= link_to document.title,
document.attachment.url,
target: "_blank",
rel: "" %><br>
<% end %>
</div>
<% end %>
</div>
</li>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/comments/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<%= f.hidden_field :commentable_id, value: commentable.id %>
<%= f.hidden_field :parent_id, value: parent_id %>

<%= f.submit comment_button_text(parent_id, commentable), class: "button" %>
<%= f.submit comment_button_text(parent_id, commentable), class: "button", id: "publish_comment" %>

<% if can? :comment_as_moderator, commentable %>
<div class="float-right">
Expand Down
2 changes: 1 addition & 1 deletion app/views/devise/menu/_login_items.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% if user_signed_in? %>
<li>
<li id="notifications">
<%= link_to notifications_path, rel: "", class: "notifications" do %>
<span class="show-for-sr"><%= t("layouts.header.notifications") %></span>
<% if current_user.notifications_count > 0 %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/notifications/_notification.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<li id="<%= dom_id(notification) %>" class="notification">
<% if notification.notifiable.present? %>
<% if notification.notifiable_available? %>
<%= link_to notification do %>
<p>
<em>
Expand Down
1 change: 1 addition & 0 deletions config/locales/en/activerecord.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ en:
budget/investment/milestone:
title: "Title"
description: "Description"
publication_date: "Publication date"
comment:
body: "Comment"
user: "User"
Expand Down
Loading