thredded 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.mkdn +63 -0
- data/Procfile +1 -0
- data/README.mkdn +42 -20
- data/app/assets/images/thredded/private-messages.svg +4 -0
- data/app/assets/images/thredded/settings.svg +4 -0
- data/app/assets/javascripts/thredded.es6 +2 -10
- data/app/assets/javascripts/thredded/{currently_online.es6 → components/currently_online.es6} +0 -0
- data/app/assets/javascripts/thredded/{post_form.es6 → components/post_form.es6} +0 -0
- data/app/assets/javascripts/thredded/{time_stamps.es6 → components/time_stamps.es6} +0 -0
- data/app/assets/javascripts/thredded/{topic_form.es6 → components/topic_form.es6} +1 -1
- data/app/assets/javascripts/thredded/components/topics.es6 +37 -0
- data/app/assets/javascripts/thredded/components/user_preferences_form.es6 +45 -0
- data/app/assets/javascripts/thredded/components/users_select.es6 +56 -0
- data/app/assets/javascripts/thredded/dependencies.js +9 -0
- data/app/assets/javascripts/thredded/thredded.es6 +1 -0
- data/app/assets/stylesheets/thredded/_base.scss +3 -2
- data/app/assets/stylesheets/thredded/_thredded.scss +4 -1
- data/app/assets/stylesheets/thredded/base/_buttons.scss +2 -1
- data/app/assets/stylesheets/thredded/base/_forms.scss +23 -18
- data/app/assets/stylesheets/thredded/base/_grid.scss +1 -1
- data/app/assets/stylesheets/thredded/base/_nav.scss +21 -0
- data/app/assets/stylesheets/thredded/base/_tables.scss +5 -14
- data/app/assets/stylesheets/thredded/base/_typography.scss +9 -4
- data/app/assets/stylesheets/thredded/base/_variables.scss +28 -9
- data/app/assets/stylesheets/thredded/components/_alerts.scss +19 -0
- data/app/assets/stylesheets/thredded/components/_currently-online.scss +1 -1
- data/app/assets/stylesheets/thredded/components/_form-list.scss +2 -4
- data/app/assets/stylesheets/thredded/components/_icons.scss +3 -0
- data/app/assets/stylesheets/thredded/components/_messageboard.scss +4 -4
- data/app/assets/stylesheets/thredded/components/_pagination.scss +2 -2
- data/app/assets/stylesheets/thredded/components/_post-form.scss +3 -0
- data/app/assets/stylesheets/thredded/components/_post.scss +14 -4
- data/app/assets/stylesheets/thredded/components/_select2.scss +79 -9
- data/app/assets/stylesheets/thredded/components/_topic-header.scss +11 -1
- data/app/assets/stylesheets/thredded/components/_topics.scss +13 -11
- data/app/assets/stylesheets/thredded/layout/_main-container.scss +3 -3
- data/app/assets/stylesheets/thredded/layout/_main-navigation.scss +11 -17
- data/app/assets/stylesheets/thredded/layout/_navigation.scss +72 -0
- data/app/assets/stylesheets/thredded/layout/_search-navigation.scss +66 -0
- data/app/assets/stylesheets/thredded/layout/_user-navigation.scss +35 -61
- data/app/commands/thredded/at_notification_extractor.rb +1 -0
- data/app/commands/thredded/members_marked_notified.rb +1 -0
- data/app/commands/thredded/messageboard_destroyer.rb +7 -2
- data/app/commands/thredded/notify_mentioned_users.rb +8 -21
- data/app/commands/thredded/notify_private_topic_users.rb +3 -5
- data/app/controllers/thredded/application_controller.rb +76 -41
- data/app/controllers/thredded/autocomplete_users_controller.rb +46 -0
- data/app/controllers/thredded/messageboards_controller.rb +8 -5
- data/app/controllers/thredded/posts_controller.rb +20 -22
- data/app/controllers/thredded/preferences_controller.rb +19 -14
- data/app/controllers/thredded/private_topics_controller.rb +58 -23
- data/app/controllers/thredded/setups_controller.rb +1 -0
- data/app/controllers/thredded/theme_previews_controller.rb +24 -53
- data/app/controllers/thredded/topics_controller.rb +48 -77
- data/app/forms/thredded/private_topic_form.rb +1 -21
- data/app/forms/thredded/topic_form.rb +3 -7
- data/app/forms/thredded/user_preferences_form.rb +62 -0
- data/app/helpers/thredded/application_helper.rb +11 -12
- data/app/helpers/thredded/urls_helper.rb +103 -0
- data/app/jobs/thredded/activity_updater_job.rb +4 -3
- data/app/jobs/thredded/at_notifier_job.rb +1 -0
- data/app/jobs/thredded/notify_private_topic_users_job.rb +1 -0
- data/app/mailer_previews/thredded/base_mailer_preview.rb +101 -0
- data/app/mailer_previews/thredded/post_mailer_preview.rb +11 -0
- data/app/mailer_previews/thredded/private_post_mailer_preview.rb +11 -0
- data/app/mailer_previews/thredded/private_topic_mailer_preview.rb +15 -0
- data/app/mailers/thredded/base_mailer.rb +13 -0
- data/app/mailers/thredded/post_mailer.rb +4 -2
- data/app/mailers/thredded/private_post_mailer.rb +4 -2
- data/app/mailers/thredded/private_topic_mailer.rb +4 -2
- data/app/models/concerns/thredded/friendly_id_reserved_words_and_pagination.rb +16 -0
- data/app/models/concerns/thredded/post_common.rb +68 -63
- data/app/models/concerns/thredded/topic_common.rb +31 -8
- data/app/models/concerns/thredded/user_topic_read_state_common.rb +31 -0
- data/app/models/thredded/category.rb +1 -0
- data/app/models/thredded/messageboard.rb +24 -25
- data/app/models/thredded/messageboard_user.rb +1 -0
- data/app/models/thredded/null_preference.rb +1 -0
- data/app/models/thredded/null_user.rb +1 -6
- data/app/models/thredded/null_user_topic_read_state.rb +12 -0
- data/app/models/thredded/post.rb +6 -9
- data/app/models/thredded/post_notification.rb +1 -0
- data/app/models/thredded/private_post.rb +6 -2
- data/app/models/thredded/private_topic.rb +46 -32
- data/app/models/thredded/private_user.rb +3 -2
- data/app/models/thredded/stats.rb +1 -0
- data/app/models/thredded/topic.rb +40 -64
- data/app/models/thredded/topic_category.rb +1 -0
- data/app/models/thredded/user_detail.rb +2 -15
- data/app/models/thredded/user_extender.rb +29 -14
- data/app/models/thredded/user_messageboard_preference.rb +20 -0
- data/app/models/thredded/user_permissions/admin/if_admin_column_true.rb +1 -0
- data/app/models/thredded/user_permissions/admin/none.rb +1 -0
- data/app/models/thredded/user_permissions/message/readers_of_writeable_boards.rb +1 -0
- data/app/models/thredded/user_permissions/moderate/if_moderator_column_true.rb +1 -0
- data/app/models/thredded/user_permissions/moderate/none.rb +1 -0
- data/app/models/thredded/user_permissions/read/all.rb +1 -0
- data/app/models/thredded/user_permissions/write/all.rb +1 -0
- data/app/models/thredded/user_permissions/write/none.rb +1 -0
- data/app/models/thredded/user_preference.rb +7 -1
- data/app/models/thredded/user_private_topic_read_state.rb +12 -0
- data/app/models/thredded/user_topic_read_state.rb +12 -0
- data/app/policies/thredded/messageboard_policy.rb +27 -0
- data/app/policies/thredded/post_policy.rb +33 -0
- data/app/policies/thredded/private_post_policy.rb +29 -0
- data/app/policies/thredded/private_topic_policy.rb +23 -0
- data/app/policies/thredded/topic_policy.rb +32 -0
- data/app/view_models/thredded/base_topic_view.rb +56 -0
- data/app/view_models/thredded/post_view.rb +44 -0
- data/app/view_models/thredded/posts_page_view.rb +27 -0
- data/app/view_models/thredded/private_topic_view.rb +9 -0
- data/app/{decorators/thredded/topic_email_decorator.rb → view_models/thredded/topic_email_view.rb} +2 -1
- data/app/view_models/thredded/topic_view.rb +23 -0
- data/app/view_models/thredded/topics_page_view.rb +26 -0
- data/app/views/thredded/error_pages/forbidden.html.erb +6 -0
- data/app/views/thredded/error_pages/not_found.html.erb +6 -0
- data/app/views/thredded/messageboards/_messageboard.html.erb +13 -6
- data/app/views/thredded/messageboards/index.html.erb +2 -8
- data/app/views/thredded/messageboards/new.html.erb +8 -2
- data/app/views/thredded/post_mailer/at_notification.html.erb +3 -3
- data/app/views/thredded/post_mailer/at_notification.text.erb +1 -1
- data/app/views/thredded/posts/_content_field.html.erb +1 -1
- data/app/views/thredded/posts/_form.html.erb +5 -1
- data/app/views/thredded/posts/_post.html.erb +3 -1
- data/app/views/thredded/posts/edit.html.erb +7 -3
- data/app/views/thredded/posts_common/_form.html.erb +1 -1
- data/app/views/thredded/posts_common/_post.html.erb +14 -8
- data/app/views/thredded/preferences/_form.html.erb +37 -15
- data/app/views/thredded/preferences/_header.html.erb +1 -1
- data/app/views/thredded/preferences/edit.html.erb +4 -6
- data/app/views/thredded/private_post_mailer/at_notification.html.erb +6 -4
- data/app/views/thredded/private_posts/_form.html.erb +5 -1
- data/app/views/thredded/private_posts/_private_post.html.erb +3 -1
- data/app/views/thredded/private_topic_mailer/message_notification.html.erb +3 -7
- data/app/views/thredded/private_topic_mailer/message_notification.text.erb +1 -3
- data/app/views/thredded/private_topics/_breadcrumbs.html.erb +2 -2
- data/app/views/thredded/private_topics/_form.html.erb +15 -10
- data/app/views/thredded/private_topics/_header.html.erb +12 -0
- data/app/views/thredded/private_topics/_no_private_topics.html.erb +2 -2
- data/app/views/thredded/private_topics/_private_topic.html.erb +4 -6
- data/app/views/thredded/private_topics/edit.html.erb +32 -0
- data/app/views/thredded/private_topics/index.html.erb +5 -5
- data/app/views/thredded/private_topics/new.html.erb +1 -2
- data/app/views/thredded/private_topics/show.html.erb +12 -7
- data/app/views/thredded/search/_form.html.erb +9 -6
- data/app/views/thredded/shared/{_messageboard_topics_breadcrumbs.html.erb → _breadcrumbs.html.erb} +2 -2
- data/app/views/thredded/shared/_header.html.erb +2 -3
- data/app/views/thredded/shared/_nav.html.erb +20 -0
- data/app/views/thredded/shared/nav/_notification_preferences.html.erb +6 -0
- data/app/views/thredded/shared/nav/_private_topics.html.erb +11 -0
- data/app/views/thredded/shared/nav/_standalone.html.erb +12 -0
- data/app/views/thredded/theme_previews/_section_title.html.erb +2 -2
- data/app/views/thredded/theme_previews/show.html.erb +13 -17
- data/app/views/thredded/topics/_form.html.erb +8 -6
- data/app/views/thredded/topics/_header.html.erb +12 -0
- data/app/views/thredded/topics/_topic.html.erb +4 -8
- data/app/views/thredded/topics/_topic_form_admin_options.html.erb +1 -1
- data/app/views/thredded/topics/edit.html.erb +22 -18
- data/app/views/thredded/topics/index.html.erb +3 -3
- data/app/views/thredded/topics/new.html.erb +1 -1
- data/app/views/thredded/topics/search.html.erb +17 -5
- data/app/views/thredded/topics/show.html.erb +14 -11
- data/bin/rails +5 -0
- data/config.ru +3 -0
- data/config/i18n-tasks.yml +16 -0
- data/config/locales/en.yml +90 -0
- data/config/routes.rb +29 -15
- data/db/migrate/20160329231848_create_thredded.rb +29 -33
- data/db/seeds.rb +115 -0
- data/db/upgrade_migrations/20160410111522_upgrade_v0_2_to_v0_3.rb +59 -0
- data/heroku.gemfile +26 -0
- data/heroku.gemfile.lock +282 -0
- data/lib/generators/thredded/install/install_generator.rb +1 -0
- data/lib/generators/thredded/install/templates/initializer.rb +17 -0
- data/lib/html/pipeline/at_mention_filter.rb +2 -1
- data/lib/html/pipeline/bbcode_filter.rb +13 -4
- data/lib/tasks/thredded_tasks.rake +1 -0
- data/lib/thredded.rb +19 -17
- data/lib/thredded/at_users.rb +1 -0
- data/lib/thredded/engine.rb +14 -5
- data/lib/thredded/errors.rb +11 -11
- data/lib/thredded/main_app_route_delegator.rb +1 -0
- data/lib/thredded/search_parser.rb +2 -1
- data/lib/thredded/topics_search.rb +67 -0
- data/lib/thredded/version.rb +2 -1
- data/thredded.gemspec +12 -8
- metadata +146 -82
- data/app/assets/javascripts/thredded/users_select.es6 +0 -5
- data/app/assets/stylesheets/thredded/layout/_topic-navigation.scss +0 -53
- data/app/commands/thredded/user_reads_private_topic.rb +0 -22
- data/app/commands/thredded/user_resets_private_topic_to_unread.rb +0 -23
- data/app/decorators/thredded/base_topic_decorator.rb +0 -14
- data/app/decorators/thredded/base_user_topic_decorator.rb +0 -63
- data/app/decorators/thredded/messageboard_decorator.rb +0 -41
- data/app/decorators/thredded/post_decorator.rb +0 -40
- data/app/decorators/thredded/private_topic_decorator.rb +0 -23
- data/app/decorators/thredded/topic_decorator.rb +0 -25
- data/app/decorators/thredded/user_private_topic_decorator.rb +0 -13
- data/app/decorators/thredded/user_topic_decorator.rb +0 -37
- data/app/models/thredded/ability.rb +0 -60
- data/app/models/thredded/notification_preference.rb +0 -17
- data/app/models/thredded/null_topic.rb +0 -15
- data/app/models/thredded/null_topic_read.rb +0 -19
- data/app/models/thredded/user_topic_read.rb +0 -10
- data/app/views/thredded/shared/_notification_preferences.html.erb +0 -7
- data/app/views/thredded/shared/_top_nav.html.erb +0 -36
- data/app/views/thredded/shared/_topic_nav.html.erb +0 -22
- data/app/views/thredded/topics/_recent_topics_by_user.html.erb +0 -8
- data/app/views/thredded/topics/by_category.html.erb +0 -56
- data/app/views/thredded/topics_common/_header.html.erb +0 -6
- data/lib/thredded/messageboard_user_permissions.rb +0 -22
- data/lib/thredded/post_sql_builder.rb +0 -12
- data/lib/thredded/post_user_permissions.rb +0 -32
- data/lib/thredded/private_topic_user_permissions.rb +0 -26
- data/lib/thredded/search_sql_builder.rb +0 -21
- data/lib/thredded/seed_database.rb +0 -76
- data/lib/thredded/table_sql_builder.rb +0 -41
- data/lib/thredded/topic_sql_builder.rb +0 -11
- data/lib/thredded/topic_user_permissions.rb +0 -32
@@ -1,10 +0,0 @@
|
|
1
|
-
module Thredded
|
2
|
-
class UserTopicRead < ActiveRecord::Base
|
3
|
-
belongs_to :topic
|
4
|
-
belongs_to :user, class_name: Thredded.user_class
|
5
|
-
belongs_to :farthest_post,
|
6
|
-
class_name: 'Thredded::Post', foreign_key: 'post_id'
|
7
|
-
validates :user_id, uniqueness: { scope: :topic }
|
8
|
-
belongs_to :post
|
9
|
-
end
|
10
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
<% unless !messageboard.try(:persisted?) && !Thredded.standalone_layout? %>
|
2
|
-
<nav class="thredded--user-navigation" role="navigation">
|
3
|
-
<div class="thredded--user-navigation--search">
|
4
|
-
<%= render 'thredded/search/form' %>
|
5
|
-
</div>
|
6
|
-
|
7
|
-
<ul class="thredded--user-navigation--actions">
|
8
|
-
<% if signed_in? %>
|
9
|
-
<% if Thredded.standalone_layout? %>
|
10
|
-
<li>
|
11
|
-
<%= link_to user_path(thredded_current_user) do %>
|
12
|
-
<span><%= thredded_current_user %></span>
|
13
|
-
<% end %>
|
14
|
-
</li>
|
15
|
-
<% end %>
|
16
|
-
|
17
|
-
<%= render 'thredded/shared/notification_preferences',
|
18
|
-
messageboard: messageboard %>
|
19
|
-
|
20
|
-
<% if Thredded.standalone_layout? %>
|
21
|
-
<li>
|
22
|
-
<%= link_to main_app.session_path, method: :delete do %>
|
23
|
-
<span>Sign Out</span>
|
24
|
-
<% end %>
|
25
|
-
</li>
|
26
|
-
<% end %>
|
27
|
-
<% elsif Thredded.standalone_layout? %>
|
28
|
-
<li>
|
29
|
-
<%= link_to main_app.sessions_new_path do %>
|
30
|
-
<span>Sign In / Register</span>
|
31
|
-
<% end %>
|
32
|
-
</li>
|
33
|
-
<% end %>
|
34
|
-
</ul>
|
35
|
-
</nav>
|
36
|
-
<% end %>
|
@@ -1,22 +0,0 @@
|
|
1
|
-
<div class="thredded--main-navigation">
|
2
|
-
<%= yield :thredded_breadcrumbs %>
|
3
|
-
|
4
|
-
<ul class="thredded--topic-navigation">
|
5
|
-
<% if messageboard.try(:persisted?) -%>
|
6
|
-
<li class="thredded--topic-navigation--public">
|
7
|
-
<%= link_to 'Topics', messageboard_topics_path(messageboard) %>
|
8
|
-
</li>
|
9
|
-
<% end -%>
|
10
|
-
|
11
|
-
<li class="thredded--topic-navigation--private">
|
12
|
-
<%= link_to private_topics_path do %>
|
13
|
-
Private Topics
|
14
|
-
<% if unread_private_topics_count > 0 -%>
|
15
|
-
<span class="thredded--topic-navigation--unread">
|
16
|
-
<%= unread_private_topics_count %>
|
17
|
-
</span>
|
18
|
-
<% end -%>
|
19
|
-
<% end -%>
|
20
|
-
</li>
|
21
|
-
</ul>
|
22
|
-
</div>
|
@@ -1,8 +0,0 @@
|
|
1
|
-
<% if current_ability.can? :read, topic %>
|
2
|
-
<tr>
|
3
|
-
<td class="title table-first-column"> <%= topic.title %> </td>
|
4
|
-
<td class="replies"> <%= topic.posts_count %> </td>
|
5
|
-
<td class="created"> <%= formatted_user_profile_date(topic.created_at) %> </td>
|
6
|
-
<td class="updated"> <%= formatted_user_profile_date(topic.updated_at) %> </td>
|
7
|
-
</tr>
|
8
|
-
<% end %>
|
@@ -1,56 +0,0 @@
|
|
1
|
-
<% content_for :thredded_page_title, 'Topic Categories' %>
|
2
|
-
<% content_for :thredded_page_id, 'thredded--topic-categories' %>
|
3
|
-
|
4
|
-
<% content_for :breadcrumbs do %>
|
5
|
-
<ul class="breadcrumbs">
|
6
|
-
<li><%= link_to 'Forums', root_path %></li>
|
7
|
-
<li><%= link_to messageboard.title, messageboard_topics_path(messageboard) %></li>
|
8
|
-
<li><span>Category</span></li>
|
9
|
-
</ul>
|
10
|
-
<% end %>
|
11
|
-
|
12
|
-
<% content_for :actions do %>
|
13
|
-
<ul class="actions">
|
14
|
-
<%= render 'thredded/search/form' %>
|
15
|
-
|
16
|
-
<% if current_ability.can? :create, Thredded::Topic %>
|
17
|
-
<li class='new_topic'>
|
18
|
-
<%= link_to 'new topic', new_messageboard_topic_path(messageboard) %>
|
19
|
-
</li>
|
20
|
-
<li class='new_private_topic'>
|
21
|
-
<%= link_to 'private topic', new_messageboard_topic_path(messageboard) %>
|
22
|
-
</li>
|
23
|
-
<% end %>
|
24
|
-
</ul>
|
25
|
-
<% end %>
|
26
|
-
|
27
|
-
<%= thredded_page do %>
|
28
|
-
<header>
|
29
|
-
<nav>
|
30
|
-
<%= yield :breadcrumbs %>
|
31
|
-
<%= yield :actions %>
|
32
|
-
</nav>
|
33
|
-
|
34
|
-
<%= render 'thredded/shared/currently_online' %>
|
35
|
-
</header>
|
36
|
-
|
37
|
-
<section class="topics">
|
38
|
-
<% if @sticky.any? %>
|
39
|
-
<div class="stuck">
|
40
|
-
<%= render partial: 'thredded/topics/topic_condensed', collection: @sticky, as: :t %>
|
41
|
-
</div>
|
42
|
-
<% end %>
|
43
|
-
|
44
|
-
<div class="currently">
|
45
|
-
<%= render partial: 'thredded/topics/topic_condensed', collection: @topics, as: :t %>
|
46
|
-
</div>
|
47
|
-
</section>
|
48
|
-
|
49
|
-
<footer>
|
50
|
-
<%= paginate @topics %>
|
51
|
-
<nav>
|
52
|
-
<%= yield :actions %>
|
53
|
-
<%= yield :breadcrumbs %>
|
54
|
-
</nav>
|
55
|
-
</footer>
|
56
|
-
<% end %>
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module Thredded
|
2
|
-
class MessageboardUserPermissions
|
3
|
-
attr_reader :messageboard, :user
|
4
|
-
|
5
|
-
def initialize(messageboard, user)
|
6
|
-
@messageboard = messageboard
|
7
|
-
@user = user
|
8
|
-
end
|
9
|
-
|
10
|
-
def readable?
|
11
|
-
user.thredded_can_read_messageboards.include?(messageboard)
|
12
|
-
end
|
13
|
-
|
14
|
-
def postable?
|
15
|
-
user.thredded_can_write_messageboards.include?(messageboard)
|
16
|
-
end
|
17
|
-
|
18
|
-
def moderatable?
|
19
|
-
user.thredded_can_moderate_messageboards.include?(messageboard)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
module Thredded
|
2
|
-
class PostSqlBuilder < TableSqlBuilder
|
3
|
-
def apply_filters
|
4
|
-
@scope = @scope.joins(:topic_categories).where(category_id: categories) if categories.present?
|
5
|
-
return unless users.present? || text.present?
|
6
|
-
posts_scope = Thredded::Post
|
7
|
-
posts_scope = posts_scope.where(user_id: users) if users.present?
|
8
|
-
posts_scope = DbTextSearch::FullTextSearch.new(posts_scope, :content).find(text) if text.present?
|
9
|
-
@scope = @scope.joins(:posts).merge(posts_scope)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module Thredded
|
2
|
-
class PostUserPermissions
|
3
|
-
def initialize(post, user, _user_details)
|
4
|
-
@post = post
|
5
|
-
@topic = post.postable
|
6
|
-
@messageboard_user_permission = MessageboardUserPermissions.new(post.messageboard, user)
|
7
|
-
@user = user
|
8
|
-
end
|
9
|
-
|
10
|
-
def editable?
|
11
|
-
created_post? || @messageboard_user_permission.moderatable?
|
12
|
-
end
|
13
|
-
|
14
|
-
def manageable?
|
15
|
-
created_post? || @messageboard_user_permission.moderatable?
|
16
|
-
end
|
17
|
-
|
18
|
-
def creatable?
|
19
|
-
thread_is_not_locked? && @messageboard_user_permission.postable?
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
def created_post?
|
25
|
-
@user.id == @post.user_id
|
26
|
-
end
|
27
|
-
|
28
|
-
def thread_is_not_locked?
|
29
|
-
@topic.private? || !@topic.locked?
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
module Thredded
|
2
|
-
class PrivateTopicUserPermissions
|
3
|
-
def initialize(private_topic, user, _user_details)
|
4
|
-
@private_topic = private_topic
|
5
|
-
@user = user
|
6
|
-
end
|
7
|
-
|
8
|
-
def readable?
|
9
|
-
@private_topic.users.include?(@user)
|
10
|
-
end
|
11
|
-
|
12
|
-
def manageable?
|
13
|
-
user_started_topic?
|
14
|
-
end
|
15
|
-
|
16
|
-
def creatable?
|
17
|
-
!@user.thredded_anonymous?
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
def user_started_topic?
|
23
|
-
@user.id == @private_topic.user_id
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'thredded/topic_sql_builder'
|
2
|
-
require 'thredded/post_sql_builder'
|
3
|
-
|
4
|
-
module Thredded
|
5
|
-
class SearchSqlBuilder
|
6
|
-
def initialize(query, messageboard)
|
7
|
-
@topic_builder = TopicSqlBuilder.new(query, messageboard)
|
8
|
-
@post_builder = PostSqlBuilder.new(query, messageboard)
|
9
|
-
@order_by = 'ORDER BY updated_at DESC'
|
10
|
-
end
|
11
|
-
|
12
|
-
def build
|
13
|
-
[
|
14
|
-
'SELECT * FROM thredded_topics WHERE id IN (', @post_builder.sql,
|
15
|
-
'UNION', @topic_builder.sql,
|
16
|
-
')', @order_by,
|
17
|
-
'LIMIT 50'
|
18
|
-
].join(' ')
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,76 +0,0 @@
|
|
1
|
-
require 'factory_girl_rails'
|
2
|
-
|
3
|
-
# rubocop:disable HandleExceptions
|
4
|
-
begin
|
5
|
-
if FactoryGirl.factories.instance_variable_get(:@items).none?
|
6
|
-
require_relative '../../../spec/factories'
|
7
|
-
end
|
8
|
-
rescue NameError
|
9
|
-
end
|
10
|
-
# rubocop:enable HandleExceptions
|
11
|
-
|
12
|
-
module Thredded
|
13
|
-
class SeedDatabase
|
14
|
-
attr_reader :user, :users, :messageboard, :topics, :private_topics, :posts
|
15
|
-
|
16
|
-
def self.run(users: 5, topics: 26, posts: (0..20))
|
17
|
-
s = new
|
18
|
-
s.create_messageboard
|
19
|
-
s.create_first_user
|
20
|
-
s.create_users(count: users)
|
21
|
-
s.create_topics(count: topics)
|
22
|
-
s.create_posts(count: posts)
|
23
|
-
s.create_private_posts(count: posts)
|
24
|
-
end
|
25
|
-
|
26
|
-
def create_first_user
|
27
|
-
@user ||= begin
|
28
|
-
::User.first ||
|
29
|
-
::User.create(name: 'joe', email: 'joe@example.com')
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def create_users(count: 5)
|
34
|
-
@users = [user] + FactoryGirl.create_list(:user, count)
|
35
|
-
end
|
36
|
-
|
37
|
-
def create_messageboard
|
38
|
-
@messageboard = FactoryGirl.create(
|
39
|
-
:messageboard,
|
40
|
-
name: 'Main Board',
|
41
|
-
slug: 'main-board',
|
42
|
-
description: 'A board is not a board without some posts'
|
43
|
-
)
|
44
|
-
end
|
45
|
-
|
46
|
-
def create_topics(count: 26)
|
47
|
-
@topics = FactoryGirl.create_list(
|
48
|
-
:topic, count,
|
49
|
-
messageboard: messageboard,
|
50
|
-
user: users.sample,
|
51
|
-
last_user: users.sample)
|
52
|
-
|
53
|
-
@private_topics = FactoryGirl.create_list(
|
54
|
-
:private_topic, count,
|
55
|
-
user: users.sample,
|
56
|
-
last_user: users.sample,
|
57
|
-
users: [user])
|
58
|
-
end
|
59
|
-
|
60
|
-
def create_posts(count: (0..30))
|
61
|
-
@posts = topics.flat_map do |topic|
|
62
|
-
(count.min + rand(count.max + 1)).times do
|
63
|
-
FactoryGirl.create(:post, postable: topic, messageboard: messageboard, user: users.sample)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def create_private_posts(count: (0..30))
|
69
|
-
@private_posts = private_topics.flat_map do |topic|
|
70
|
-
(count.min + rand(count.max + 1)).times do
|
71
|
-
FactoryGirl.create(:private_post, postable: topic, user: users.sample)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
require 'thredded/search_parser'
|
2
|
-
module Thredded
|
3
|
-
class TableSqlBuilder
|
4
|
-
def initialize(query, messageboard)
|
5
|
-
@terms = SearchParser.new(query).parse
|
6
|
-
@scope = Thredded::Topic.select(:id).where(messageboard_id: messageboard.id)
|
7
|
-
@search_categories = @search_users = @search_text = nil
|
8
|
-
end
|
9
|
-
|
10
|
-
def sql
|
11
|
-
apply_filters
|
12
|
-
@scope.to_sql
|
13
|
-
end
|
14
|
-
|
15
|
-
protected
|
16
|
-
|
17
|
-
def categories
|
18
|
-
@search_categories ||=
|
19
|
-
if @terms['in']
|
20
|
-
DbTextSearch::CaseInsensitiveEq.new(Category, :name)
|
21
|
-
.find(@terms['in']).pluck(:id)
|
22
|
-
else
|
23
|
-
[]
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def users
|
28
|
-
@search_users ||=
|
29
|
-
if @terms['by']
|
30
|
-
DbTextSearch::CaseInsensitiveEq.new(Thredded.user_class, Thredded.user_name_column)
|
31
|
-
.find(@terms['by']).pluck(:id)
|
32
|
-
else
|
33
|
-
[]
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def text
|
38
|
-
@terms['text']
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
require 'thredded/table_sql_builder'
|
2
|
-
|
3
|
-
module Thredded
|
4
|
-
class TopicSqlBuilder < TableSqlBuilder
|
5
|
-
def apply_filters
|
6
|
-
@scope = @scope.joins(:topic_categories).where(category_id: categories) if categories.present?
|
7
|
-
@scope = @scope.where(user_id: users) if users.present?
|
8
|
-
@scope = DbTextSearch::FullTextSearch.new(@scope, :title).find(text) if text.present?
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|