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

User page: new following section #1750

Merged
merged 17 commits into from
Jul 24, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Do not display send notification button when proposal is from another…
… author.
  • Loading branch information
taitus authored and Senen committed Jul 13, 2017
commit b0c571e658e6e4c293e6a58e57ae0af1bb2d9062
9 changes: 2 additions & 7 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ class UsersController < ApplicationController
load_and_authorize_resource
helper_method :author?
helper_method :valid_interests_access?
helper_method :author_or_admin?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't really understand the reason to remove author_or_admin? method and its usage, can you explain a bit further? :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bertocq The main reason is that apparently it was not being used anywhere in the application.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 you're right, I did a project search and no use, although sometimes looking for the method string is not enough if you do compose de method name with a string interpolation like send("#{this}_or_#{that}") but that's not the case I guess based on the specs passing ^_^

Nice catch & cleanup 👏 😄


def show
load_filtered_activity if valid_access?
Expand Down Expand Up @@ -81,12 +80,8 @@ def valid_interests_access?
@user.public_interests || authorized_current_user?
end

def author?
@author ||= current_user && (current_user == @user)
end

def author_or_admin?
@author_or_admin ||= current_user && (author? || current_user.administrator?)
def author?(proposal)
proposal.author_id == current_user.id
end

def authorized_current_user?
Expand Down
2 changes: 1 addition & 1 deletion app/models/abilities/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def initialize(user)
can :create, Budget::Investment, budget: { phase: "accepting" }
can :suggest, Budget::Investment, budget: { phase: "accepting" }
can :destroy, Budget::Investment, budget: { phase: ["accepting", "reviewing"] }, author_id: user.id
can :vote, Budget::Investment, budget: { phase: "selecting" }
can :vote, Budget::Investment, budget: { phase: "selecting" }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^_^ /bertocq likes this

can [:show, :create], Budget::Ballot, budget: { phase: "balloting" }
can [:create, :destroy], Budget::Ballot::Line, budget: { phase: "balloting" }

Expand Down
4 changes: 2 additions & 2 deletions app/views/users/_proposal.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
<%= proposal.summary %>
</td>

<% if can? :retire_form, proposal %>
<% if author?(proposal) %>
<td class="text-center">
<%= link_to t("users.proposals.send_notification"),
new_proposal_notification_path(proposal_id: proposal.id),
class: 'button hollow' %>
</td>
<% end %>

<% if can? :new, ProposalNotification, author_id: proposal.author_id %>
<% if author?(proposal) || proposal.retired? %>
Copy link
Collaborator

@bertocq bertocq Jul 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It took me a bit to understand all the conditionals around this block and realize there is only 2 scenarios. Maybe this could be easier to read:

<% if proposal.retired? %>
 <td class="text-center">
  <span class="label alert"><%= t('users.proposals.retired') %></span>
 </td>
<% elsif author?(proposal) %>
 <td class="text-center">
   <%= link_to t('users.proposals.retire'),
               retire_form_proposal_path(proposal),
               class: 'button hollow alert' %>
 </td>
<% end %>

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally agree @bertocq! We will make this change too!

<td class="text-center">
<% if proposal.retired? %>
<span class="label alert"><%= t('users.proposals.retired') %></span>
Expand Down