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

Master -> production #320

Merged
merged 28 commits into from
Jun 9, 2020
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
b7f3794
Add route for public signs
trevh-ack Apr 26, 2020
3f56035
Add controller for public signs (index only)
trevh-ack Apr 26, 2020
38b4b85
Add public sign service
trevh-ack Apr 26, 2020
8983030
Add sql for public signs
trevh-ack Apr 26, 2020
610b78d
Add view (index template) for public signs
trevh-ack Apr 26, 2020
a718463
From home page link to public signs
trevh-ack Apr 26, 2020
a933cf7
Spec update
trevh-ack Apr 26, 2020
379b618
Spec for public signs service
trevh-ack Apr 27, 2020
5f7113a
Merge pull request #317 from ackama/feature/ncg-286-all-signs
trevh-ack May 11, 2020
7d6f6cc
Update rails due to security vulnerabilities
May 20, 2020
cf31d39
Merge pull request #319 from ackama/security-updates-CVE-2020-8162-CV…
CaraHill May 20, 2020
2d5c077
chore: replace `sass-lint` with `stylelint`
G-Rath Apr 8, 2020
5193135
chore: run `yarn upgrade`
G-Rath Apr 9, 2020
c0ab72b
ci: remove yarn integrity check
G-Rath Apr 9, 2020
c2b130d
chore: update `webdrivers`
G-Rath Jun 1, 2020
c5bad90
chore: update `kaminari`
G-Rath Jun 2, 2020
503ab4a
chore: update `puma`
G-Rath Jun 2, 2020
f38d1e0
Handle request for asset manifest
joshmcarthur Jun 7, 2020
737c2a7
Update rubocop to 0.85
joshmcarthur Jun 7, 2020
6c9ff56
Automated rubocop fixes for 0.85
joshmcarthur Jun 7, 2020
64a3ca7
chore: update `websocket-extensions`
G-Rath Jun 7, 2020
7c14354
chore: run `yarn upgrade`
G-Rath Jun 7, 2020
23fa1cd
Order routes correctly so that asset-manifest.json route comes before…
joshmcarthur Jun 8, 2020
6e5bca4
Merge branch 'security-updates' of gh:ackama/nzsl-share into security…
joshmcarthur Jun 8, 2020
6d22b3b
Merge pull request #314 from ackama/security-updates
joshmcarthur Jun 8, 2020
71c9f93
chore: upgrade lighthouse
G-Rath Jun 8, 2020
657d0c2
Update headings to be in descending order to resolve new accessibilit…
joshmcarthur Jun 9, 2020
c6380f5
Merge pull request #324 from ackama/upgrade-lighthouse
joshmcarthur Jun 9, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
110 changes: 55 additions & 55 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,61 +3,61 @@ GEM
specs:
aasm (5.0.6)
concurrent-ruby (~> 1.0)
actioncable (6.0.2.2)
actionpack (= 6.0.2.2)
actioncable (6.0.3.1)
actionpack (= 6.0.3.1)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailbox (6.0.2.2)
actionpack (= 6.0.2.2)
activejob (= 6.0.2.2)
activerecord (= 6.0.2.2)
activestorage (= 6.0.2.2)
activesupport (= 6.0.2.2)
actionmailbox (6.0.3.1)
actionpack (= 6.0.3.1)
activejob (= 6.0.3.1)
activerecord (= 6.0.3.1)
activestorage (= 6.0.3.1)
activesupport (= 6.0.3.1)
mail (>= 2.7.1)
actionmailer (6.0.2.2)
actionpack (= 6.0.2.2)
actionview (= 6.0.2.2)
activejob (= 6.0.2.2)
actionmailer (6.0.3.1)
actionpack (= 6.0.3.1)
actionview (= 6.0.3.1)
activejob (= 6.0.3.1)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
actionpack (6.0.2.2)
actionview (= 6.0.2.2)
activesupport (= 6.0.2.2)
actionpack (6.0.3.1)
actionview (= 6.0.3.1)
activesupport (= 6.0.3.1)
rack (~> 2.0, >= 2.0.8)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
actiontext (6.0.2.2)
actionpack (= 6.0.2.2)
activerecord (= 6.0.2.2)
activestorage (= 6.0.2.2)
activesupport (= 6.0.2.2)
actiontext (6.0.3.1)
actionpack (= 6.0.3.1)
activerecord (= 6.0.3.1)
activestorage (= 6.0.3.1)
activesupport (= 6.0.3.1)
nokogiri (>= 1.8.5)
actionview (6.0.2.2)
activesupport (= 6.0.2.2)
actionview (6.0.3.1)
activesupport (= 6.0.3.1)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activejob (6.0.2.2)
activesupport (= 6.0.2.2)
activejob (6.0.3.1)
activesupport (= 6.0.3.1)
globalid (>= 0.3.6)
activemodel (6.0.2.2)
activesupport (= 6.0.2.2)
activerecord (6.0.2.2)
activemodel (= 6.0.2.2)
activesupport (= 6.0.2.2)
activestorage (6.0.2.2)
actionpack (= 6.0.2.2)
activejob (= 6.0.2.2)
activerecord (= 6.0.2.2)
activemodel (6.0.3.1)
activesupport (= 6.0.3.1)
activerecord (6.0.3.1)
activemodel (= 6.0.3.1)
activesupport (= 6.0.3.1)
activestorage (6.0.3.1)
actionpack (= 6.0.3.1)
activejob (= 6.0.3.1)
activerecord (= 6.0.3.1)
marcel (~> 0.3.1)
activesupport (6.0.2.2)
activesupport (6.0.3.1)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
zeitwerk (~> 2.2)
zeitwerk (~> 2.2, >= 2.2.2)
addressable (2.6.0)
public_suffix (>= 2.0.2, < 4.0)
administrate (0.13.0)
Expand Down Expand Up @@ -196,7 +196,7 @@ GEM
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
ruby_dep (~> 1.2)
loofah (2.4.0)
loofah (2.5.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.1)
Expand All @@ -207,11 +207,11 @@ GEM
mime-types (3.3)
mime-types-data (~> 3.2015)
mime-types-data (3.2019.1009)
mimemagic (0.3.4)
mimemagic (0.3.5)
mini_magick (4.9.5)
mini_mime (1.0.2)
mini_portile2 (2.4.0)
minitest (5.14.0)
minitest (5.14.1)
mock_redis (0.21.0)
momentjs-rails (2.20.1)
railties (>= 3.1)
Expand Down Expand Up @@ -249,29 +249,29 @@ GEM
rack
rack-test (1.1.0)
rack (>= 1.0, < 3)
rails (6.0.2.2)
actioncable (= 6.0.2.2)
actionmailbox (= 6.0.2.2)
actionmailer (= 6.0.2.2)
actionpack (= 6.0.2.2)
actiontext (= 6.0.2.2)
actionview (= 6.0.2.2)
activejob (= 6.0.2.2)
activemodel (= 6.0.2.2)
activerecord (= 6.0.2.2)
activestorage (= 6.0.2.2)
activesupport (= 6.0.2.2)
rails (6.0.3.1)
actioncable (= 6.0.3.1)
actionmailbox (= 6.0.3.1)
actionmailer (= 6.0.3.1)
actionpack (= 6.0.3.1)
actiontext (= 6.0.3.1)
actionview (= 6.0.3.1)
activejob (= 6.0.3.1)
activemodel (= 6.0.3.1)
activerecord (= 6.0.3.1)
activestorage (= 6.0.3.1)
activesupport (= 6.0.3.1)
bundler (>= 1.3.0)
railties (= 6.0.2.2)
railties (= 6.0.3.1)
sprockets-rails (>= 2.0.0)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.3.0)
loofah (~> 2.3)
railties (6.0.2.2)
actionpack (= 6.0.2.2)
activesupport (= 6.0.2.2)
railties (6.0.3.1)
actionpack (= 6.0.3.1)
activesupport (= 6.0.3.1)
method_source
rake (>= 0.8.7)
thor (>= 0.20.3, < 2.0)
Expand Down Expand Up @@ -361,7 +361,7 @@ GEM
turbolinks (5.2.0)
turbolinks-source (~> 5.2)
turbolinks-source (5.2.0)
tzinfo (1.2.6)
tzinfo (1.2.7)
thread_safe (~> 0.1)
unicode-display_width (1.6.0)
virtus (1.0.5)
Expand Down
16 changes: 16 additions & 0 deletions app/controllers/public_signs_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class PublicSignsController < ApplicationController
def index
@signs = search_results.data
@page = search_results.support
end

