Allow Mastodon address domain to be different from primary domain
This commit is contained in:
parent
10bcd5c32b
commit
b7fa4b012a
@ -106,6 +106,9 @@ class Setting < RailsSettings::Base
|
||||
field :mastodon_enabled, type: :boolean,
|
||||
default: (ENV["MASTODON_PUBLIC_URL"].present?.to_s || false)
|
||||
|
||||
field :mastodon_address_domain, type: :string,
|
||||
default: ENV["MASTODON_ADDRESS_DOMAIN"].presence || self.primary_domain
|
||||
|
||||
#
|
||||
# MediaWiki
|
||||
#
|
||||
|
@ -110,6 +110,11 @@ class User < ApplicationRecord
|
||||
"#{self.cn}@#{self.ou}"
|
||||
end
|
||||
|
||||
def mastodon_address
|
||||
return nil unless Setting.mastodon_enabled?
|
||||
"#{self.cn}@#{Setting.mastodon_address_domain}"
|
||||
end
|
||||
|
||||
def valid_attribute?(attribute_name)
|
||||
self.valid?
|
||||
self.errors[attribute_name].blank?
|
||||
|
@ -12,5 +12,9 @@
|
||||
key: :mastodon_public_url,
|
||||
title: "Public URL"
|
||||
) %>
|
||||
<%= render FormElements::FieldsetResettableSettingComponent.new(
|
||||
key: :mastodon_address_domain,
|
||||
title: "User address domain"
|
||||
) %>
|
||||
<% end %>
|
||||
</ul>
|
||||
|
@ -13,7 +13,7 @@
|
||||
</p>
|
||||
<p data-controller="clipboard" class="flex gap-1 sm:w-2/5">
|
||||
<input type="text" id="user_address" class="grow"
|
||||
value=<%= current_user.address %> disabled="disabled"
|
||||
value=<%= current_user.mastodon_address %> disabled="disabled"
|
||||
data-clipboard-target="source" />
|
||||
<button id="copy-user-address" class="btn-md btn-icon btn-outline shrink-0"
|
||||
data-clipboard-target="trigger" data-action="clipboard#copy"
|
||||
|
@ -12,6 +12,38 @@ RSpec.describe User, type: :model do
|
||||
end
|
||||
end
|
||||
|
||||
describe "#mastodon_address" do
|
||||
let(:user) { build :user, cn: "jimmy", ou: "kosmos.org" }
|
||||
|
||||
context "Mastodon service not configured" do
|
||||
it "returns nil" do
|
||||
expect(user.mastodon_address).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context "Mastodon service configured" do
|
||||
before do
|
||||
Setting.mastodon_enabled = true
|
||||
end
|
||||
|
||||
describe "domain is the same as primary domain" do
|
||||
it "returns the user address" do
|
||||
expect(user.mastodon_address).to eq("jimmy@kosmos.org")
|
||||
end
|
||||
end
|
||||
|
||||
describe "domain is different from primary domain" do
|
||||
before do
|
||||
Setting.mastodon_address_domain = "kosmos.social"
|
||||
end
|
||||
|
||||
it "returns the user address" do
|
||||
expect(user.mastodon_address).to eq("jimmy@kosmos.social")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#is_admin?" do
|
||||
it "returns true when admin flag is set in LDAP" do
|
||||
expect(Devise::LDAP::Adapter).to receive(:get_ldap_param)
|
||||
|
Loading…
x
Reference in New Issue
Block a user