-
Notifications
You must be signed in to change notification settings - Fork 1
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
Url validation and Authorisation #48
Open
Nimmyjv
wants to merge
25
commits into
master
Choose a base branch
from
feat-rankhub
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
f04521a
Add validators folder, url validation
NimmyVipin 16e87d1
Authorize collection added by each user with pundit gem
NimmyVipin 55b69bb
Modify as run pronto
NimmyVipin 95b2f2d
Authorization moved from service to controller
NimmyVipin 2a7915c
Edit rubocop.yml to avoid frozenstringliteralwarnings
NimmyVipin 494e5e8
Modify method to add protocol to url
NimmyVipin abf759e
Fix rubocop warnings
NimmyVipin dde10d5
Correct method name
NimmyVipin f32a6b6
Remove query to delete from join table
NimmyVipin 8695d57
Modify authorize method
NimmyVipin b074c36
change https to http
NimmyVipin 1c1ee84
Destroy collectionWebsites also when collection deleted
NimmyVipin 9229cf7
To check if same url is added to a single list.For eg; earlier when r…
NimmyVipin 93f18c8
In Rails 5, redirect_to :back has been deprecated and instead a new m…
NimmyVipin cc68662
Add tool tips in multiple list page
NimmyVipin 917f122
Edit rubocop file to ignore regex literal
NimmyVipin f370efd
change redirection path
NimmyVipin 1fa8094
Spacing correction
NimmyVipin 2528f30
Solve error while run rake db:seed
NimmyVipin 9516584
Modify test file to fix failures
NimmyVipin 89dff22
Run pronto
NimmyVipin 0dbd52d
Code refactored
NimmyVipin ed02b10
Indentation corrected
NimmyVipin 19a9a7d
change name
NimmyVipin 1a53955
remove return value
NimmyVipin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
class Collection < ApplicationRecord | ||
belongs_to :user | ||
|
||
has_many :collection_websites, dependent: :destroy | ||
has_many :websites, through: :collection_websites | ||
|
||
validates :name, presence: true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class CollectionPolicy < ApplicationPolicy | ||
def destroy? | ||
record.user == user | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class UrlValidator < ActiveModel::EachValidator | ||
def validate_each(record, attribute, value) | ||
uri = URI.parse(value) | ||
record.errors.add(attribute, 'is invalid') unless valid_url?(uri) | ||
end | ||
|
||
private | ||
|
||
def valid_url?(uri) | ||
uri && valid_host?(uri.host) | ||
rescue URI::InvalidURIError | ||
false | ||
end | ||
|
||
def valid_host?(host) | ||
host.present? && valid_characters?(host) | ||
end | ||
|
||
def valid_characters?(host) | ||
!host[/[\s\!\\"$%&'\(\)*+_,:;<=>?@\[\]^|£§°ç\/]/] && host.include?('.') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,27 @@ | ||
<nav id="mainNav" class="navbar navbar-default navbar-fixed-top collections-login-navbar"> | ||
<div class="container"> | ||
<div class="navbar-header"> | ||
|
||
<%= link_to 'RankHub',root_path, class:"navbar-brand page-scroll collections-navbar-icon" %> | ||
</div> | ||
<% if user_signed_in? %> | ||
<nav> | ||
<ul class="nav navbar-nav navbar-right"> | ||
<div class="dropdown collections-navbar-right"> | ||
|
||
<li data-toggle="dropdown"> | ||
<%= link_to current_user.email, root_path, class:'load collections-navbar-links' %> | ||
<span class = "caret dropdown-arrow"></span> | ||
<li data-toggle="dropdown"> | ||
<%= link_to current_user.email, root_path, class:'load collections-navbar-links' %> | ||
<span class = "caret dropdown-arrow"></span> | ||
</li> | ||
<ul class="dropdown-menu load collections-navbar-right-links"> | ||
<li> | ||
<%= link_to 'Account Management', edit_user_registration_path %> | ||
</li> | ||
<ul class="dropdown-menu load collections-navbar-right-links"> | ||
<li> | ||
<%= link_to 'Account Management', edit_user_registration_path %> | ||
</li> | ||
<li> | ||
<%= link_to 'Log Out', destroy_user_session_path, method: :delete %> | ||
</li> | ||
</ul> | ||
<li> | ||
<%= link_to 'Log Out', destroy_user_session_path, method: :delete %> | ||
</li> | ||
</ul> | ||
</div> | ||
</ul> | ||
</nav> | ||
|
||
<% end %> | ||
<% end %> | ||
</div> | ||
</nav> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,3 @@ | ||
|
||
|
||
|
||
|
||
<div class="modal fade" id="demo1" role="dialog" aria-hidden="true"> | ||
<div class="modal-dialog modal-sm"> | ||
<div class="modal-content"> | ||
|
@@ -16,9 +12,9 @@ | |
</div> | ||
<div class="col-md-3"> | ||
<%= f.hidden_field :user_id, value: current_user.id %> | ||
<%= f.submit "Add", class: 'btn btn-success btn-sm btn pull-right'%> | ||
<%= f.submit "Add", class: 'btn btn-success btn-sm btn pull-right'%> | ||
</div> | ||
<% end %> | ||
<% end %> | ||
</div> | ||
</div> | ||
</div> | ||
|
@@ -29,71 +25,62 @@ | |
<div class="rows sidebar-section"> | ||
<div id="mySidenav" class="sidenav sidebar-list"> | ||
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">×</a> | ||
<button class="accordion " data-toggle="collapse" data-toggle="collapse" data-target="#demo">Lists</button> | ||
<button class="accordion " data-toggle="collapse" data-toggle="collapse" data-target="#demo" data-toggle="tooltip" data-placement="top" title="Add new list">Lists</button> | ||
<div id="demo" class="collapse sidebar-collapse"> | ||
<% collection_nil = [] %> | ||
<% @urls.each do |url| %> | ||
<% if url.collection_ids.nil? %> | ||
<% collection_nil << url.id %> | ||
<% end %> | ||
<% end %> | ||
<% if collection_nil.empty? %> | ||
<% @collection_names.any? %><br> | ||
<div class="panel-group sub-list" id="accordion"> | ||
<% @collection_names.each_with_index do |collect, index| %> | ||
<a data-toggle="collapse" data-parent="#accordion" href="#collapse<%= index+1 %>" onclick="showListWiseGraph(<%= collect.id %>, <%= index %>)" id="collection<%= index %>"> | ||
<h4> | ||
<%= collect.name %> | ||
</h4> | ||
</a> | ||
<%= link_to "Delete", collection_path(collect.id), | ||
data: { confirm: "Are you sure?" }, class: 'remove-list',method: :delete %> | ||
<div id="collapse<%= index+1 %>" class="panel-collapse collapse"> | ||
<div class="panel-body"> | ||
<div class="row"> | ||
<%= form_for (@website) do |f| %> | ||
<div class="col-md-9"> | ||
|
||
<%= f.text_field :url, id:'url_id', class:'form-control',placeholder:"Add Domain" %> | ||
<% end %> | ||
<% end %> | ||
<% if collection_nil.empty? %> | ||
<% @collection_names.any? %> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this do? It just seems to return true or false and render nothing. |
||
<br> | ||
<div class="panel-group sub-list" id="accordion"> | ||
<% @collection_names.each_with_index do |collect, index| %> | ||
<a data-toggle="collapse" data-parent="#accordion" href="#collapse<%= index+1 %>" onclick="showListWiseGraph(<%= collect.id %>, <%= index %>)" id="collection<%= index %>" data-toggle="tooltip" data-placement="top" title="Click to add domain"><h4><%= collect.name %></h4></a> | ||
<%= link_to "Delete", collection_path(collect.id), data: { confirm: "Are you sure?" }, | ||
class: 'remove-list',method: :delete %> | ||
<div id="collapse<%= index+1 %>" class="panel-collapse collapse"> | ||
<div class="panel-body"> | ||
<div class="row"> | ||
<%= form_for (@website) do |f| %> | ||
<div class="col-md-9"> | ||
<%= f.text_field :url, id:'url_id', class:'form-control',placeholder:"Add Domain" %> | ||
<%= f.hidden_field :collection_id, value: collect.id%> | ||
<%= f.hidden_field :current_user, value: current_user.id%> | ||
|
||
</div> | ||
<div class="col-md-3"> | ||
<%= f.submit "Add", class: ' btn btn-success btn-sm btn pull-right'%> | ||
</div> | ||
<% end %> | ||
<%= render partial: "domain", locals: { collect: collect } %> | ||
</div> | ||
</div> | ||
</div> | ||
<% end %> | ||
</div> | ||
<a class="add-newlist" data-toggle="modal" data-target="#demo1">Add new list</a> | ||
</div> | ||
</div> | ||
|
||
<div id="main"> | ||
<span onclick="openNav()">☰</span> | ||
|
||
</div> | ||
<div class="col-md-3"> | ||
<%= f.submit "Add", class: ' btn btn-success btn-sm btn pull-right'%> | ||
</div> | ||
<% end %> | ||
<%= render partial: "domain", locals: { collect: collect } %> | ||
</div> | ||
</div> | ||
</div> | ||
<% end %> | ||
</div> | ||
<a class="add-newlist" data-toggle="modal" data-target="#demo1" data-toggle="tooltip" data-placement="top" title="Click me">Add new list</a> | ||
</div> | ||
</div> | ||
<div id="main"> | ||
<span onclick="openNav()" data-toggle="tooltip" data-placement="top" title="Open side bar">☰ | ||
</span> | ||
</div> | ||
<div class="col-md-5"> | ||
<div class="row url-flash-message"> | ||
<% if flash[:error] %> | ||
<div class="alert alert-danger"> | ||
<%= flash[:error]%> | ||
<div class="row url-flash-message"> | ||
<% if flash[:error] %> | ||
<div class="alert alert-danger"> | ||
<%= flash[:error]%> | ||
</div> | ||
<% end %> | ||
</div> | ||
<% end %> | ||
</div> | ||
</div> | ||
|
||
<div class="col-md-7 show-graph" id="graph"></div> | ||
|
||
</div> | ||
<div class="col-md-7 show-graph" id="graph"></div> | ||
</div> | ||
<% else %> | ||
<%= render 'check' %> | ||
<% end %> | ||
|
||
<% end %> | ||
</div> | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Trailing whitespace, and unnecessary 2nd blank line. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing space.