Skip to Content Skip to Search
Methods
#
A
B
C
D
E
F
H
I
M
N
O
P
R
S
T
U
V
W

Constants

STATUSES = active_statuses + inactive_statuses
 

Class Public methods

active_statuses()

# File app/models/db/site.rb, line 15
def self.active_statuses
  %w[agency_mode free unknown] + DB::Subscription.active_statuses
end

cms_values()

# File app/models/db/site.rb, line 11
def self.cms_values
  Admin::IntegrationProviderManager.cms_values.map(&:to_s)
end

inactive_statuses()

# File app/models/db/site.rb, line 19
def self.inactive_statuses
  %w[expired] + DB::Subscription.inactive_statuses
end

memberspace()

# File app/models/db/site.rb, line 276
def self.memberspace
  find_by(subdomain: memberspace_subdomain)
end

memberspace_subdomain()

# File app/models/db/site.rb, line 272
def self.memberspace_subdomain
  "admin"
end

reserved_subdomains()

# File app/models/db/site.rb, line 280
def self.reserved_subdomains
  %w[
    www ftp mail pop smtp ssl sftp api my app scripts cdn widgets mymemberspace
    memberspace current custom plugins assets widget
  ]
end

Instance Public methods

<<(admin)

# File app/models/db/site.rb, line 105
def <<(admin)
  super(admin.becomes(SiteAdmin))
end

active?()

# File app/models/db/site.rb, line 521
def active?
  !archived? && self.class.active_statuses.include?(status)
end

after_logout_url()

# File app/models/db/site.rb, line 227
def after_logout_url
  Util::Url.fully_qualified_url(settings.after_logout_url, self)
end

agency_mode!()

# File app/models/db/site.rb, line 342
def agency_mode!
  update!(built_by_agency: true, billing_enabled: false)
end

agency_mode?()

# File app/models/db/site.rb, line 351
def agency_mode?
  built_by_agency? && !billing_enabled?
end

agency_mode_off!()

# File app/models/db/site.rb, line 346
def agency_mode_off!
  update!(built_by_agency: false, billing_enabled: true)
  sync_owner_subscription_status
end

all_onboarding_steps_completed?()

# File app/models/db/site.rb, line 387
def all_onboarding_steps_completed?
  created_plan? && installed_code?
end

archived!()

# File app/models/db/site.rb, line 565
def archived!
  update_columns(archived: true, website: website_with_archive)
end

billing_disabled!()

# File app/models/db/site.rb, line 549
def billing_disabled!
  update!(billing_enabled: false)
end

billing_disabled?()

# File app/models/db/site.rb, line 553
def billing_disabled?
  !billing_enabled?
end

billing_enabled!()

# File app/models/db/site.rb, line 535
def billing_enabled!
  update!(billing_enabled: true)
end

billing_enabled_with_new_owner!(new_owner)

# File app/models/db/site.rb, line 539
def billing_enabled_with_new_owner!(new_owner)
  update!(
    owner: new_owner,
    billing_enabled: true,
    ownership_transferred_at: Time.current
  )

  add_creator_to_administrators!
end

billing_invite_recipient?(site_owner)

# File app/models/db/site.rb, line 561
def billing_invite_recipient?(site_owner)
  billing_invite.present? && billing_invite.is_recipient?(site_owner)
end

block_reserved_subdomains()

# File app/models/db/site.rb, line 411
def block_reserved_subdomains
  if self.class.reserved_subdomains.include?(subdomain)
    errors.add(:subdomain, "Subdomain is not allowed")
  end
end

cms=(value)

# File app/models/db/site.rb, line 295
def cms=(value)
  super(value.to_s)
end

cms_title()

# File app/models/db/site.rb, line 318
def cms_title
  if cms == "html"
    "Custom HTML Website"
  else
    cms.titleize
  end
end

created_plan!()

# File app/models/db/site.rb, line 359
def created_plan!
  track_onboarded(:created_plan)
end

created_plan?()

# File app/models/db/site.rb, line 391
def created_plan?
  onboarding_step_complete?(:created_plan)
