Skip to content

Commit babf10d

Browse files
committed
WIP: Add initial community hub and display public activity (initially just pages)
1 parent 83bdf5f commit babf10d

File tree

29 files changed

+321
-10
lines changed

29 files changed

+321
-10
lines changed

Gemfile.lock

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ PATH
4747
mobility-actiontext (~> 1.1)
4848
noticed
4949
premailer-rails
50+
public_activity
5051
pundit (>= 2.1, < 2.6)
5152
pundit-resources
5253
rack-attack
@@ -502,6 +503,11 @@ GEM
502503
psych (5.2.6)
503504
date
504505
stringio
506+
public_activity (3.0.1)
507+
actionpack (>= 6.1.0)
508+
activerecord (>= 6.1)
509+
i18n (>= 0.5.0)
510+
railties (>= 6.1.0)
505511
public_suffix (6.0.1)
506512
puma (6.6.0)
507513
nio4r (~> 2.0)

app/controllers/better_together/application_controller.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ module BetterTogether
44
# Base application controller for engine
55
class ApplicationController < ActionController::Base # rubocop:todo Metrics/ClassLength
66
include ActiveStorage::SetCurrent
7+
include PublicActivity::StoreController
78
include Pundit::Authorization
89

910
protect_from_forgery with: :exception
11+
1012
before_action :check_platform_setup
1113
before_action :set_locale
1214
before_action :store_user_location!, if: :storable_location?
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
module BetterTogether
4+
# Internal hub for logged-in users to see relevant platform & community information
5+
class HubController < ApplicationController
6+
def index
7+
authorize :'better_together/hub', :index?
8+
@activities = helpers.activities
9+
end
10+
end
11+
end
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# frozen_string_literal: true
2+
3+
module BetterTogether
4+
# Helper methods used for displaying the Community Hub
5+
module HubHelper
6+
def activities
7+
BetterTogether::ActivityPolicy::Scope.new(current_user, PublicActivity::Activity).resolve
8+
end
9+
10+
# For generating time tags calculated using jquery.timeago
11+
def timeago(time, options = {})
12+
options[:class] ||= 'timeago'
13+
content_tag(:abbr, time.to_s, options.merge(title: time.getutc.iso8601)) if time
14+
end
15+
16+
# Shortcut for outputing proper ownership of objects,
17+
# depending on who is looking
18+
# rubocop:todo Naming/PredicateMethod
19+
def whose?(user, object) # rubocop:todo Metrics/MethodLength, Naming/PredicateMethod
20+
# rubocop:enable Naming/PredicateMethod
21+
owner = case object
22+
when Page
23+
object.creator
24+
end
25+
if user && owner
26+
if user.id == owner.id
27+
'his'
28+
else
29+
"#{owner.nickname}'s"
30+
end
31+
else
32+
''
33+
end
34+
end
35+
36+
# Check if object still exists in the database and display a link to it,
37+
# otherwise display a proper message about it.
38+
# This is used in activities that can refer to
39+
# objects which no longer exist, like removed posts.
40+
def link_to_trackable(object, object_type)
41+
if object
42+
object_url = object.respond_to?(:url) ? object.url : object
43+
trackable_name = "#{object.class.model_name.human}: #{object}"
44+
link_to trackable_name, object_url
45+
else
46+
"a #{object_type.downcase} which does not exist anymore"
47+
end
48+
end
49+
end
50+
end

app/helpers/better_together/navigation_items_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def route_names_for_select(nav_item = nil)
133133
BetterTogether::NavigationItem.route_names.map do |name, route|
134134
[I18n.t("better_together.navigation_items.route_names.#{name}"), route]
135135
end,
136-
(nav_item ? nav_item.route_name : nil)
136+
nav_item&.route_name
137137
)
138138
end
139139

app/helpers/better_together/sidebar_nav_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def render_nav_item(nav_item:, current_page:, level:, parent_id:, index:) # rubo
100100
# rubocop:enable Metrics/CyclomaticComplexity
101101

102102
# Memoized method to check if any descendants are active
103-
def has_active_descendants?(nav_item_id, current_page) # rubocop:todo Naming/PredicateName
103+
def has_active_descendants?(nav_item_id, current_page) # rubocop:todo Naming/PredicatePrefix
104104
@active_descendant_cache ||= {}
105105
return @active_descendant_cache[nav_item_id] if @active_descendant_cache.key?(nav_item_id)
106106

app/models/better_together/contact_detail.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def self.permitted_attributes(id: false, destroy: false, exclude_extra: false) #
3030
] + super
3131
end
3232

33-
def has_contact_details? # rubocop:todo Naming/PredicateName
33+
def has_contact_details? # rubocop:todo Naming/PredicatePrefix
3434
# rubocop:todo Layout/LineLength
3535
phone_numbers.size.positive? || email_addresses.size.positive? || addresses.size.positive? || social_media_accounts.size.positive? || website_links.size.positive?
3636
# rubocop:enable Layout/LineLength

app/models/better_together/navigation_item.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class NavigationItem < ApplicationRecord # rubocop:todo Metrics/ClassLength
2020
geography_regions: 'geography_regions_url',
2121
geography_settlements: 'geography_settlements_url',
2222
host_dashboard: 'host_dashboard_url',
23+
hub: 'hub_url',
2324
metrics_reports: 'metrics_reports_url',
2425
navigation_areas: 'navigation_areas_url',
2526
pages: 'pages_url',

app/models/better_together/page.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class Page < ApplicationRecord
99
include Protected
1010
include Privacy
1111
include Searchable
12+
include TrackedActivity
1213

1314
categorizable
1415

app/models/concerns/better_together/content/block_attributes.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,8 @@ def block_styles # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
163163

164164
# rubocop:todo Metrics/PerceivedComplexity
165165
# rubocop:todo Metrics/AbcSize
166-
# rubocop:todo Naming/PredicateName
167-
def has_custom_styling? # rubocop:todo Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/PerceivedComplexity, Naming/PredicateName
168-
# rubocop:enable Naming/PredicateName
166+
# rubocop:todo Naming/PredicatePrefix
167+
def has_custom_styling? # rubocop:todo Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/PerceivedComplexity
169168
BACKGROUND_ATTRIBUTES.any? { |attr| send(attr).present? } ||
170169
BORDER_ATTRIBUTES.any? { |attr| send(attr).present? } ||
171170
MARGIN_PADDING_ATTRIBUTES.any? { |attr| send(attr).present? } ||
@@ -174,6 +173,7 @@ def has_custom_styling? # rubocop:todo Metrics/CyclomaticComplexity, Metrics/Abc
174173
end
175174
# rubocop:enable Metrics/AbcSize
176175
# rubocop:enable Metrics/PerceivedComplexity
176+
# rubocop:enable Naming/PredicatePrefix
177177

178178
def inline_block_styles
179179
inline_styles(block_styles)

0 commit comments

Comments
 (0)