Repository navigation
Member subdomains: sidebar link, footer link, and primary-domain-only display #469
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
Merged
TripleU613
merged 3 commits into
main
from
feat/member-subdomains-links-and-primary-display
Dec 4, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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
77 changes: 77 additions & 0 deletions
77
assets/javascripts/discourse/initializers/member-subdomains.ts
This file contains hidden or 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,77 @@ | ||
| import type Owner from "@ember/owner"; | ||
| import { withPluginApi } from "discourse/lib/plugin-api"; | ||
| import type BaseCommunitySectionLink from "discourse/lib/sidebar/base-community-section-link"; | ||
| import { i18n } from "discourse-i18n"; | ||
|
|
||
| interface SubdomainsSiteSettings { | ||
| jtech_enabled?: boolean; | ||
| member_subdomains_enabled?: boolean; | ||
| member_subdomains_staff_only?: boolean; | ||
| member_subdomains_min_trust_level?: number; | ||
| } | ||
|
|
||
| interface SubdomainsUser { | ||
| staff?: boolean; | ||
| trust_level?: number; | ||
| } | ||
|
|
||
| export default { | ||
| name: "jtech-member-subdomains", | ||
|
|
||
| initialize(container: Owner) { | ||
| const siteSettings = container.lookup( | ||
| "service:site-settings" | ||
| ) as SubdomainsSiteSettings; | ||
| if ( | ||
| !siteSettings.jtech_enabled || | ||
| !siteSettings.member_subdomains_enabled | ||
| ) { | ||
| return; | ||
| } | ||
|
|
||
| const currentUser = container.lookup( | ||
| "service:current-user" | ||
| ) as SubdomainsUser | null; | ||
| if (!currentUser) { | ||
| return; | ||
| } | ||
|
|
||
| if (siteSettings.member_subdomains_staff_only && !currentUser.staff) { | ||
| return; | ||
| } | ||
|
|
||
| const minTl = siteSettings.member_subdomains_min_trust_level ?? 1; | ||
| if (!currentUser.staff && (currentUser.trust_level ?? 0) < minTl) { | ||
| return; | ||
| } | ||
|
|
||
| withPluginApi((api) => { | ||
| api.addCommunitySectionLink( | ||
| (BaseSectionLink: typeof BaseCommunitySectionLink) => { | ||
| return class MemberSubdomainsSectionLink extends BaseSectionLink { | ||
| get name() { | ||
| return "member-subdomains"; | ||
| } | ||
|
|
||
| get route() { | ||
| return "member-subdomains"; | ||
| } | ||
|
|
||
| get title() { | ||
| return i18n("member_subdomains.sidebar.title"); | ||
| } | ||
|
|
||
| get text() { | ||
| return i18n("member_subdomains.sidebar.text"); | ||
| } | ||
|
|
||
| get defaultPrefixValue() { | ||
| return "globe"; | ||
| } | ||
| }; | ||
| }, | ||
| true | ||
| ); | ||
| }); | ||
| }, | ||
| }; | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,97 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require "json" | ||
|
|
||
| module ::DiscourseMemberSubdomains | ||
| module AiReviewer | ||
| SYSTEM_PROMPT = <<~PROMPT.strip | ||
| You review subdomain requests for a community tech forum. | ||
| Approve almost all normal personal names, handles, project names, hobbies, tech tools, and ordinary websites. | ||
| ONLY reject if the subdomain label or target is clearly: | ||
| 1. Profanity, slurs, hate speech, or sexually explicit / NSFW wording. | ||
| 2. Impersonating an official service, bank, login page, government agency, or well-known brand for phishing or scams (for example: paypal-login, apple-verify, bankofamerica, official-support). | ||
| 3. Obviously pointing to a known scam, phishing, malware, or adult domain. | ||
|
|
||
| Do NOT be paranoid: creative handles, tech/dev/modding terms, personal sites, GitHub Pages, Vercel, Cloudflare Pages, or normal IP addresses are all ALLOWED. | ||
|
|
||
| Respond with ONLY valid JSON: {"allowed": true} or {"allowed": false, "reason": "short plain reason"}. | ||
| PROMPT | ||
|
|
||
| def self.available? | ||
| return false unless SiteSetting.member_subdomains_ai_review_enabled | ||
| return false unless defined?(::DiscourseAi::Completions::Llm) && defined?(::LlmModel) | ||
| unless SiteSetting.respond_to?(:discourse_ai_enabled) && SiteSetting.discourse_ai_enabled | ||
| return false | ||
| end | ||
|
|
||
| llm_model.present? | ||
| end | ||
|
|
||
| def self.llm_model | ||
| return nil unless defined?(::LlmModel) | ||
|
|
||
| configured_id = SiteSetting.member_subdomains_ai_llm_model_id.to_i | ||
| if configured_id > 0 | ||
| ::LlmModel.find_by(id: configured_id) | ||
| else | ||
| default_id = | ||
| SiteSetting.respond_to?(:ai_default_llm_model) ? SiteSetting.ai_default_llm_model.to_i : 0 | ||
| (default_id > 0 && ::LlmModel.find_by(id: default_id)) || ::LlmModel.order(:id).first | ||
| end | ||
| end | ||
|
|
||
| def self.check!(user:, label:, record_type:, target:) | ||
| return :skipped if user&.staff? | ||
| return :skipped unless available? | ||
|
|
||
| model = llm_model | ||
| return :skipped unless model | ||
|
|
||
| prompt = | ||
| ::DiscourseAi::Completions::Prompt.new( | ||
| SYSTEM_PROMPT, | ||
| messages: [ | ||
| { | ||
| type: :user, | ||
| content: | ||
| "Subdomain label: #{label}\nRecord type: #{record_type}\nTarget: #{target}\nForum host: #{Discourse.current_hostname}", | ||
| }, | ||
| ], | ||
| ) | ||
|
|
||
| raw = | ||
| ::DiscourseAi::Completions::Llm.proxy(model).generate( | ||
| prompt, | ||
| user: user || Discourse.system_user, | ||
| temperature: 0, | ||
| max_tokens: 120, | ||
| feature_name: "member_subdomains_review", | ||
| ) | ||
|
|
||
| verdict = parse_verdict(raw) | ||
| return :allowed if verdict.nil? || verdict["allowed"] != false | ||
|
|
||
| reason = verdict["reason"].to_s.strip.presence || "Not allowed by safety review." | ||
| raise ValidationError, "Subdomain rejected: #{reason}" | ||
| rescue ValidationError | ||
| raise | ||
| rescue StandardError => e | ||
| # Fail open so an upstream LLM outage never blocks legitimate members. | ||
| Rails.logger.warn("#{LOG_TAG} AI review skipped due to error: #{e.class}: #{e.message}") | ||
| :skipped | ||
| end | ||
|
|
||
| def self.parse_verdict(raw) | ||
| text = raw.to_s.strip | ||
| return nil if text.empty? | ||
|
|
||
| json_str = text[/\{.*\}/m] | ||
| return nil unless json_str | ||
|
|
||
| parsed = JSON.parse(json_str) | ||
| parsed.is_a?(Hash) ? parsed : nil | ||
| rescue JSON::ParserError | ||
| nil | ||
| end | ||
| end | ||
| end |
Oops, something went wrong.
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.
The new sidebar and footer links introduce user-visible behavior with different enablement, staff-only, and trust-level conditions, but the commit adds no frontend or system specs covering either link; a repository-wide search of
specandtestfinds subdomain coverage only for backend behavior. Add navigation specs that assert the links' destinations and their visibility with the module disabled, staff-only mode enabled, and eligible versus ineligible users. This is required by the repository's explicit rule that new behavior gets a spec.AGENTS.md reference: AGENTS.md:L19-L19
Useful? React with 👍 / 👎.