private

def search
@search ||= Search.new(params.permit(:page, :sort))
end

def search_results
@search_results ||= PublicSignService.call(search: search, relation: policy_scope(Sign))
end
end
44 changes: 44 additions & 0 deletions app/services/public_sign_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# frozen_string_literal: true

require "./lib/sql/status"

class PublicSignService < ApplicationService
attr_reader :search, :results

def initialize(search:, relation:)
@search = search
@relation = relation
@results = SearchResults.new
end

def process
results.data = build_results
results.support = search.page_with_total
results
end

private

def build_results
sql_arr = [SQL::Status.public_signs(search.order_clause)]
result_ids = parse_results(exec_query(sql_arr))
result_relation = @relation.where(@relation.primary_key => result_ids)
search.total = result_relation.count
fetch_results(result_relation, result_ids)
end

def fetch_results(result_relation, result_ids)
result_relation
.limit(search.page[:limit])
.order(Arel.sql("array_position(array[#{result_ids.join(",")}]::integer[],
\"#{@relation.table_name}\".\"#{@relation.primary_key}\")"))
end

def parse_results(results)
results.field_values(@relation.primary_key)
end

def exec_query(sql_arr)
ApplicationRecord.connection.execute(ApplicationRecord.send(:sanitize_sql_array, sql_arr))
end
end
11 changes: 9 additions & 2 deletions app/views/home/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,15 @@
<p>Approved member can add new signs for everyone to see</p>
</div>

