FEATURE: Can edit category/host relationships for embedding#1
Conversation
Codoki PR ReviewSummary: Persist embeddable host changes, fix test fabricators, align admin UI
This review covered the top 30 of 36 files (risk-ranked). For complete coverage and faster feedback, consider splitting into ~1 smaller PR(s). Issues (Critical & High only)
Showing top 5 issues. Critical: 0, High: 5. See inline suggestions for more. Key Feedback (click to expand)
Confidence: 2/5 — Not ready to merge (5 high · status: Requires changes · scope: top 30/36 files reviewed) React with 👍 or 👎 if you found this review useful. |
| validates_format_of :host, :with => /\A[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?\Z/i | ||
| belongs_to :category | ||
|
|
||
| before_validation do |
There was a problem hiding this comment.
| before_validation do | |
| before_validation do | |
| if self.host.present? | |
| self.host = self.host.to_s.sub(/^https?:\/\//, '').sub(/\/.*$/, '') | |
| end | |
| end |
| host = uri.host | ||
| return false unless host.present? | ||
|
|
||
| where("lower(host) = ?", host).first |
There was a problem hiding this comment.
🔷 Medium: The query compares lower(host) to the unmodified input. If the input host contains uppercase letters (e.g., 'EVILTROUT.COM'), this will not match. Downcase the input to ensure consistent case-insensitive comparison.
| where("lower(host) = ?", host).first | |
| where("lower(host) = ?", host.downcase).first |
| records = val.split("\n") | ||
| if records.present? | ||
| records.each do |h| | ||
| execute "INSERT INTO embeddable_hosts (host, category_id, created_at, updated_at) VALUES ('#{h}', #{category_id}, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)" |
There was a problem hiding this comment.
| execute "INSERT INTO embeddable_hosts (host, category_id, created_at, updated_at) VALUES ('#{h}', #{category_id}, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)" | |
| execute "INSERT INTO embeddable_hosts (host, category_id, created_at, updated_at) VALUES (#{ActiveRecord::Base.connection.quote(h)}, #{category_id.to_i}, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)" |
| if !(Rails.env.development? && current_user.try(:admin?)) | ||
| raise Discourse::InvalidAccess.new('embeddable hosts not set') if SiteSetting.embeddable_hosts.blank? | ||
| raise Discourse::InvalidAccess.new('invalid referer host') unless SiteSetting.allows_embeddable_host?(request.referer) | ||
| raise Discourse::InvalidAccess.new('invalid referer host') unless EmbeddableHost.host_allowed?(request.referer) |
There was a problem hiding this comment.
| raise Discourse::InvalidAccess.new('invalid referer host') unless EmbeddableHost.host_allowed?(request.referer) | |
| raise Discourse::InvalidAccess.new('invalid referer host') unless EmbeddableHost.host_allowed?(request.referer) || SiteSetting.allows_embeddable_host?(request.referer) |
| @@ -0,0 +1,16 @@ | |||
| class EmbeddableHostSerializer < ApplicationSerializer | |||
There was a problem hiding this comment.
🔷 Medium: The explicit id/host/category_id methods duplicate the default behavior of attributes; simplifying reduces maintenance and keeps the serializer idiomatic.
| class EmbeddableHostSerializer < ApplicationSerializer | |
| class EmbeddableHostSerializer < ApplicationSerializer | |
| attributes :id, :host, :category_id | |
| end |
|
|
||
| actions: { | ||
| saveChanges() { | ||
| this.get('embedding').update({}); |
There was a problem hiding this comment.
| this.get('embedding').update({}); | |
| this.get('embedding').update({ | |
| embeddable_host_ids: this.get('embedding.embeddable_hosts').mapBy('id').filter(Boolean) | |
| }); |
| cat.update!(read_restricted: true) | ||
| cat.category_groups.build(group_id: transients[:group].id, permission_type: CategoryGroup.permission_types[:full]) | ||
| end | ||
| Fabricator(:embeddable_host) do |
There was a problem hiding this comment.
| Fabricator(:embeddable_host) do | |
| Fabricator(:category) do | |
| name { sequence(:name) { |n| "Amazing Category #{n}" } } | |
| user | |
| end |
No description provided.