Skip to content

Commit

Permalink
Merge pull request #37 from OpenSourcePolitics/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
ludivinecp authored Feb 2, 2018
2 parents 95902f1 + f6a7ca0 commit ffffbfa
Show file tree
Hide file tree
Showing 49 changed files with 632 additions and 302 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def create_navbar_link
Decidim::NavbarLink.create!(
title: form.title,
link: form.link,
weight: form.weight,
target: form.target,
decidim_organization_id: form.organization_id
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def attributes
{
title: form.title,
link: form.link,
weight: form.weight,
target: form.target,
decidim_organization_id: form.organization_id
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ module Decidim
module Admin
# This controller allows admins to manage moderations in a participatory process.
class ModerationsController < Decidim::Admin::ApplicationController
helper_method :moderations
helper_method :downstream_moderations
helper_method :upstream_moderations


def index
authorize! :read, Decidim::Moderation
@upstream = true if params[:moderation_type] == "upstream"
Expand All @@ -22,6 +24,22 @@ def authorize
redirect_to moderations_path(moderation_type: "upstream", moderated: moderated)
end

def unreport
authorize! :unreport, reportable

Admin::UnreportResource.call(reportable) do
on(:ok) do
flash[:notice] = I18n.t("reportable.unreport.success", scope: "decidim.moderations.admin")
redirect_to moderations_path
end

on(:invalid) do
flash.now[:alert] = I18n.t("reportable.unreport.invalid", scope: "decidim.moderations.admin")
redirect_to moderations_path
end
end
end

# This action is use to hide or to set as refused moderated object
def hide
authorize! :hide, reportable
Expand All @@ -45,24 +63,25 @@ def hide
end
end

def unreport
authorize! :unreport, reportable

Admin::UnreportResource.call(reportable) do
on(:ok) do
flash[:notice] = I18n.t("reportable.unreport.success", scope: "decidim.moderations.admin")
redirect_to moderations_path
end
private

on(:invalid) do
flash.now[:alert] = I18n.t("reportable.unreport.invalid", scope: "decidim.moderations.admin")
redirect_to moderations_path
def moderations
@moderations ||= begin
if params[:hidden]
participatory_space_moderations.where.not(hidden_at: nil)
else
participatory_space_moderations.where(hidden_at: nil)
end
end
end

private
def reportable
@reportable ||= participatory_space_moderations.find(params[:id]).reportable
end

def participatory_space_moderations
@participatory_space_moderations ||= Decidim::Moderation.where(participatory_space: current_participatory_space)
end

def downstream_moderations
@downstream_moderations ||= begin
Expand All @@ -77,7 +96,7 @@ def downstream_moderations
def upstream_moderations
@upstream_moderations ||= begin
if params[:moderated] && params[:moderation_type] == "upstream"
filtered_upstream_moderations.where.not(upstream_moderation: "unmoderate").order("created_at").reverse
filtered_upstream_moderations.where("upstream_moderation = ? OR upstream_moderation = ?", "refused", "authorized").order("created_at").reverse
elsif params[:moderation_type] == "upstream"
filtered_upstream_moderations.where(upstream_moderation: "unmoderate").order("created_at").reverse
end
Expand All @@ -101,14 +120,6 @@ def get_features

features = Decidim::Feature.where(id: features.map(&:id), participatory_space: current_participatory_space)
end

def reportable
@reportable ||= participatory_space_moderations.find(params[:id]).reportable
end

def participatory_space_moderations
@participatory_space_moderations ||= Decidim::Moderation.where(participatory_space: current_participatory_space)
end
end
end
end
4 changes: 3 additions & 1 deletion decidim-admin/app/forms/decidim/admin/navbar_link_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ class NavbarLinkForm < Form

translatable_attribute :title, String
attribute :link, String
attribute :weight, Integer
attribute :organization_id, Integer
attribute :target, String

validates :link, :format => { :with => URI::regexp(%w(http https)) }, presence: true
validates :title, translatable_presence: true
validates :title, translatable_presence: true, presence: true
validates :weight, presence: true
validates :organization_id, :link, presence: true

end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
<div class="row column">
<%= form.translated :text_field, :title %>
<%= form.translated :text_field, :title, label: t(".title") %>
</div>

<div class="row">
<div class="columns xlarge-6">
<%= form.text_field :link, value: navbar_link.link || "http://" %>
<%= form.text_field :link, value: navbar_link.link || "http://", label: t(".link") %>
</div>
<div class="columns xlarge-6">
<%= form.radio_button :target, "blank", label: "Ouvrir sur un nouvel onglet" %>
<%= form.radio_button :target, "", label: "Ouvrir dans le même onglet" %>
<%= form.number_field :weight, value: navbar_link.weight, label: t(".weight") %>
</div>
<div class="columns xlarge-6">
<%= form.radio_button :target, "blank", label: t(".new_tab") %>
<%= form.radio_button :target, "", label: t(".same_tab") %>
</div>
<%= form.hidden_field :organization_id, value: current_organization.id %>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<thead>
<tr>
<th><%= t("models.navbar_link.fields.title", scope: "decidim.admin") %></th>
<th><%= t("models.navbar_link.fields.weight", scope: "decidim.admin") %></th>
<th><%= t("models.navbar_link.fields.link", scope: "decidim.admin") %></th>
<th></th>
</tr>
Expand All @@ -21,6 +22,9 @@
<td>
<%= translated_attribute(navbar_link.title) %>
</td>
<td>
<%= navbar_link.weight %>
</td>
<td>
<%= link_to navbar_link.link, navbar_link.link, target: :blank %>
</td>
Expand Down
8 changes: 8 additions & 0 deletions decidim-admin/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,10 @@ en:
fields:
title: Title
link: Link
weight: Weight
moderations:
index:
title: Moderations
title:
upstream: Upstream moderation
downstream: Downstream moderation
Expand Down Expand Up @@ -477,6 +479,12 @@ en:
title: Invite user as administrator
navbar_links:
no_links: No links created
form:
title: Title
link: Link
weight: Weight
new_tab: Open in a new tab
same_tab: Open in the same tab
new:
title: New navbar link
create: Create
Expand Down
8 changes: 8 additions & 0 deletions decidim-admin/config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,10 @@ fr:
fields:
title: Titre
link: Lien
weight: Position
moderations:
index:
title: Modérations
title:
upstream: Modération à priori
downstream: Modération à postériori
Expand Down Expand Up @@ -470,6 +472,12 @@ fr:
title: Inviter l'utilisateur en tant qu'administrateur
navbar_links:
no_links: Vous n'avez pas créé de lien
form:
title: Titre
link: Lien
weight: Poids
new_tab: Ouvrir sur un nouvel onglet
same_tab: Ouvrir dans le même onglet
new:
title: Nouveau lien de navigation
create: Créer
Expand Down
14 changes: 7 additions & 7 deletions decidim-api/app/controllers/decidim/api/queries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ def create

private

def store_current_user
Thread.current[:current_user] = current_user
yield
ensure
Thread.current[:current_user] = nil
end

def context
{
current_organization: current_organization,
Expand All @@ -40,6 +33,13 @@ def ensure_hash(query_variables)
query_variables
end
end

def store_current_user
Thread.current[:current_user] = current_user
yield
ensure
Thread.current[:current_user] = nil
end
end
end
end
4 changes: 2 additions & 2 deletions decidim-budgets/app/models/decidim/budgets/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ def comments_have_votes?
true
end

# Public: Overrides the `users_to_notify_on_comment_authorized` Commentable concern method.
def users_to_notify_on_comment_authorized
# Public: Overrides the `users_to_notify_on_comment_created` Commentable concern method.
def users_to_notify_on_comment_created # this method has been extended
followers
end

Expand Down
1 change: 1 addition & 0 deletions decidim-budgets/config/initializers/extends.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require "decidim/extends/project_extend.rb"
13 changes: 13 additions & 0 deletions decidim-budgets/lib/decidim/extends/project_extend.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module ProjectExtend
def users_to_notify_on_comment_created
get_all_users_with_role
end

def users_to_notify_on_comment_authorized
followers
end
end

Decidim::Budgets::Project.class_eval do
prepend(ProjectExtend)
end
17 changes: 6 additions & 11 deletions decidim-comments/app/commands/decidim/comments/create_comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def call

transaction do
create_comment
send_notification_to_moderators
send_notification
end

broadcast(:ok, @comment)
Expand All @@ -43,17 +43,17 @@ def create_comment
decidim_user_group_id: form.user_group_id)
end

def send_notification_to_moderators
def send_notification
recipient_ids = (@commentable.users_to_notify_on_comment_created - [@author]).pluck(:id)
recipient_ids += @author.followers.pluck(:id)

Decidim::EventsManager.publish(
event: "decidim.events.comments.comment_created",
event_class: Decidim::Comments::CommentCreatedEvent,
resource: @comment.root_commentable,
recipient_ids: recipient_ids.uniq,
extra: {
comment_id: @comment.id,
moderation_event: @comment.moderation.upstream_activated? ? true : false,
new_content: true,
process_slug: @comment.root_commentable.feature.participatory_space.slug
comment_id: @comment.id
}
)
end
Expand All @@ -62,11 +62,6 @@ def root_commentable(commentable)
return commentable.root_commentable if commentable.is_a? Decidim::Comments::Comment
commentable
end

def create_moderation
participatory_space_id = @comment.root_commentable.feature.participatory_space_id
Decidim::Moderation.create(decidim_participatory_space_id: participatory_space_id, decidim_reportable_type: @comment.class.name, decidim_reportable_id: @comment.id, decidim_participatory_space_type: "Decidim::ParticipatoryProcess")
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# frozen-string_literal: true

module Decidim
module Comments
class CommentAuthorizedEvent < Decidim::Events::BaseEvent
include Decidim::Events::EmailEvent
include Decidim::Events::NotificationEvent

def email_subject
I18n.t(
"decidim.comments.events.comment_authorized.#{comment_type}.email_subject",
resource_title: resource_title,
resource_url: resource_locator.url(url_params),
author_name: author.name
)
end

def email_intro
I18n.t(
"decidim.comments.events.comment_authorized.#{comment_type}.email_intro",
resource_title: resource_title
).html_safe
end

def email_outro
I18n.t(
"decidim.comments.events.comment_authorized.#{comment_type}.email_outro",
resource_title: resource_title
)
end

def notification_title
I18n.t(
"decidim.comments.events.comment_authorized.#{comment_type}.notification_title",
resource_title: resource_title,
resource_path: resource_locator.path(url_params),
author_nickname: author.nickname,
author_name: author.name,
author_path: author.profile_path
).html_safe
end

def email_url
I18n.t(
"decidim.comments.events.comment_authorized.#{comment_type}.url",
resource_url: resource_locator.url(url_params)
).html_safe
end

private

def author
@author ||= Decidim::UserPresenter.new(comment.author)
end

def comment
@comment ||= Decidim::Comments::Comment.find(extra[:comment_id])
end

def comment_type
comment.depth.zero? ? :comment : :reply
end

def url_params
comment_type == :comment ? {} : { anchor: "comment_#{comment.id}" }
end
end
end
end
Loading

0 comments on commit ffffbfa

Please sign in to comment.