end

custom_domain_host()

# File app/models/db/site.rb, line 484
def custom_domain_host
  custom_domain&.ssl_setup? ? custom_domain.host : false
end

default_from_address?()

# File app/models/db/site.rb, line 326
def default_from_address?
  email_settings.from_address == DB::SiteSettings.default_from_address
end

email()

Alias for: email_settings

email_settings()

Also aliased as: email
# File app/models/db/site.rb, line 434
def email_settings
  super || build_email_settings
end

email_white_label()

# File app/models/db/site.rb, line 439
def email_white_label
  @email_white_label ||= Admin::EmailWhiteLabel.find(site: self)
end

features_and_limits()

# File app/models/db/site.rb, line 573
def features_and_limits
  {
    broadcast_emails_per_month: owner_broadcast_emails_per_month_limit,
    can_create_free_plans:,
    can_create_organization:,
    can_invite_site_admins:,
    can_remove_branding:,
    can_send_broadcasts:,
    can_setup_integrations:
  }
end

has_member_with_email?(email)

# File app/models/db/site.rb, line 447
def has_member_with_email?(email)
  members.where(email:).exists?
end

has_payment_gateway?()

# File app/models/db/site.rb, line 314
def has_payment_gateway?
  has_stripe_config? && payment_gateway_id.present?
end

has_transaction_fee?()

# File app/models/db/site.rb, line 475
def has_transaction_fee?
  transaction_fee_percent > 0
end

host()

# File app/models/db/site.rb, line 463
def host
  custom_domain_host || platform_host
end

installed_code!()

# File app/models/db/site.rb, line 363
def installed_code!
  track_onboarded(:installed_code)
end

installed_code?()

# File app/models/db/site.rb, line 395
def installed_code?
  onboarding_step_complete?(:installed_code)
end

member?(member)

# File app/models/db/site.rb, line 443
def member?(member)
  member&.site_id == id
end

members_require_approval?()

# File app/models/db/site.rb, line 417
def members_require_approval?
  settings.require_approval?
end

memberspace?()

# File app/models/db/site.rb, line 330
def memberspace?
  subdomain == self.class.memberspace_subdomain
end

notion?()

# File app/models/db/site.rb, line 407
def notion?
  cms == "notion"
end

onboarded!(value: true)

# File app/models/db/site.rb, line 367
def onboarded!(value: true)
  update(welcome: welcome.merge(complete: value))
end

onboarded?()

# File app/models/db/site.rb, line 399
def onboarded?
  onboarding_step_complete?(:complete)
end

onboarding_step_complete?(step)

# File app/models/db/site.rb, line 383
def onboarding_step_complete?(step)
  !!welcome.with_indifferent_access[step]
end

owner=(owner)

# File app/models/db/site.rb, line 291
def owner=(owner)
  super(owner&.becomes(SiteOwner))
end

payment_gateway_connected?()

# File app/models/db/site.rb, line 310
def payment_gateway_connected?
  has_payment_gateway? && stripe_access_token.present?
end

payment_gateway_id()

Alias for: remote_account_id

platform_host()

# File app/models/db/site.rb, line 467
def platform_host
  [subdomain, Rails.application.config.host].join(".")
end

platform_host_with_scheme()

# File app/models/db/site.rb, line 455
def platform_host_with_scheme
  construct_uri(platform_host).to_s
end

remote_account_id()

Also aliased as: payment_gateway_id
# File app/models/db/site.rb, line 299
def remote_account_id
  return unless has_stripe_config?
  stripe["stripe_user_id"]
end

requires_postal_code()

# File app/models/db/site.rb, line 231
def requires_postal_code
  unless Flipper.enabled?(:automatic_payment_methods)
    settings.requires_postal_code
  end
end

requires_postal_code=(value)

# File app/models/db/site.rb, line 237
def requires_postal_code=(value)
  unless Flipper.enabled?(:automatic_payment_methods)
    settings.requires_postal_code = value
  end
end

restore!()

