diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index af4005e06..fbd77f184 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -3,6 +3,7 @@ class UsersController < ApplicationController
load_and_authorize_resource
helper_method :authorized_for_filter?
+ helper_method :author?
helper_method :author_or_admin?
def show
@@ -65,8 +66,12 @@ class UsersController < ApplicationController
@user.public_activity || authorized_current_user?
end
+ def author?
+ @author ||= current_user && (current_user == @user)
+ end
+
def author_or_admin?
- @author_or_admin ||= current_user && (current_user == @user || current_user.administrator?)
+ @author_or_admin ||= current_user && (author? || current_user.administrator?)
end
def authorized_current_user?
diff --git a/app/views/users/_proposals.html.erb b/app/views/users/_proposals.html.erb
index e0b54dcc4..d23e865ca 100644
--- a/app/views/users/_proposals.html.erb
+++ b/app/views/users/_proposals.html.erb
@@ -7,17 +7,24 @@
<%= proposal.summary %>
+ <% if author? %>
+
+ <%= link_to t("users.proposals.send_message"), new_proposal_notification_path(proposal_id: proposal.id) %>
+ |
+ <% end %>
+
<% if author_or_admin? %>
<% if proposal.retired? %>
- <%= t('users.show.retired') %>
+ <%= t('users.proposals.retired') %>
<% else %>
- <%= link_to t('users.show.retire'),
+ <%= link_to t('users.proposals.retire'),
retire_form_proposal_path(proposal),
class: 'delete' %>
<% end %>
|
<% end %>
+
<% end %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 725e8d08b..40407f3fc 100755
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -510,8 +510,10 @@ en:
other: "%{count} Spending proposals"
no_activity: User has no public activity
private_activity: This user decided to keep the activity list private
- retire: Retire
- retired: Retired
+ proposals:
+ send_message: "Send message"
+ retire: "Retire"
+ retired: "Retired"
votes:
agree: I agree
anonymous: Too many anonymous votes to admit vote %{verify_account}.
diff --git a/config/locales/es.yml b/config/locales/es.yml
index 840dcf705..4c26d7561 100755
--- a/config/locales/es.yml
+++ b/config/locales/es.yml
@@ -510,8 +510,10 @@ es:
other: "%{count} Propuestas de inversión"
no_activity: Usuario sin actividad pública
private_activity: Este usuario ha decidido mantener en privado su lista de actividades
- retire: Retirar
- retired: Retirada
+ proposals:
+ send_message: "Enviar mensaje"
+ retire: "Retirar"
+ retired: "Retirada"
votes:
agree: Estoy de acuerdo
anonymous: Demasiados votos anónimos, para poder votar %{verify_account}.
diff --git a/spec/features/proposal_notifications_spec.rb b/spec/features/proposal_notifications_spec.rb
index 756fc3fdd..d10beb6f4 100644
--- a/spec/features/proposal_notifications_spec.rb
+++ b/spec/features/proposal_notifications_spec.rb
@@ -6,9 +6,17 @@ feature 'Proposal Notifications' do
noelia = create(:user)
vega = create(:user)
- proposal = create(:proposal)
- #use correct path from my activity
- visit new_proposal_notification_path(proposal_id: proposal.id)
+ author = create(:user)
+ proposal = create(:proposal, author: author)
+
+ login_as(author)
+ visit root_path
+
+ click_link "My activity"
+
+ within("#proposal_#{proposal.id}") do
+ click_link "Send message"
+ end
fill_in 'proposal_notification_title', with: "Thank you for supporting my proposal"
fill_in 'proposal_notification_body', with: "Please share it with others so we can make it happen!"
@@ -19,6 +27,30 @@ feature 'Proposal Notifications' do
expect(page).to have_content "Please share it with others so we can make it happen!"
end
+ context "Permissions" do
+
+ scenario "Link to send the message" do
+ user = create(:user)
+ author = create(:user)
+ proposal = create(:proposal, author: author)
+
+ login_as(author)
+ visit user_path(author)
+
+ within("#proposal_#{proposal.id}") do
+ expect(page).to have_link "Send message"
+ end
+
+ login_as(user)
+ visit user_path(author)
+
+ within("#proposal_#{proposal.id}") do
+ expect(page).to_not have_link "Send message"
+ end
+ end
+
+ end
+
scenario "Error messages" do
proposal = create(:proposal)