Module: Thredded

Defined in:
lib/thredded/database_seeder.rb,
lib/thredded.rb,
lib/thredded/engine.rb,
lib/thredded/errors.rb,
lib/thredded/version.rb,
lib/thredded/db_tools.rb,
app/models/thredded/post.rb,
app/models/thredded/stats.rb,
app/models/thredded/topic.rb,
lib/thredded/base_notifier.rb,
lib/thredded/base_migration.rb,
app/forms/thredded/post_form.rb,
app/models/thredded/category.rb,
app/forms/thredded/topic_form.rb,
app/models/thredded/null_user.rb,
lib/thredded/content_formatter.rb,
lib/thredded/email_transformer.rb,
lib/thredded/view_hooks/config.rb,
app/helpers/thredded/nav_helper.rb,
app/models/thredded/user_detail.rb,
app/helpers/thredded/urls_helper.rb,
app/mailers/thredded/base_mailer.rb,
app/mailers/thredded/post_mailer.rb,
app/models/thredded/messageboard.rb,
app/models/thredded/private_post.rb,
app/models/thredded/private_user.rb,
lib/thredded/view_hooks/renderer.rb,
app/models/thredded/private_topic.rb,
app/models/thredded/user_extender.rb,
app/policies/thredded/post_policy.rb,
app/forms/thredded/edit_topic_form.rb,
app/helpers/thredded/render_helper.rb,
app/models/thredded/topic_category.rb,
app/policies/thredded/topic_policy.rb,
app/view_models/thredded/post_view.rb,
app/commands/thredded/mark_all_read.rb,
app/commands/thredded/moderate_post.rb,
app/models/thredded/user_preference.rb,
app/view_models/thredded/topic_view.rb,
lib/thredded/email_transformer/base.rb,
app/forms/thredded/private_post_form.rb,
lib/thredded/formatting_demo_content.rb,
app/forms/thredded/private_topic_form.rb,
app/models/thredded/messageboard_user.rb,
app/models/thredded/user_topic_follow.rb,
app/notifiers/thredded/email_notifier.rb,
lib/thredded/email_transformer/onebox.rb,
app/commands/thredded/autofollow_users.rb,
app/jobs/thredded/activity_updater_job.rb,
app/models/thredded/messageboard_group.rb,
app/view_hooks/thredded/all_view_hooks.rb,
app/helpers/thredded/application_helper.rb,
app/forms/thredded/user_preferences_form.rb,
app/models/concerns/thredded/post_common.rb,
app/view_models/thredded/base_topic_view.rb,
app/view_models/thredded/posts_page_view.rb,
lib/thredded/html_pipeline/onebox_filter.rb,
app/commands/thredded/create_messageboard.rb,
app/controllers/thredded/posts_controller.rb,
app/mailers/thredded/private_topic_mailer.rb,
app/models/concerns/thredded/topic_common.rb,
app/models/thredded/user_topic_read_state.rb,
app/policies/thredded/messageboard_policy.rb,
app/policies/thredded/private_post_policy.rb,
app/view_models/thredded/topic_email_view.rb,
app/view_models/thredded/topics_page_view.rb,
app/controllers/thredded/topics_controller.rb,
app/models/concerns/thredded/search_parser.rb,
app/models/concerns/thredded/topics_search.rb,
app/models/thredded/post_moderation_record.rb,
app/models/thredded/user_post_notification.rb,
app/policies/thredded/private_topic_policy.rb,
lib/thredded/html_pipeline/autolink_filter.rb,
lib/thredded/html_pipeline/kramdown_filter.rb,
app/view_models/thredded/private_topic_view.rb,
app/commands/thredded/notify_following_users.rb,
app/jobs/thredded/auto_follow_and_notify_job.rb,
lib/thredded/html_pipeline/at_mention_filter.rb,
app/models/concerns/thredded/moderation_state.rb,
app/models/thredded/user_permissions/read/all.rb,
app/controllers/thredded/moderation_controller.rb,
app/models/thredded/null_user_topic_read_state.rb,
app/models/thredded/user_permissions/write/all.rb,
app/view_models/thredded/topic_posts_page_view.rb,
lib/thredded/html_pipeline/wrap_iframes_filter.rb,
app/commands/thredded/at_notification_extractor.rb,
app/controllers/thredded/application_controller.rb,
app/controllers/thredded/preferences_controller.rb,
app/controllers/thredded/read_states_controller.rb,
app/models/thredded/user_permissions/admin/none.rb,
app/models/thredded/user_permissions/write/none.rb,
app/policies/thredded/messageboard_group_policy.rb,
app/commands/thredded/notify_private_topic_users.rb,
app/controllers/concerns/thredded/render_preview.rb,
app/jobs/thredded/notify_private_topic_users_job.rb,
app/mailer_previews/thredded/base_mailer_preview.rb,
app/mailer_previews/thredded/post_mailer_preview.rb,
app/models/concerns/thredded/notifier_preference.rb,
app/models/thredded/user_messageboard_preference.rb,
app/view_models/thredded/messageboard_group_view.rb,
app/controllers/concerns/thredded/new_post_params.rb,
app/controllers/thredded/messageboards_controller.rb,
app/controllers/thredded/post_previews_controller.rb,
app/controllers/thredded/private_posts_controller.rb,
app/models/thredded/user_private_topic_read_state.rb,
app/view_models/thredded/private_topics_page_view.rb,
lib/generators/thredded/install/install_generator.rb,
app/controllers/concerns/thredded/new_topic_params.rb,
app/controllers/thredded/private_topics_controller.rb,
app/controllers/thredded/theme_previews_controller.rb,
app/controllers/thredded/topic_previews_controller.rb,
app/models/thredded/user_permissions/moderate/none.rb,
app/controllers/thredded/post_permalinks_controller.rb,
app/models/thredded/notifications_for_private_topics.rb,
app/models/concerns/thredded/content_moderation_state.rb,
app/models/thredded/notifications_for_followed_topics.rb,
app/controllers/thredded/autocomplete_users_controller.rb,
lib/thredded/collection_to_strings_with_cache_renderer.rb,
app/controllers/thredded/messageboard_groups_controller.rb,
app/controllers/concerns/thredded/new_private_post_params.rb,
app/controllers/thredded/private_post_previews_controller.rb,
app/mailer_previews/thredded/private_topic_mailer_preview.rb,
app/models/concerns/thredded/user_topic_read_state_common.rb,
app/controllers/concerns/thredded/new_private_topic_params.rb,
app/controllers/thredded/private_topic_previews_controller.rb,
app/controllers/thredded/private_post_permalinks_controller.rb,
app/models/thredded/user_permissions/admin/if_admin_column_true.rb,
app/models/thredded/messageboard_notifications_for_followed_topics.rb,
app/models/concerns/thredded/friendly_id_reserved_words_and_pagination.rb,
app/models/thredded/user_permissions/moderate/if_moderator_column_true.rb,
app/models/thredded/user_permissions/message/readers_of_writeable_boards.rb

