Skip to content

Commit f676a18

Browse files
authored
Merge branch 'wip/new-to-nl-2' into wip/encrypted-rich-text-messages
2 parents 5d89ad5 + 89077f4 commit f676a18

File tree

18 files changed

+31
-34
lines changed

18 files changed

+31
-34
lines changed
102 KB
Loading
Binary file not shown.
102 KB
Loading
-94 KB
Binary file not shown.
102 KB
Loading
-94 KB
Binary file not shown.

app/concerns/better_together/joinable.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ module Joinable
66
extend ActiveSupport::Concern
77

88
included do
9-
class_attribute :member_role_associations
9+
class_attribute :member_role_associations, :joinable_type
1010
self.member_role_associations = []
1111

1212
def self.joinable(joinable_type:, member_type:, **membership_options) # rubocop:todo Metrics/MethodLength
13+
self.joinable_type = joinable_type
1314
membership_class = "BetterTogether::#{member_type.camelize}#{joinable_type.camelize}Membership"
1415
membership_name = :"#{member_type}_#{joinable_type}_memberships"
1516

app/concerns/better_together/member.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ module Member
66
extend ActiveSupport::Concern
77

88
included do # rubocop:todo Metrics/BlockLength
9-
class_attribute :joinable_role_associations
9+
class_attribute :joinable_role_associations, :joinable_membership_classes
1010
self.joinable_role_associations = []
11+
self.joinable_membership_classes = []
1112

1213
def self.member(joinable_type:, member_type:, **membership_options) # rubocop:todo Metrics/MethodLength
1314
membership_class = "BetterTogether::#{member_type.camelize}#{joinable_type.camelize}Membership"
@@ -31,6 +32,7 @@ def self.member(joinable_type:, member_type:, **membership_options) # rubocop:to
3132

3233
# Register the association name for role retrieval
3334
joinable_role_associations << joinable_roles_association
35+
joinable_membership_classes << membership_class
3436
end
3537

3638
# Cache roles for the current instance
@@ -103,8 +105,7 @@ def record_permission_granted?(resource_permission, record)
103105
# Check if the member has a membership tied explicitly to the record
104106
memberships = membership_class.where(
105107
member: self,
106-
joinable_id: record.id,
107-
joinable_type: record.class.name
108+
joinable_id: record.id
108109
).includes(:role)
109110

110111
memberships.any? do |membership|
@@ -114,9 +115,9 @@ def record_permission_granted?(resource_permission, record)
114115

115116
# Determine the membership class for the record's joinable type
116117
def membership_class_for(record)
117-
joinable_type = record.class.name
118-
membership_class_name = self.class.joinable_role_associations.find do |assoc|
119-
assoc.to_s.include?(joinable_type.underscore)
118+
joinable_type = record.class.joinable_type
119+
membership_class_name = self.class.joinable_membership_classes.find do |assoc|
120+
assoc.to_s.include?(joinable_type.capitalize)
120121
end
121122

122123
membership_class_name&.to_s&.classify&.constantize # rubocop:todo Style/SafeNavigationChainLength

app/helpers/better_together/image_helper.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ def cover_image_tag(entity, options = {}) # rubocop:todo Metrics/MethodLength, M
1212
image_width = options[:width] || 2400
1313
image_height = options[:height] || 600
1414
image_format = options[:format] || 'jpg'
15-
image_alt = options[:alt] || 'Default Cover Image'
16-
image_title = options[:title] || 'Default Cover Image'
15+
image_alt = options[:alt] || 'Cover Image'
16+
image_title = options[:title] || 'Cover Image'
1717
image_tag_attributes = {
1818
class: image_classes,
1919
style: image_style,
@@ -48,8 +48,8 @@ def profile_image_tag(entity, options = {}) # rubocop:todo Metrics/MethodLength,
4848
image_style = (options[:style]).to_s
4949
image_size = options[:size] || 300
5050
image_format = options[:format] || 'jpg'
51-
image_alt = options[:alt] || 'Default Cover Image'
52-
image_title = options[:title] || 'Default Cover Image'
51+
image_alt = options[:alt] || 'Profile Image'
52+
image_title = options[:title] || 'Profile Image'
5353
image_tag_attributes = {
5454
class: image_classes,
5555
style: image_style,

app/models/better_together/community.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ class Community < ApplicationRecord
6161

6262
validates :name,
6363
presence: true
64-
validates :description,
65-
presence: true
6664

6765
# Resize the cover image to specific dimensions
6866
def cover_image_variant(width, height)
@@ -76,12 +74,12 @@ def optimized_profile_image
7674
else
7775
# For other formats, analyze to determine transparency
7876
metadata = profile_image.metadata
79-
if profile_image.content_type == 'image/png' && metadata[:alpha]
77+
if profile_image.content_type == 'image/png'
8078
# If PNG with transparency, return the optimized PNG variant
81-
profile_image.variant(:optimized_png)
79+
profile_image.variant(:optimized_png).processed
8280
else
8381
# Otherwise, use the optimized JPG variant
84-
profile_image.variant(:optimized_jpeg)
82+
profile_image.variant(:optimized_jpeg).processed
8583
end
8684
end
8785
end

0 commit comments

Comments
 (0)