<div class="cell margin-top-1 home-main__signs">
<h2>Recently Added</h2>
<div id="recently-published" class="cell margin-top-1 home-main__signs">
<div class="grid-x">
<div class="cell auto">
<h2>Recently Added</h2>
</div>
<div class="cell shrink">
<%= link_to "See all", public_signs_path, class: "button primary" %>
</div>
</div>
<div class="sign-grid sign-grid--not-bottom">
<% @recent_signs.each do |sign| %>
<%= render "signs/card", sign: sign %>
Expand Down
34 changes: 34 additions & 0 deletions app/views/public_signs/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<div class="grid-x margin-vertical-2">
<div class="cell auto">
<h2 class="normal">
<% if @page[:limit] >= @page[:total] %>
<%= @page[:total] %> of <%= @page[:total] %> signs
<% else %>
<%= @page[:limit] %> of <%= @page[:total] %> signs
<% end %>
</h2>
</div>

<div class="cell shrink">
<%= render "search/sort_by", page: @page unless @page[:total].zero? %>
</div>
</div>
<hr class="list__divider list__divider--dark">

<% if @signs.any? %>
<div class="grid-x cell" id="community-signs">
<div class="cell margin-top-3 margin-bottom-0 grid-x align-middle">
<h2 class="cell auto">All community signs</h2>
</div>
<div class="sign-grid cell">
<% @signs.each do |sign| %>
<%= render "signs/card", sign: sign %>
<% end %>
</div>
</div>
<% if @page[:total] >= @page[:limit] %>
<div class="cell auto text-center margin-2">
<%= link_to "Show More", params.to_unsafe_h.merge(page: @page[:next_page], anchor: dom_id(@signs.last, :card)), class: "button primary" %>
</div>
<% end %>
<% end %>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

root "home#index"
resources :search, only: [:index]
resources :public_signs, only: [:index]
resources :approved_user_applications, only: %i[new create]
resources :signs, except: %i[index] do
resources :share, only: %i[show create destroy], controller: :sign_share, param: :token
Expand Down
51 changes: 51 additions & 0 deletions lib/sql/status.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# frozen_string_literal: true

module SQL
module Status
module_function

def public_signs(order)
<<-SQL
WITH sign_search(id, rank_precedence, rank_order, row_num) AS
(SELECT rs1.id,
rs1.rank_precedence,
rs1.rank_order,
ROW_NUMBER() OVER (PARTITION BY rs1.id
ORDER BY rs1.rank_precedence ASC) AS row_num
FROM
(SELECT signs.id,
1 AS rank_precedence,
RANK() OVER (ORDER BY signs.word) AS rank_order
FROM signs
WHERE signs.status = 'published'
UNION SELECT signs.id,
2 AS rank_precedence,
RANK() OVER (ORDER BY signs.word) AS rank_order
FROM signs
WHERE signs.status = 'published'
UNION SELECT signs.id,
3 AS rank_precedence,
RANK() OVER (ORDER BY signs.secondary) AS rank_order
FROM signs
WHERE signs.status = 'published'
UNION SELECT signs.id,
4 AS rank_precedence,
RANK() OVER (ORDER BY signs.secondary) AS rank_order
FROM signs
WHERE signs.status = 'published' ) AS rs1)
SELECT signs.id
FROM sign_search
JOIN signs ON signs.id=sign_search.id
LEFT JOIN LATERAL (SELECT sign_activities.sign_id,
COUNT(sign_activities.sign_id) AS count
FROM sign_activities
WHERE sign_search.row_num = 1 AND
sign_activities.sign_id = sign_search.id AND
sign_activities.key = 'agree'
GROUP BY sign_activities.sign_id) AS activity ON TRUE
WHERE sign_search.row_num = 1
ORDER BY #{order}
SQL
end
end
end