Overview

rubocop:enable HandleExceptions

Defined Under Namespace

Modules: ApplicationHelper, ContentModerationState, DbTools, EmailTransformer, Errors, FormattingDemoContent, Generators, HtmlPipeline, ModeratePost, ModerationState, NavHelper, NewPostParams, NewPrivatePostParams, NewPrivateTopicParams, NewTopicParams, NotifierPreference, PostCommon, RenderHelper, RenderPreview, TopicCommon, UrlsHelper, UserExtender, UserPermissions, UserTopicReadStateCommon, ViewHooks Classes: ActivityUpdaterJob, AllViewHooks, ApplicationController, AtNotificationExtractor, AutoFollowAndNotifyJob, AutocompleteUsersController, AutofollowUsers, BaseMailer, BaseMailerPreview, BaseMigration, BaseNotifier, BaseTopicView, Category, CollectionToStringsWithCacheRenderer, ContentFormatter, CreateMessageboard, DatabaseSeeder, EditTopicForm, EmailNotifier, Engine, Error, FriendlyIdReservedWordsAndPagination, MarkAllRead, Messageboard, MessageboardGroup, MessageboardGroupPolicy, MessageboardGroupView, MessageboardGroupsController, MessageboardNotificationsForFollowedTopics, MessageboardPolicy, MessageboardUser, MessageboardsController, ModerationController, NotificationsForFollowedTopics, NotificationsForPrivateTopics, NotifyFollowingUsers, NotifyPrivateTopicUsers, NotifyPrivateTopicUsersJob, NullUser, NullUserTopicReadState, Post, PostForm, PostMailer, PostMailerPreview, PostModerationRecord, PostPermalinksController, PostPolicy, PostPreviewsController, PostView, PostsController, PostsPageView, PreferencesController, PrivatePost, PrivatePostForm, PrivatePostPermalinksController, PrivatePostPolicy, PrivatePostPreviewsController, PrivatePostsController, PrivateTopic, PrivateTopicForm, PrivateTopicMailer, PrivateTopicMailerPreview, PrivateTopicPolicy, PrivateTopicPreviewsController, PrivateTopicView, PrivateTopicsController, PrivateTopicsPageView, PrivateUser, ReadStatesController, SearchParser, Stats, ThemePreviewsController, Topic, TopicCategory, TopicEmailView, TopicForm, TopicPolicy, TopicPostsPageView, TopicPreviewsController, TopicView, TopicsController, TopicsPageView, TopicsSearch, UserDetail, UserMessageboardPreference, UserPostNotification, UserPreference, UserPreferencesForm, UserPrivateTopicReadState, UserTopicFollow, UserTopicReadState

Constant Summary collapse

VERSION =
'0.14.5'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.messageboards_order=(value) ⇒ Object

Parameters:

  • value (:position, :topics_count_desc, :last_post_at_desc)


133
134
135
136
137
138
139
140
# File 'lib/thredded.rb', line 133

def self.messageboards_order=(value)
  case value
  when :position, :topics_count_desc, :last_post_at_desc
    @@messageboards_order = value # rubocop:disable Style/ClassVars
  else
    fail ArgumentError, "Unexpected value for Thredded.messageboards_order: #{value}"
  end
end

.notifiersObject



119
120
121
# File 'lib/thredded.rb', line 119

def self.notifiers
  @@notifiers ||= [Thredded::EmailNotifier.new] # rubocop:disable Style/ClassVars
end

.notifiers=(notifiers) ⇒ Object



123
124
125
126
# File 'lib/thredded.rb', line 123

def self.notifiers=(notifiers)
  notifiers.each { |notifier| BaseNotifier.validate_notifier(notifier) }
  @@notifiers = notifiers # rubocop:disable Style/ClassVars
end

.posts_page_view(scope:, current_user:) ⇒ PostsPageView

Returns a view for the given posts’ scope, applying read permission filters to the scope. Can be used in main_app, e.g. for showing the recent user posts on the profile page.

Parameters:

  • scope (ActiveRecord::Relation<Thredded::Post>)

    the posts scope for which to return the view.

  • current_user (Thredded.user_class, nil)

    the user viewing the posts.

Returns:



175
176
177
178
179
180
181
182
183
# File 'lib/thredded.rb', line 175

def self.posts_page_view(scope:, current_user:)
  current_user ||= Thredded::NullUser.new
  PostsPageView.new(
    current_user,
    Pundit.policy_scope!(current_user, scope)
      .where(messageboard_id: Pundit.policy_scope!(current_user, Thredded::Messageboard.all).pluck(:id))
      .includes(:postable)
  )
end

.rails_gte_51?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


186
187
188
189
# File 'lib/thredded.rb', line 186

def self.rails_gte_51?
  @rails_gte_51 = (Rails.gem_version >= Gem::Version.new('5.1.0')) if @rails_gte_51.nil?
  @rails_gte_51
end

.standalone_layout?Boolean

Whether the layout is a thredded layout as opposed to the application layout.

Returns:

  • (Boolean)


165
166
167
# File 'lib/thredded.rb', line 165

def self.standalone_layout?
  layout.is_a?(String) && layout.start_with?('thredded/')
end

.user_classClass<Thredded::UserExtender>

Returns the user class from the host application.

Returns:



151
152
153
154
155
# File 'lib/thredded.rb', line 151

def self.user_class
  # This is nil before the initializer is installed.
  return nil if @@user_class_name.nil?
  @@user_class_name.constantize
end

.user_class=(user_class_name) ⇒ Object

Parameters:

  • user_class_name (String)


143
144
145
146
147
148
# File 'lib/thredded.rb', line 143

