Skip to content

friendly vault, snippet and user path, clean up controller, test#13

Open
mrvncaragay wants to merge 2 commits intocodervault:masterfrom
mrvncaragay:simple_path
Open

friendly vault, snippet and user path, clean up controller, test#13
mrvncaragay wants to merge 2 commits intocodervault:masterfrom
mrvncaragay:simple_path

Conversation

@mrvncaragay
Copy link
Copy Markdown
Contributor

No description provided.

def set_vault
@vault = params[:vault_id] ? Vault.find_by_id(params[:vault_id]) : Vault.find_by_id(params[:id])
redirect_to root_url if @vault.nil? || @vault.user_username != params[:username]
@vault = params[:vault_id] ? Vault.find_vault(params[:vault_id]) : Vault.find_vault(params[:id])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What happens if @vault is nil?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@CGA1123 def authenticate_username ... is called first. It checks if the user is valid and checks if the user owns the vault. Therefore, if the that pass no need to authenticate set_vault

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It seems unwise to couple those two methods together that closely.

It would make more sense to make set_vault check for correct ownership, do you not think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I see what you saying @CGA1123. is there trade-off going this way or is just a bad practice and should be avoided?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't know whether it's bad practice or not, it just seems more logical to keep the validation of vault in set_vault.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

okay, will update this change. the code below belongs to SalGant and i just moved it to application since they're both the same code.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You could still push those changes!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

just made an update. i remove the authenticate username and created a simple if..else if the action is show authenticate both @vault and @vault.user_username if not just authenticate @vault it is nil.

end

def check_edit_permissions
if @vault.user_id != current_user.id then
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Style guide prefers omitting the then.


def check_edit_permissions
if @vault.user_id != current_user.id then
flash[:alert] = t(:permissions_error)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You can write redirect_to root_url, alert: t(:permissions_error)

<div class="col-md-12">
<div class="panel panel-default panel-interactive">
<%= link_to "", vault_path(vault, username: vault.user.username), class: "overlay" %>
<%= link_to "", owner_vault_path(vault, username: vault.user.username), class: "overlay" %>
Copy link
Copy Markdown
Contributor

@CGA1123 CGA1123 Sep 30, 2016

Choose a reason for hiding this comment

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

Could use vault.user_username here, to keep things consistent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants