Class: SidebarUrl

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/sidebar_url.rb

Constant Summary collapse

[%r{\A/my/[a-z_\-/]+\z}, %r{\A/pub/[a-z_\-/]+\z}, %r{\A/safe-mode\z}]
MAX_ICON_LENGTH =
40
MAX_NAME_LENGTH =
80
MAX_VALUE_LENGTH =
1000
[
  {
    name: "Topics",
    path: "/latest",
    icon: "layer-group",
    segment: SidebarUrl.segments["primary"],
  },
  {
    name: "My Posts",
    path: "/my/activity",
    icon: "user",
    segment: SidebarUrl.segments["primary"],
  },
  { name: "Review", path: "/review", icon: "flag", segment: SidebarUrl.segments["primary"] },
  { name: "Admin", path: "/admin", icon: "wrench", segment: SidebarUrl.segments["primary"] },
  { name: "Users", path: "/u", icon: "users", segment: SidebarUrl.segments["secondary"] },
  {
    name: "About",
    path: "/about",
    icon: "info-circle",
    segment: SidebarUrl.segments["secondary"],
  },
  {
    name: "FAQ",
    path: "/faq",
    icon: "question-circle",
    segment: SidebarUrl.segments["secondary"],
  },
  { name: "Groups", path: "/g", icon: "user-friends", segment: SidebarUrl.segments["secondary"] },
  {
    name: "Badges",
    path: "/badges",
    icon: "certificate",
    segment: SidebarUrl.segments["secondary"],
  },
]

Instance Method Summary collapse

Instance Method Details

#full_reload?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'app/models/sidebar_url.rb', line 73

def full_reload?
  FULL_RELOAD_LINKS_REGEX.any? { |regex| value =~ regex }
end

#path_validatorObject



55
56
57
58
59
60
61
62
63
# File 'app/models/sidebar_url.rb', line 55

def path_validator
  return true if !external?
  raise ActionController::RoutingError.new("Not Found") if value !~ Discourse::Utils::URI_REGEXP
rescue ActionController::RoutingError
  errors.add(
    :value,
    I18n.t("activerecord.errors.models.sidebar_section_link.attributes.linkable_type.invalid"),
  )
end

#remove_internal_hostnameObject



65
66
67
# File 'app/models/sidebar_url.rb', line 65

def remove_internal_hostname
  self.value = self.value.sub(%r{\Ahttp(s)?://#{Discourse.current_hostname}}, "")
end

#set_externalObject



69
70
71
# File 'app/models/sidebar_url.rb', line 69

def set_external
  self.external = value.start_with?("http://", "https://")
end