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 4 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 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
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
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
4 changes: 4 additions & 0 deletions spec/features/budgets/investments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

feature 'Budget Investments' do

context "Concerns" do
it_behaves_like 'notifiable in-app', Budget::Investment
end

let(:author) { create(:user, :level_two, username: 'Isabel') }
let(:budget) { create(:budget, name: "Big Budget") }
let(:other_budget) { create(:budget, name: "What a Budget!") }
Expand Down
5 changes: 5 additions & 0 deletions spec/features/comments/legislation_questions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
include ActionView::Helpers::DateHelper

feature 'Commenting legislation questions' do

context "Concerns" do
it_behaves_like 'notifiable in-app', Legislation::Question
end

let(:user) { create :user, :level_two }
let(:process) { create :legislation_process, :in_debate_phase }
let(:legislation_question) { create :legislation_question, process: process }
Expand Down
5 changes: 5 additions & 0 deletions spec/features/debates_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
Setting['feature.debates'] = true
end

context "Concerns" do
it_behaves_like 'notifiable in-app', Debate
end

scenario 'Index' do
debates = [create(:debate), create(:debate), create(:debate)]

Expand Down Expand Up @@ -1111,4 +1115,5 @@
expect(page).to_not have_content("Featured")
end
end

end
6 changes: 6 additions & 0 deletions spec/features/legislation/proposals_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
require 'sessions_helper'

feature 'Legislation Proposals' do

context "Concerns" do
it_behaves_like 'notifiable in-app', Legislation::Proposal
end

let(:user) { create(:user) }
let(:user2) { create(:user) }
let(:process) { create(:legislation_process) }
Expand Down Expand Up @@ -55,4 +60,5 @@
def legislation_proposals_order
all("[id^='legislation_proposal_']").collect { |e| e[:id] }
end

end
Loading