adds link to send message from my activity

This commit is contained in:
rgarcia
2016-06-01 21:01:24 +02:00
parent f5375e813d
commit 6e4ed0b895
5 changed files with 58 additions and 10 deletions

View File

@@ -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?

View File

@@ -7,17 +7,24 @@
<%= proposal.summary %>
</td>
<% if author? %>
<td class="text-center">
<%= link_to t("users.proposals.send_message"), new_proposal_notification_path(proposal_id: proposal.id) %>
</td>
<% end %>
<% if author_or_admin? %>
<td class="text-center">
<% if proposal.retired? %>
<span class="label alert"><%= t('users.show.retired') %></span>
<span class="label alert"><%= t('users.proposals.retired') %></span>
<% else %>
<%= link_to t('users.show.retire'),
<%= link_to t('users.proposals.retire'),
retire_form_proposal_path(proposal),
class: 'delete' %>
<% end %>
</td>
<% end %>
</tr>
<% end %>
</table>

View File

@@ -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}.

View File

@@ -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}.

View File

@@ -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)