Merge pull request 'Make default user services configurable by admins' (#203) from feature/default_service_settings into master
All checks were successful
continuous-integration/drone/push Build is passing

Reviewed-on: #203
Reviewed-by: galfert <garret.alfert@gmail.com>
This commit was merged in pull request #203.
This commit is contained in:
2024-09-11 11:21:38 +00:00
40 changed files with 449 additions and 275 deletions

View File

@@ -0,0 +1,25 @@
require 'rails_helper'
describe ServicesHelper do
describe "#service_human_name" do
it "returns the human name when it's configured" do
expect(service_human_name("mastodon")).to eq("Mastodon")
end
it "returns the key when there is no human name" do
expect(service_human_name("ejabberd")).to eq("ejabberd")
end
end
describe "#service_display_name" do
it "returns the display name when it's configured" do
expect(service_display_name("lndhub")).to eq("Lightning Network")
end
it "returns the human name when there is no display name" do
expect(service_display_name("mastodon")).to eq("Mastodon")
end
end
end

View File

@@ -44,7 +44,7 @@ RSpec.describe CreateLdapUserJob, type: :job do
it "adds default services for pre-confirmed accounts" do
allow(ldap_client_mock).to receive(:add) # spy on mock
allow(Setting).to receive(:default_services).and_return(["xmpp", "discourse"])
Setting.default_services = ["ejabberd", "discourse"]
perform_enqueued_jobs { job_for_preconfirmed_account }
@@ -56,7 +56,7 @@ RSpec.describe CreateLdapUserJob, type: :job do
sn: "halfinney",
uid: "halfinney",
mail: "halfinney@example.com",
serviceEnabled: ["xmpp", "discourse"],
serviceEnabled: ["ejabberd", "discourse"],
userPassword: "remember-remember-the-5th-of-november"
}
)

View File

@@ -13,7 +13,7 @@ RSpec.describe XmppExchangeContactsJob, type: :job do
before do
stub_request(:post, "http://xmpp.example.com/api/add_rosteritem")
.to_return(status: 200, body: "", headers: {})
allow_any_instance_of(User).to receive(:services_enabled).and_return(["xmpp"])
allow_any_instance_of(User).to receive(:services_enabled).and_return(["ejabberd"])
end
it "posts add_rosteritem commands to the ejabberd API" do

View File

@@ -0,0 +1,25 @@
require 'rails_helper'
RSpec.describe Setting, type: :model do
describe ".available_services" do
before do
Setting.discourse_enabled = true
Setting.ejabberd_enabled = true
Setting.email_enabled = false
Setting.gitea_enabled = false
Setting.lndhub_enabled = true
Setting.mastodon_enabled = true
Setting.mediawiki_enabled = false
Setting.nostr_enabled = false
Setting.remotestorage_enabled = true
end
it "contains all enabled services" do
expect(Setting.available_services).to eq(%w[
discourse ejabberd lndhub mastodon remotestorage
])
end
end
end

View File

@@ -78,9 +78,9 @@ RSpec.describe User, type: :model do
it "returns the entries from the LDAP service attribute" do
expect(user).to receive(:ldap_entry).and_return({
uid: user.cn, ou: user.ou, mail: user.email, admin: nil,
services_enabled: ["discourse", "email", "gitea", "wiki", "xmpp"]
services_enabled: ["discourse", "ejabberd", "email", "gitea", "wiki"]
})
expect(user.services_enabled).to eq(["discourse", "email", "gitea", "wiki", "xmpp"])
expect(user.services_enabled).to eq(["discourse", "ejabberd", "email", "gitea", "wiki"])
end
end
@@ -88,7 +88,7 @@ RSpec.describe User, type: :model do
before do
allow(user).to receive(:ldap_entry).and_return({
uid: user.cn, ou: user.ou, mail: user.email, admin: nil,
services_enabled: ["gitea", "xmpp"]
services_enabled: ["ejabberd", "gitea"]
})
end
@@ -121,9 +121,9 @@ RSpec.describe User, type: :model do
it "adds multiple service to the LDAP entry" do
expect_any_instance_of(LdapService).to receive(:replace_attribute)
.with(dn, :serviceEnabled, ["discourse", "gitea", "wiki", "xmpp"]).and_return(true)
.with(dn, :serviceEnabled, ["discourse", "ejabberd", "gitea", "wiki"]).and_return(true)
user.enable_service([:wiki, :xmpp])
user.enable_service([:ejabberd, :wiki])
end
end
@@ -131,7 +131,7 @@ RSpec.describe User, type: :model do
before do
allow(user).to receive(:ldap_entry).and_return({
uid: user.cn, ou: user.ou, mail: user.email, admin: nil,
services_enabled: ["discourse", "gitea", "xmpp"]
services_enabled: ["discourse", "ejabberd", "gitea"]
})
allow(user).to receive(:dn).and_return(dn)
end
@@ -140,14 +140,14 @@ RSpec.describe User, type: :model do
expect_any_instance_of(LdapService).to receive(:replace_attribute)
.with(dn, :serviceEnabled, ["discourse", "gitea"]).and_return(true)
user.disable_service(:xmpp)
user.disable_service(:ejabberd)
end
it "removes multiple services from the LDAP entry" do
expect_any_instance_of(LdapService).to receive(:replace_attribute)
.with(dn, :serviceEnabled, ["discourse"]).and_return(true)
user.disable_service([:xmpp, "gitea"])
user.disable_service([:ejabberd, "gitea"])
end
end
@@ -178,7 +178,7 @@ RSpec.describe User, type: :model do
after { clear_enqueued_jobs }
it "enables default services" do
expect(user).to receive(:enable_service).with(%w[ discourse gitea mastodon mediawiki remotestorage xmpp ])
expect(user).to receive(:enable_service).with(Setting.default_services)
user.send :devise_after_confirmation
end

View File

@@ -44,7 +44,7 @@ RSpec.describe "WebFinger", type: :request do
before do
allow_any_instance_of(User).to receive(:ldap_entry).and_return({
uid: user.cn, ou: user.ou, mail: user.email, admin: nil,
services_enabled: ["xmpp"]
services_enabled: ["ejabberd"]
})
end
@@ -106,7 +106,7 @@ RSpec.describe "WebFinger", type: :request do
before do
allow_any_instance_of(User).to receive(:ldap_entry).and_return({
uid: user.cn, ou: user.ou, mail: user.email, admin: nil,
services_enabled: ["xmpp"]
services_enabled: ["ejabberd"]
})
end