def self.user_class=(user_class_name)
  unless user_class_name.is_a?(String)
    fail "Thredded.user_class must be set to a String, got #{user_class_name.inspect}"
  end
  @@user_class_name = user_class_name # rubocop:disable Style/ClassVars
end

.user_display_name_methodObject



128
129
130
# File 'lib/thredded.rb', line 128

def self.user_display_name_method
  @@user_display_name_method || user_name_column
end

.user_path(view_context, user) ⇒ String

Returns path to the user evaluated in the specified context.

Parameters:

Returns:

  • (String)

    path to the user evaluated in the specified context.



160
161
162
# File 'lib/thredded.rb', line 160

def self.user_path(view_context, user)
  view_context.instance_exec(user, &@@user_path)
end

.view_hooksThredded::AllViewHooks

Returns View hooks configuration.

Returns:



111
112
113
114
115
116
117
# File 'lib/thredded.rb', line 111

def self.view_hooks
  instance = Thredded::AllViewHooks.instance
  unless instance
    fail '`Thredded.view_hooks` must be configured in a `Rails.application.config.to_prepare` block!'
  end
  instance
end

Instance Method Details

#admin_columnSymbol

Returns The name of the admin flag column on the users table for the default permissions model.

Returns:

  • (Symbol)

    The name of the admin flag column on the users table for the default permissions model



65
# File 'lib/thredded.rb', line 65

mattr_accessor :admin_column

#auto_follow_when_creating_topicBoolean

Returns Whether the user should get subscribed to a new topic they’ve created.

Returns:

  • (Boolean)

    Whether the user should get subscribed to a new topic they’ve created.



88
# File 'lib/thredded.rb', line 88

mattr_accessor :auto_follow_when_creating_topic

#auto_follow_when_posting_in_topicBoolean

Returns Whether the user should get subscribed to a topic after posting in it.

Returns:

  • (Boolean)

    Whether the user should get subscribed to a topic after posting in it.



92
# File 'lib/thredded.rb', line 92

mattr_accessor :auto_follow_when_posting_in_topic

#content_visible_while_pending_moderationBoolean

Returns Whether posts that are pending moderation are visible to regular users.

Returns:

  • (Boolean)

    Whether posts that are pending moderation are visible to regular users.



68
# File 'lib/thredded.rb', line 68

mattr_accessor :content_visible_while_pending_moderation

#current_user_methodSymbol

Returns The name of the method used by Thredded controllers and views to fetch the currently signed-in user.

Returns:

  • (Symbol)

    The name of the method used by Thredded controllers and views to fetch the currently signed-in user



59
# File 'lib/thredded.rb', line 59

mattr_accessor :current_user_method

#moderator_columnSymbol

Returns The name of the moderator flag column on the users table for the default permissions model.

Returns:

  • (Symbol)

    The name of the moderator flag column on the users table for the default permissions model



62
# File 'lib/thredded.rb', line 62

mattr_accessor :moderator_column

#notifiersArray

Returns The notifiers, by default just the EmailNotifier.

Returns:

  • (Array)

    The notifiers, by default just the EmailNotifier



71
# File 'lib/thredded.rb', line 71

mattr_accessor :notifiers

#parent_mailerString

Returns The name of the parent mailer class for Thredded mailers.

Returns:

  • (String)

    The name of the parent mailer class for Thredded mailers.



80
# File 'lib/thredded.rb', line 80

mattr_accessor :parent_mailer

#show_topic_followersBoolean

Returns Whether users that are following a topic are listed on topic page.

Returns:

  • (Boolean)

    Whether users that are following a topic are listed on topic page.



74
# File 'lib/thredded.rb', line 74

mattr_accessor :show_topic_followers

#slugifierProc

Returns The proc that Thredded uses to generate URL slugs from text.

Returns:

  • (Proc)

    The proc that Thredded uses to generate URL slugs from text.



84
# File 'lib/thredded.rb', line 84

mattr_accessor :slugifier

#user_class_nameString

Returns The name of the user class.

Returns:

  • (String)

    The name of the user class



96
# File 'lib/thredded.rb', line 96

mattr_reader :user_class_name

#user_display_name_methodSymbol

Returns The name of the method used by Thredded to display users.

Returns:

  • (Symbol)

    The name of the method used by Thredded to display users



77
# File 'lib/thredded.rb', line 77

mattr_accessor :user_display_name_method