# File app/models/db/site.rb, line 569
def restore!
  update_columns(archived: false, website: website_without_archive)
end

settings()

# File app/models/db/site.rb, line 426
def settings
  super || build_settings
end

settings_custom_style()

# File app/models/db/site.rb, line 500
def settings_custom_style
  settings.custom_style
end

settings_notify_when!(notification_event, set_to_value = true)

# File app/models/db/site.rb, line 508
def settings_notify_when!(notification_event, set_to_value = true)
  settings.notify_when!(notification_event, set_to_value)
end

settings_notify_when?(notification_event)

# File app/models/db/site.rb, line 504
def settings_notify_when?(notification_event)
  settings.notify_when?(notification_event)
end

should_connect_billing?()

# File app/models/db/site.rb, line 557
def should_connect_billing?
  persisted? && !memberspace? && billing_disabled?
end

sso_integration?()

# File app/models/db/site.rb, line 421
def sso_integration?
  # Circle is our only SSO integration currently
  integrations.circle.present?
end

stripe_access_token()

# File app/models/db/site.rb, line 305
def stripe_access_token
  return unless has_stripe_config?
  stripe["access_token"]
end

stripe_account_params()

# File app/models/db/site.rb, line 471
def stripe_account_params
  {stripe_account: payment_gateway_id}
end

sync_owner_subscription_status()

# File app/models/db/site.rb, line 517
def sync_owner_subscription_status
  SiteStatusSyncJob.perform_now(member_id:)
end

theme()

# File app/models/db/site.rb, line 287
def theme
  super || build_theme
end

to_liquid()

# File app/models/db/site.rb, line 488
def to_liquid
  EmailDrops::SiteDrop.new(self)
end

track_features(*features)

# File app/models/db/site.rb, line 512
def track_features(*features)
  tracking = features.map { |f| [f, Time.current] }.to_h
  update(tracked_features: tracked_features.deep_merge(tracking))
end

track_onboarded(step, value: true, force: false)

# File app/models/db/site.rb, line 371
def track_onboarded(step, value: true, force: false)
  return if !force && onboarding_step_complete?(step)

  welcome[step] = value

  if all_onboarding_steps_completed?
    onboarded!(value: value)
  else
    save
  end
end

tracker()

# File app/models/db/site.rb, line 430
def tracker
  super || build_tracker
end

transaction_fee_percent()

# File app/models/db/site.rb, line 479
def transaction_fee_percent
  return 0 unless owner.present? && active_plan.present?
  active_plan.transaction_fee_percent
end

transfer_billing(new_owner:)

# File app/models/db/site.rb, line 529
def transfer_billing(new_owner:)
  validate_transfer!(new_owner) && transfer_billing!(new_owner)
rescue ActiveRecord::RecordInvalid
  false
end

transferred_to_client?()

# File app/models/db/site.rb, line 355
def transferred_to_client?
  built_by_agency? && ownership_transferred_at? && billing_enabled?
end

url()

# File app/models/db/site.rb, line 451
def url
  construct_uri(host).to_s
end

use_design_custom_styles?()

# File app/models/db/site.rb, line 492
def use_design_custom_styles?
  design_theme_custom_styles.present?
end

use_settings_custom_style?()

# File app/models/db/site.rb, line 496
def use_settings_custom_style?
  settings_custom_style.present?
end

valid_origins()

# File app/models/db/site.rb, line 525
def valid_origins
  @valid_origins ||= base_valid_origins_alternated
end

widget_url(path_or_pathname, *args, query: {})

# File app/models/db/site.rb, line 459
def widget_url(path_or_pathname, *args, query: {})
  WidgetUrl.for(path_or_pathname, *args, query:, site: self)
end

widget_v1?()

# File app/models/db/site.rb, line 338
def widget_v1?
  widget_version == 1
end

widget_v2?()

# File app/models/db/site.rb, line 334
def widget_v2?
  widget_version == 2
end

wordpress_plugin_active?()

# File app/models/db/site.rb, line 403
def wordpress_plugin_active?
  wordpress_plugin_version.present?
end