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,27 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_dependency 'thredded/posts_page_view'
|
3
|
+
require_dependency 'thredded/topics_page_view'
|
1
4
|
module Thredded
|
2
5
|
class PrivateTopicsController < Thredded::ApplicationController
|
3
|
-
|
6
|
+
before_action :thredded_require_login!
|
4
7
|
|
5
8
|
def index
|
6
|
-
@
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
9
|
+
@private_topics = Thredded::TopicsPageView.new(
|
10
|
+
thredded_current_user,
|
11
|
+
PrivateTopic
|
12
|
+
.distinct
|
13
|
+
.for_user(thredded_current_user)
|
14
|
+
.order_recently_updated_first
|
15
|
+
.includes(:last_user, :user)
|
16
|
+
.page(params[:page]))
|
17
|
+
|
18
|
+
PrivateTopicForm.new(user: thredded_current_user).tap do |form|
|
19
|
+
@new_private_topic = form if policy(form.private_topic).create?
|
20
|
+
end
|
15
21
|
end
|
16
22
|
|
17
23
|
def show
|
18
|
-
|
19
|
-
UserReadsPrivateTopic.new(private_topic, thredded_current_user).run
|
24
|
+
authorize_reading private_topic
|
20
25
|
|
21
|
-
|
26
|
+
page_scope = private_topic
|
22
27
|
.posts
|
23
28
|
.includes(:user)
|
24
|
-
.
|
29
|
+
.order_oldest_first
|
30
|
+
.page(current_page)
|
31
|
+
@posts = Thredded::PostsPageView.new(thredded_current_user, private_topic, page_scope)
|
32
|
+
|
33
|
+
if signed_in?
|
34
|
+
UserPrivateTopicReadState.touch!(thredded_current_user.id, private_topic.id, page_scope.last, current_page)
|
35
|
+
end
|
25
36
|
|
26
37
|
@post = private_topic.posts.build
|
27
38
|
end
|
@@ -34,32 +45,56 @@ module Thredded
|
|
34
45
|
def create
|
35
46
|
@private_topic = PrivateTopicForm.new(new_private_topic_params)
|
36
47
|
if @private_topic.save
|
37
|
-
NotifyPrivateTopicUsersJob
|
38
|
-
.perform_later(@private_topic.private_topic.id)
|
39
|
-
|
40
|
-
UserResetsPrivateTopicToUnread
|
41
|
-
.new(@private_topic.private_topic, thredded_current_user)
|
42
|
-
.run
|
43
|
-
|
48
|
+
NotifyPrivateTopicUsersJob.perform_later(@private_topic.private_topic.id)
|
44
49
|
redirect_to @private_topic.private_topic
|
45
50
|
else
|
46
51
|
render :new
|
47
52
|
end
|
48
53
|
end
|
49
54
|
|
55
|
+
def edit
|
56
|
+
authorize private_topic, :update?
|
57
|
+
end
|
58
|
+
|
59
|
+
def update
|
60
|
+
authorize private_topic, :update?
|
61
|
+
if private_topic.update(private_topic_params)
|
62
|
+
redirect_to private_topic_url(private_topic),
|
63
|
+
notice: t('thredded.private_topics.updated_notice')
|
64
|
+
else
|
65
|
+
render :edit
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
50
69
|
private
|
51
70
|
|
71
|
+
def current_page
|
72
|
+
(params[:page] || 1).to_i
|
73
|
+
end
|
74
|
+
|
52
75
|
def private_topic
|
53
76
|
@private_topic ||= Thredded::PrivateTopic.find_by_slug(params[:id])
|
54
77
|
end
|
55
78
|
|
79
|
+
def private_topic_params
|
80
|
+
params
|
81
|
+
.require(:private_topic)
|
82
|
+
.permit(:title)
|
83
|
+
end
|
84
|
+
|
56
85
|
def new_private_topic_params
|
57
86
|
params
|
58
87
|
.require(:private_topic)
|
59
|
-
.permit(:title, :
|
88
|
+
.permit(:title, :content, :user_ids, user_ids: [])
|
60
89
|
.merge(
|
61
90
|
user: thredded_current_user,
|
62
|
-
ip:
|
91
|
+
ip: request.remote_ip
|
92
|
+
).tap { |p| adapt_user_ids! p }
|
93
|
+
end
|
94
|
+
|
95
|
+
# select2 returns a string of IDs joined with commas.
|
96
|
+
def adapt_user_ids!(p)
|
97
|
+
p[:user_ids] = p[:user_ids].split(',') if p[:user_ids].is_a?(String)
|
63
98
|
end
|
64
99
|
end
|
65
100
|
end
|
@@ -1,59 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Thredded
|
2
3
|
class ThemePreviewsController < Thredded::ApplicationController
|
3
|
-
before_filter :fail_on_empty_database, if: :no_messageboard?
|
4
|
-
|
5
4
|
def show
|
6
|
-
@messageboard =
|
7
|
-
|
8
|
-
@
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
@
|
15
|
-
@
|
16
|
-
|
17
|
-
@
|
18
|
-
@
|
19
|
-
@
|
20
|
-
@
|
21
|
-
|
22
|
-
@
|
23
|
-
|
24
|
-
@
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
@messageboard
|
29
|
-
end
|
30
|
-
|
31
|
-
def preference
|
32
|
-
@preference ||= NotificationPreference
|
33
|
-
.where(messageboard_id: messageboard.id, user_id: user.id)
|
34
|
-
.first_or_create!
|
35
|
-
end
|
36
|
-
|
37
|
-
def current_page
|
38
|
-
1
|
39
|
-
end
|
40
|
-
|
41
|
-
private
|
42
|
-
|
43
|
-
def fail_on_empty_database
|
44
|
-
fail Thredded::Errors::DatabaseEmpty
|
45
|
-
end
|
46
|
-
|
47
|
-
def no_messageboard?
|
48
|
-
!Thredded::Messageboard.any?
|
49
|
-
end
|
50
|
-
|
51
|
-
def user
|
52
|
-
@user ||= if thredded_current_user.thredded_anonymous?
|
53
|
-
Thredded.user_class.first_or_create!(slug: 'joe', name: 'joe', email: 'joe@example.com')
|
54
|
-
else
|
55
|
-
thredded_current_user
|
56
|
-
end
|
5
|
+
@messageboard = Messageboard.first
|
6
|
+
fail Thredded::Errors::DatabaseEmpty unless @messageboard
|
7
|
+
@user = if thredded_current_user.thredded_anonymous?
|
8
|
+
Thredded.user_class.new(id: 1334, name: 'joe', email: 'joe@example.com')
|
9
|
+
else
|
10
|
+
thredded_current_user
|
11
|
+
end
|
12
|
+
@messageboards = Messageboard.where(closed: false)
|
13
|
+
@topics = TopicsPageView.new(@user, @messageboard.topics.page(1).limit(3))
|
14
|
+
@private_topics = TopicsPageView.new(@user, @user.thredded_private_topics.page(1).limit(3))
|
15
|
+
topic = Topic.new(messageboard: @messageboard, title: 'Hello', slug: 'hello', user: @user)
|
16
|
+
@topic = TopicView.from_user(topic, @user)
|
17
|
+
@posts = PostsPageView.new(@user, topic, topic.posts.page(1).limit(3))
|
18
|
+
@post = topic.posts.build(id: 1337, postable: topic, content: 'Hello world', user: @user)
|
19
|
+
@new_post = @messageboard.posts.build(postable: topic)
|
20
|
+
@new_topic = TopicForm.new(user: @user, messageboard: @messageboard)
|
21
|
+
@new_private_topic = PrivateTopicForm.new(user: @user)
|
22
|
+
private_topic = PrivateTopic.new(id: 1337, title: 'Hello', user: @user, last_user: @user, users: [@user])
|
23
|
+
@private_topic = PrivateTopicView.from_user(private_topic, @user)
|
24
|
+
@private_posts = PostsPageView.new(@user, private_topic, private_topic.posts.page(1).limit(3))
|
25
|
+
@private_post = private_topic.posts.build(
|
26
|
+
id: 1337, postable: private_topic, content: 'A private hello world', user: @user)
|
27
|
+
@preferences = UserPreferencesForm.new(user: @user, messageboard: @messageboard)
|
57
28
|
end
|
58
29
|
end
|
59
30
|
end
|
@@ -1,40 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_dependency 'thredded/posts_page_view'
|
3
|
+
require_dependency 'thredded/topics_page_view'
|
1
4
|
module Thredded
|
2
5
|
class TopicsController < Thredded::ApplicationController
|
3
|
-
|
4
|
-
|
6
|
+
before_action :thredded_require_login!,
|
7
|
+
only: [:edit, :new, :update, :create, :destroy]
|
8
|
+
after_action :update_user_activity
|
5
9
|
|
6
10
|
def index
|
7
11
|
authorize_reading messageboard
|
8
12
|
|
9
|
-
@topics =
|
10
|
-
|
11
|
-
.
|
12
|
-
|
13
|
-
|
13
|
+
@topics = Thredded::TopicsPageView.new(
|
14
|
+
thredded_current_user,
|
15
|
+
messageboard.topics
|
16
|
+
.order_sticky_first.order_recently_updated_first
|
17
|
+
.includes(:categories, :last_user, :user)
|
18
|
+
.page(current_page))
|
19
|
+
TopicForm.new(messageboard: messageboard, user: thredded_current_user).tap do |form|
|
20
|
+
@new_topic = form if policy(form.topic).create?
|
14
21
|
end
|
15
22
|
end
|
16
23
|
|
17
24
|
def show
|
18
|
-
|
19
|
-
|
20
|
-
@posts = topic.posts
|
25
|
+
authorize_reading topic
|
26
|
+
page_scope = topic.posts
|
21
27
|
.includes(:user, :messageboard, :postable)
|
22
|
-
.
|
28
|
+
.order_oldest_first
|
23
29
|
.page(current_page)
|
30
|
+
@posts = Thredded::PostsPageView.new(thredded_current_user, topic, page_scope)
|
24
31
|
|
25
|
-
|
26
|
-
postable: topic,
|
27
|
-
filter: messageboard.filter
|
28
|
-
)
|
32
|
+
UserTopicReadState.touch!(thredded_current_user.id, topic.id, page_scope.last, current_page) if signed_in?
|
29
33
|
|
30
|
-
|
34
|
+
@new_post = messageboard.posts.build(postable: topic)
|
31
35
|
end
|
32
36
|
|
33
37
|
def search
|
34
|
-
@
|
35
|
-
@
|
36
|
-
|
37
|
-
|
38
|
+
@query = params[:q].to_s
|
39
|
+
@topics = Thredded::TopicsPageView.new(
|
40
|
+
thredded_current_user,
|
41
|
+
(messageboard_or_nil ? messageboard.topics : Topic)
|
42
|
+
.search_query(@query)
|
43
|
+
.order_recently_updated_first
|
44
|
+
.includes(:categories, :last_user, :user)
|
45
|
+
.page(current_page))
|
38
46
|
end
|
39
47
|
|
40
48
|
def new
|
@@ -43,16 +51,14 @@ module Thredded
|
|
43
51
|
end
|
44
52
|
|
45
53
|
def category
|
54
|
+
authorize_reading messageboard
|
46
55
|
@category = messageboard.categories.friendly.find(params[:category_id])
|
47
|
-
@topics =
|
48
|
-
|
49
|
-
.
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
@decorated_topics = Thredded::UserTopicDecorator
|
54
|
-
.decorate_all(thredded_current_user, @topics)
|
55
|
-
|
56
|
+
@topics = Thredded::TopicsPageView.new(
|
57
|
+
thredded_current_user,
|
58
|
+
@category.topics
|
59
|
+
.unstuck
|
60
|
+
.order_recently_updated_first
|
61
|
+
.page(current_page))
|
56
62
|
render :index
|
57
63
|
end
|
58
64
|
|
@@ -67,37 +73,30 @@ module Thredded
|
|
67
73
|
end
|
68
74
|
|
69
75
|
def edit
|
70
|
-
authorize
|
76
|
+
authorize topic, :update?
|
71
77
|
end
|
72
78
|
|
73
79
|
def update
|
74
|
-
topic
|
75
|
-
|
80
|
+
authorize topic, :update?
|
81
|
+
if topic.update(topic_params.merge(last_user_id: thredded_current_user.id))
|
82
|
+
redirect_to messageboard_topic_url(messageboard, topic),
|
83
|
+
notice: t('thredded.topics.updated_notice')
|
84
|
+
else
|
85
|
+
render :edit
|
86
|
+
end
|
76
87
|
end
|
77
88
|
|
78
89
|
def destroy
|
79
|
-
authorize
|
90
|
+
authorize topic, :destroy?
|
80
91
|
topic.destroy!
|
81
|
-
redirect_to messageboard_topics_path(messageboard),
|
92
|
+
redirect_to messageboard_topics_path(messageboard),
|
93
|
+
notice: t('thredded.topics.deleted_notice')
|
82
94
|
end
|
83
95
|
|
84
96
|
private
|
85
97
|
|
86
|
-
def initialize_new_topic
|
87
|
-
TopicForm.new(messageboard: messageboard, user: thredded_current_user)
|
88
|
-
end
|
89
|
-
|
90
98
|
def topic
|
91
|
-
@topic ||= messageboard.topics.
|
92
|
-
end
|
93
|
-
|
94
|
-
def topics
|
95
|
-
messageboard
|
96
|
-
.topics
|
97
|
-
.includes(:user_topic_reads, :categories, :last_user, :user)
|
98
|
-
.order_by_stuck_and_updated_time
|
99
|
-
.on_page(current_page)
|
100
|
-
.load
|
99
|
+
@topic ||= messageboard.topics.find_by_slug!(params[:id])
|
101
100
|
end
|
102
101
|
|
103
102
|
def topic_params
|
@@ -118,36 +117,8 @@ module Thredded
|
|
118
117
|
)
|
119
118
|
end
|
120
119
|
|
121
|
-
def topics_by_category(category_id)
|
122
|
-
messageboard.categories.friendly.find(category_id)
|
123
|
-
.topics
|
124
|
-
.unstuck
|
125
|
-
.order_by_updated
|
126
|
-
.on_page(current_page)
|
127
|
-
.load
|
128
|
-
end
|
129
|
-
|
130
120
|
def current_page
|
131
|
-
params[:page] || 1
|
132
|
-
end
|
133
|
-
|
134
|
-
def user_topic
|
135
|
-
@user_topic ||= UserTopicDecorator.new(thredded_current_user, topic)
|
136
|
-
end
|
137
|
-
|
138
|
-
def update_read_status
|
139
|
-
return if thredded_current_user.thredded_anonymous?
|
140
|
-
|
141
|
-
read_history = UserTopicRead.where(
|
142
|
-
user_id: thredded_current_user,
|
143
|
-
topic: topic,
|
144
|
-
).first_or_initialize
|
145
|
-
|
146
|
-
read_history.update_attributes(
|
147
|
-
farthest_post: @posts.last,
|
148
|
-
posts_count: topic.posts_count,
|
149
|
-
page: current_page,
|
150
|
-
)
|
121
|
+
(params[:page] || 1).to_i
|
151
122
|
end
|
152
123
|
end
|
153
124
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Thredded
|
2
3
|
class PrivateTopicForm
|
3
4
|
include ActiveModel::Model
|
@@ -30,14 +31,6 @@ module Thredded
|
|
30
31
|
Thredded::PrivateTopic.model_name
|
31
32
|
end
|
32
33
|
|
33
|
-
def users
|
34
|
-
@user.thredded_can_message_users
|
35
|
-
end
|
36
|
-
|
37
|
-
def users_for_select
|
38
|
-
(users - [@user]).map { |user| [user.to_s, user.id] }
|
39
|
-
end
|
40
|
-
|
41
34
|
def id
|
42
35
|
private_topic.id
|
43
36
|
end
|
@@ -66,19 +59,6 @@ module Thredded
|
|
66
59
|
user: non_null_user)
|
67
60
|
end
|
68
61
|
|
69
|
-
def users_selected_options
|
70
|
-
{ selected: private_user_ids }
|
71
|
-
end
|
72
|
-
|
73
|
-
def users_select_html_options
|
74
|
-
{
|
75
|
-
multiple: true,
|
76
|
-
required: true,
|
77
|
-
'data-placeholder' => 'select users to participate in this topic',
|
78
|
-
'data-thredded-users-select' => true
|
79
|
-
}
|
80
|
-
end
|
81
|
-
|
82
62
|
private
|
83
63
|
|
84
64
|
def topic_categories
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Thredded
|
2
3
|
class TopicForm
|
3
4
|
include ActiveModel::Model
|
@@ -26,11 +27,7 @@ module Thredded
|
|
26
27
|
end
|
27
28
|
|
28
29
|
def category_options
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
def filter
|
33
|
-
topic.messageboard.filter
|
30
|
+
categories.map { |cat| [cat.name, cat.id] }
|
34
31
|
end
|
35
32
|
|
36
33
|
def save
|
@@ -58,8 +55,7 @@ module Thredded
|
|
58
55
|
@post ||= topic.posts.build(
|
59
56
|
content: content,
|
60
57
|
user: non_null_user,
|
61
|
-
messageboard: messageboard
|
62
|
-
filter: messageboard.filter
|
58
|
+
messageboard: messageboard
|
63
59
|
)
|
64
60
|
end
|
65
61
|
|