Add #service_enabled?
method to user model
This commit is contained in:
parent
670b2da1ef
commit
819ecf6ad8
@ -3,7 +3,7 @@ class Services::ChatController < Services::BaseController
|
|||||||
before_action :require_service_available
|
before_action :require_service_available
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@service_enabled = current_user.services_enabled.include?(:xmpp)
|
@service_enabled = current_user.service_enabled?(:xmpp)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -3,7 +3,7 @@ class Services::MastodonController < Services::BaseController
|
|||||||
before_action :require_service_available
|
before_action :require_service_available
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@service_enabled = current_user.services_enabled.include?(:mastodon)
|
@service_enabled = current_user.service_enabled?(:mastodon)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -5,7 +5,7 @@ class Services::RemotestorageController < Services::BaseController
|
|||||||
|
|
||||||
# Dashboard
|
# Dashboard
|
||||||
def show
|
def show
|
||||||
# unless current_user.services_enabled.include?(:remotestorage)
|
# unless current_user.service_enabled?(:remotestorage)
|
||||||
# redirect_to service_remotestorage_info_path
|
# redirect_to service_remotestorage_info_path
|
||||||
# end
|
# end
|
||||||
@rs_auths = current_user.remote_storage_authorizations
|
@rs_auths = current_user.remote_storage_authorizations
|
||||||
|
@ -2,8 +2,8 @@ class XmppExchangeContactsJob < ApplicationJob
|
|||||||
queue_as :default
|
queue_as :default
|
||||||
|
|
||||||
def perform(inviter, invitee)
|
def perform(inviter, invitee)
|
||||||
return unless inviter.services_enabled.include?("xmpp") &&
|
return unless inviter.service_enabled?(:xmpp) &&
|
||||||
invitee.services_enabled.include?("xmpp") &&
|
invitee.service_enabled?(:xmpp) &&
|
||||||
inviter.preferences[:xmpp_exchange_contacts_with_invitees]
|
inviter.preferences[:xmpp_exchange_contacts_with_invitees]
|
||||||
|
|
||||||
ejabberd = EjabberdApiClient.new
|
ejabberd = EjabberdApiClient.new
|
||||||
|
@ -180,6 +180,10 @@ class User < ApplicationRecord
|
|||||||
ldap_entry[:services_enabled] || []
|
ldap_entry[:services_enabled] || []
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def service_enabled?(name)
|
||||||
|
services_enabled.map(&:to_sym).include?(name.to_sym)
|
||||||
|
end
|
||||||
|
|
||||||
def enable_service(service)
|
def enable_service(service)
|
||||||
current_services = services_enabled
|
current_services = services_enabled
|
||||||
new_services = Array(service).map(&:to_s)
|
new_services = Array(service).map(&:to_s)
|
||||||
|
@ -80,6 +80,25 @@ RSpec.describe User, type: :model do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#service_enabled?" 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"]
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns true or false" do
|
||||||
|
expect(user.service_enabled?("gitea")).to be(true)
|
||||||
|
expect(user.service_enabled?("email")).to be(false)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns false when service is not enabled" do
|
||||||
|
expect(user.service_enabled?(:gitea)).to be(true)
|
||||||
|
expect(user.service_enabled?(:email)).to be(false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "#enable_service" do
|
describe "#enable_service" do
|
||||||
before do
|
before do
|
||||||
allow(user).to receive(:ldap_entry).and_return({
|
allow(user).to receive(:ldap_entry).and_return({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user