Replace hyphen with underscore in Mastodon address
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

Unfortunately, Mastodon only allows underscores for usernames, and
reversely, akkounts only allows hyphens and no underscores.
This commit is contained in:
Râu Cao 2024-03-29 09:08:15 +04:00
parent e6f5623c7f
commit 0367450c4b
Signed by: raucao
GPG Key ID: 37036C356E56CC51
2 changed files with 9 additions and 1 deletions

View File

@ -131,7 +131,7 @@ class User < ApplicationRecord
def mastodon_address def mastodon_address
return nil unless Setting.mastodon_enabled? return nil unless Setting.mastodon_enabled?
"#{self.cn}@#{Setting.mastodon_address_domain}" "#{self.cn.gsub("-", "_")}@#{Setting.mastodon_address_domain}"
end end
def valid_attribute?(attribute_name) def valid_attribute?(attribute_name)

View File

@ -41,6 +41,14 @@ RSpec.describe User, type: :model do
expect(user.mastodon_address).to eq("jimmy@kosmos.social") expect(user.mastodon_address).to eq("jimmy@kosmos.social")
end end
end end
describe "username contains hyphen/dash" do
let(:jammy) { build :user, cn: "jammy-jellyfish", ou: "kosmos.org" }
it "returns the user address" do
expect(jammy.mastodon_address).to eq("jammy_jellyfish@kosmos.org")
end
end
end end
end end