ack-mongoid-forums 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +35 -0
- data/app/assets/javascripts/mongoid_forums/admin/base.js +2 -0
- data/app/assets/javascripts/mongoid_forums/admin/categories.js +2 -0
- data/app/assets/javascripts/mongoid_forums/admin/forums.js +2 -0
- data/app/assets/javascripts/mongoid_forums/admin/groups.js +2 -0
- data/app/assets/javascripts/mongoid_forums/admin/users.js +2 -0
- data/app/assets/javascripts/mongoid_forums/application.js +15 -0
- data/app/assets/javascripts/mongoid_forums/forums.js +2 -0
- data/app/assets/javascripts/mongoid_forums/posts.js +2 -0
- data/app/assets/javascripts/mongoid_forums/topics.js +2 -0
- data/app/assets/stylesheets/mongoid_forums/admin/base.css +4 -0
- data/app/assets/stylesheets/mongoid_forums/admin/categories.css +4 -0
- data/app/assets/stylesheets/mongoid_forums/admin/forums.css +4 -0
- data/app/assets/stylesheets/mongoid_forums/admin/groups.css +4 -0
- data/app/assets/stylesheets/mongoid_forums/admin/users.css +4 -0
- data/app/assets/stylesheets/mongoid_forums/application.css +15 -0
- data/app/assets/stylesheets/mongoid_forums/forums.css +4 -0
- data/app/assets/stylesheets/mongoid_forums/posts.css +4 -0
- data/app/assets/stylesheets/mongoid_forums/topics.css +4 -0
- data/app/assets/stylesheets/scaffold.css +56 -0
- data/app/controllers/mongoid_forums/admin/base_controller.rb +18 -0
- data/app/controllers/mongoid_forums/admin/categories_controller.rb +83 -0
- data/app/controllers/mongoid_forums/admin/forums_controller.rb +83 -0
- data/app/controllers/mongoid_forums/admin/groups_controller.rb +83 -0
- data/app/controllers/mongoid_forums/admin/topics_controller.rb +48 -0
- data/app/controllers/mongoid_forums/admin/users_controller.rb +34 -0
- data/app/controllers/mongoid_forums/application_controller.rb +57 -0
- data/app/controllers/mongoid_forums/forums_controller.rb +66 -0
- data/app/controllers/mongoid_forums/posts_controller.rb +133 -0
- data/app/controllers/mongoid_forums/redirect_controller.rb +33 -0
- data/app/controllers/mongoid_forums/topics_controller.rb +83 -0
- data/app/decorators/lib/mongoid_forums/user_class_decorator.rb +1 -0
- data/app/helpers/mongoid_forums/admin/base_helper.rb +4 -0
- data/app/helpers/mongoid_forums/admin/categories_helper.rb +4 -0
- data/app/helpers/mongoid_forums/admin/forums_helper.rb +4 -0
- data/app/helpers/mongoid_forums/admin/groups_helper.rb +4 -0
- data/app/helpers/mongoid_forums/admin/users_helper.rb +4 -0
- data/app/helpers/mongoid_forums/application_helper.rb +20 -0
- data/app/helpers/mongoid_forums/formatting_helper.rb +28 -0
- data/app/helpers/mongoid_forums/forums_helper.rb +15 -0
- data/app/helpers/mongoid_forums/posts_helper.rb +4 -0
- data/app/helpers/mongoid_forums/topics_helper.rb +4 -0
- data/app/models/mongoid_forums/ability.rb +65 -0
- data/app/models/mongoid_forums/alert.rb +80 -0
- data/app/models/mongoid_forums/category.rb +31 -0
- data/app/models/mongoid_forums/concerns/subscribable.rb +76 -0
- data/app/models/mongoid_forums/concerns/viewable.rb +60 -0
- data/app/models/mongoid_forums/forum.rb +67 -0
- data/app/models/mongoid_forums/group.rb +15 -0
- data/app/models/mongoid_forums/post.rb +40 -0
- data/app/models/mongoid_forums/subscription.rb +65 -0
- data/app/models/mongoid_forums/topic.rb +55 -0
- data/app/models/mongoid_forums/view.rb +30 -0
- data/app/views/layouts/mongoid_forums/application.haml +21 -0
- data/app/views/mongoid_forums/admin/base/index.haml +6 -0
- data/app/views/mongoid_forums/admin/categories/edit.haml +4 -0
- data/app/views/mongoid_forums/admin/categories/index.haml +21 -0
- data/app/views/mongoid_forums/admin/categories/new.haml +4 -0
- data/app/views/mongoid_forums/admin/categories/show.haml +21 -0
- data/app/views/mongoid_forums/admin/forums/edit.haml +5 -0
- data/app/views/mongoid_forums/admin/forums/index.haml +25 -0
- data/app/views/mongoid_forums/admin/forums/new.haml +5 -0
- data/app/views/mongoid_forums/admin/forums/show.haml +21 -0
- data/app/views/mongoid_forums/admin/groups/edit.haml +4 -0
- data/app/views/mongoid_forums/admin/groups/index.haml +23 -0
- data/app/views/mongoid_forums/admin/groups/new.haml +5 -0
- data/app/views/mongoid_forums/admin/groups/show.haml +26 -0
- data/app/views/mongoid_forums/admin/users/index.haml +24 -0
- data/app/views/mongoid_forums/forums/index.haml +46 -0
- data/app/views/mongoid_forums/forums/new.haml +15 -0
- data/app/views/mongoid_forums/forums/show.haml +47 -0
- data/app/views/mongoid_forums/posts/_form.haml +4 -0
- data/app/views/mongoid_forums/posts/_post.haml +24 -0
- data/app/views/mongoid_forums/posts/_quoted.haml +9 -0
- data/app/views/mongoid_forums/posts/edit.haml +17 -0
- data/app/views/mongoid_forums/posts/new.haml +17 -0
- data/app/views/mongoid_forums/topics/_topic.haml +2 -0
- data/app/views/mongoid_forums/topics/my_posts.haml +6 -0
- data/app/views/mongoid_forums/topics/my_subscriptions.haml +5 -0
- data/app/views/mongoid_forums/topics/my_topics.haml +6 -0
- data/app/views/mongoid_forums/topics/show.haml +16 -0
- data/config/locales/en.yml +196 -0
- data/config/routes.rb +62 -0
- data/lib/ack_mongoid_forums.rb +1 -0
- data/lib/generators/mongoid_forums/install/templates/initializer.rb +5 -0
- data/lib/generators/mongoid_forums/install_generator.rb +90 -0
- data/lib/generators/mongoid_forums/views_generator.rb +27 -0
- data/lib/mongoid_forums.rb +53 -0
- data/lib/mongoid_forums/default_permissions.rb +63 -0
- data/lib/mongoid_forums/engine.rb +20 -0
- data/lib/mongoid_forums/sanitizer.rb +10 -0
- data/lib/mongoid_forums/version.rb +3 -0
- data/lib/tasks/mongoid_forums_tasks.rake +4 -0
- data/test/controllers/mongoid_forums/admin/base_controller_test.rb +11 -0
- data/test/controllers/mongoid_forums/admin/categories_controller_test.rb +31 -0
- data/test/controllers/mongoid_forums/admin/forums_controller_test.rb +31 -0
- data/test/controllers/mongoid_forums/admin/groups_controller_test.rb +41 -0
- data/test/controllers/mongoid_forums/admin/users_controller_test.rb +11 -0
- data/test/controllers/mongoid_forums/forums_controller_test.rb +16 -0
- data/test/controllers/mongoid_forums/posts_controller_test.rb +36 -0
- data/test/controllers/mongoid_forums/topics_controller_test.rb +36 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/javascripts/welcome.js +2 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/assets/stylesheets/scaffold.css +56 -0
- data/test/dummy/app/assets/stylesheets/welcome.css +4 -0
- data/test/dummy/app/controllers/application_controller.rb +11 -0
- data/test/dummy/app/controllers/welcome_controller.rb +4 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/helpers/welcome_helper.rb +2 -0
- data/test/dummy/app/models/concerns/zero_oid_fix.rb +10 -0
- data/test/dummy/app/models/user.rb +43 -0
- data/test/dummy/app/views/layouts/application.haml +13 -0
- data/test/dummy/app/views/partials/_nav.haml +6 -0
- data/test/dummy/app/views/welcome/index.html.erb +2 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +29 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +29 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +41 -0
- data/test/dummy/config/environments/production.rb +76 -0
- data/test/dummy/config/environments/test.rb +42 -0
- data/test/dummy/config/initializers/assets.rb +11 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/devise.rb +259 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/kaminari_config.rb +10 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/mongoid_forums.rb +5 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/simple_form.rb +166 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +9 -0
- data/test/dummy/config/locales/devise.en.yml +60 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/locales/simple_form.en.yml +31 -0
- data/test/dummy/config/mongoid.yml +69 -0
- data/test/dummy/config/routes.rb +7 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/lib/templates/erb/scaffold/_form.html.erb +13 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/test/controllers/welcome_controller_test.rb +9 -0
- data/test/dummy/test/fixtures/users.yml +11 -0
- data/test/dummy/test/models/user_test.rb +7 -0
- data/test/fixtures/mongoid_forums/categories.yml +11 -0
- data/test/fixtures/mongoid_forums/forums.yml +11 -0
- data/test/fixtures/mongoid_forums/posts.yml +11 -0
- data/test/fixtures/mongoid_forums/ranks.yml +11 -0
- data/test/fixtures/mongoid_forums/topics.yml +11 -0
- data/test/integration/navigation_test.rb +9 -0
- data/test/models/mongoid_forums/category_test.rb +9 -0
- data/test/models/mongoid_forums/forum_test.rb +9 -0
- data/test/models/mongoid_forums/post_test.rb +9 -0
- data/test/models/mongoid_forums/rank_test.rb +9 -0
- data/test/models/mongoid_forums/topic_test.rb +9 -0
- data/test/mongoid_forums_test.rb +7 -0
- data/test/test_helper.rb +17 -0
- metadata +442 -0
@@ -0,0 +1,48 @@
|
|
1
|
+
module MongoidForums
|
2
|
+
module Admin
|
3
|
+
class TopicsController < BaseController
|
4
|
+
before_filter :find_topic
|
5
|
+
|
6
|
+
def edit
|
7
|
+
end
|
8
|
+
|
9
|
+
def update
|
10
|
+
@topic.subject = params[:topic][:subject]
|
11
|
+
@topic.pinned = params[:topic][:pinned]
|
12
|
+
@topic.locked = params[:topic][:locked]
|
13
|
+
@topic.hidden = params[:topic][:hidden]
|
14
|
+
@topic.forum_id = params[:topic][:forum_id]
|
15
|
+
if @topic.save
|
16
|
+
flash[:notice] = t("mongoid_forums.topic.updated")
|
17
|
+
redirect_to topic_path(@topic)
|
18
|
+
else
|
19
|
+
flash.alert = t("mongoid_forums.topic.not_updated")
|
20
|
+
render :action => "edit"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def toggle_hide
|
25
|
+
@topic.toggle!(:hidden)
|
26
|
+
flash[:notice] = t("mongoid_forums.topic.hidden.#{@topic.hidden?}")
|
27
|
+
redirect_to topic_path(@topic)
|
28
|
+
end
|
29
|
+
|
30
|
+
def toggle_lock
|
31
|
+
@topic.toggle!(:locked)
|
32
|
+
flash[:notice] = t("mongoid_forums.topic.locked.#{@topic.locked?}")
|
33
|
+
redirect_to topic_path(@topic)
|
34
|
+
end
|
35
|
+
|
36
|
+
def toggle_pin
|
37
|
+
@topic.toggle!(:pinned)
|
38
|
+
flash[:notice] = t("mongoid_forums.topic.pinned.#{@topic.pinned?}")
|
39
|
+
redirect_to topic_path(@topic)
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
def find_topic
|
44
|
+
@topic = Topic.find(params[:format])
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require_dependency "mongoid_forums/application_controller"
|
2
|
+
|
3
|
+
module MongoidForums
|
4
|
+
module Admin
|
5
|
+
class UsersController < BaseController
|
6
|
+
|
7
|
+
before_action :set_user, only: [:add_admin, :remove_admin]
|
8
|
+
|
9
|
+
def index
|
10
|
+
@admins = User.where(mongoid_admin: true)
|
11
|
+
@non_admins = User.where(mongoid_admin: false)
|
12
|
+
end
|
13
|
+
|
14
|
+
def add_admin
|
15
|
+
@user.mongoid_admin = true
|
16
|
+
@user.save
|
17
|
+
redirect_to admin_users_path
|
18
|
+
end
|
19
|
+
|
20
|
+
def remove_admin
|
21
|
+
@user.mongoid_admin = false
|
22
|
+
@user.save
|
23
|
+
redirect_to admin_users_path
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def set_user
|
29
|
+
@user = User.find(params[:user][:id])
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'cancan'
|
2
|
+
|
3
|
+
class MongoidForums::ApplicationController < ApplicationController
|
4
|
+
helper MongoidForums::Engine.helpers
|
5
|
+
|
6
|
+
rescue_from CanCan::AccessDenied do
|
7
|
+
redirect_to root_path, :alert => t("mongoid.access_denied")
|
8
|
+
end
|
9
|
+
|
10
|
+
def current_ability
|
11
|
+
MongoidForums::Ability.new(mongoid_forums_user)
|
12
|
+
end
|
13
|
+
|
14
|
+
before_action :set_categories
|
15
|
+
before_action :set_alerts
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def set_alerts
|
20
|
+
if mongoid_forums_user.present?
|
21
|
+
@alerts = MongoidForums::Alert.where(:user_id => mongoid_forums_user.id, :read => false).desc(:updated_at).limit(25)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def set_categories
|
26
|
+
@categories = MongoidForums::Category.asc(:position)
|
27
|
+
end
|
28
|
+
|
29
|
+
def authenticate_mongoid_forums_user
|
30
|
+
if !mongoid_forums_user
|
31
|
+
session["user_return_to"] = request.fullpath
|
32
|
+
flash.alert = t("mongoid_forums.errors.not_signed_in")
|
33
|
+
devise_route = "new_#{MongoidForums.user_class.to_s.underscore}_session_path"
|
34
|
+
sign_in_path = MongoidForums.sign_in_path ||
|
35
|
+
(main_app.respond_to?(devise_route) && main_app.send(devise_route)) ||
|
36
|
+
(main_app.respond_to?(:sign_in_path) && main_app.send(:sign_in_path))
|
37
|
+
if sign_in_path
|
38
|
+
redirect_to sign_in_path
|
39
|
+
else
|
40
|
+
raise "MongoidForums could not determine the sign in path for your application. Please do one of these things:
|
41
|
+
1) Define sign_in_path in the config/routes.rb of your application like this:
|
42
|
+
or; 2) Set MongoidForums.sign_in_path to a String value that represents the location of your sign in form, such as '/users/sign_in'."
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def mongoid_forums_admin?
|
48
|
+
mongoid_forums_user && mongoid_forums_user.mongoid_forums_admin?
|
49
|
+
end
|
50
|
+
helper_method :mongoid_forums_admin?
|
51
|
+
|
52
|
+
def mongoid_forums_admin_or_moderator?(forum)
|
53
|
+
mongoid_forums_user && (mongoid_forums_user.mongoid_forums_admin? || forum.moderator?(mongoid_forums_user))
|
54
|
+
end
|
55
|
+
helper_method :mongoid_forums_admin_or_moderator?
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require_dependency "mongoid_forums/application_controller"
|
2
|
+
|
3
|
+
module MongoidForums
|
4
|
+
class ForumsController < ApplicationController
|
5
|
+
load_and_authorize_resource :class => 'MongoidForums::Forum', :only => :show
|
6
|
+
before_filter :authenticate_mongoid_forums_user, :only => [:create, :new]
|
7
|
+
|
8
|
+
def index
|
9
|
+
@categories = Category.asc(:position)
|
10
|
+
end
|
11
|
+
|
12
|
+
def show
|
13
|
+
@forum = Forum.find(params[:id])
|
14
|
+
register_view
|
15
|
+
|
16
|
+
@topics = @forum.topics
|
17
|
+
@topics = @topics.by_pinned_or_most_recent_post.page(params[:page]).per(MongoidForums.per_page)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Note: This is not an action to make a new Forum!
|
21
|
+
# it is to create a new TOPIC within a forum
|
22
|
+
def new
|
23
|
+
@forum = Forum.find(params[:forum_id])
|
24
|
+
authorize! :create_topic, @forum
|
25
|
+
|
26
|
+
@topic = Topic.new
|
27
|
+
@topic.forum = @forum.id
|
28
|
+
end
|
29
|
+
|
30
|
+
# Note: This is not an action to make a new Forum!
|
31
|
+
# it is to create a new TOPIC within a forum
|
32
|
+
def create
|
33
|
+
@forum = Forum.find(params[:forum_id])
|
34
|
+
authorize! :create_topic, @forum
|
35
|
+
|
36
|
+
@topic = Topic.new
|
37
|
+
@topic.name = topic_params[:name]
|
38
|
+
@topic.user = mongoid_forums_user.id
|
39
|
+
@topic.forum = @forum.id
|
40
|
+
@post = Post.new
|
41
|
+
@post.user = mongoid_forums_user.id
|
42
|
+
@post.text = topic_params[:posts][:text]
|
43
|
+
@topic.posts << @post
|
44
|
+
|
45
|
+
if @topic.save && @topic.posts.first.save
|
46
|
+
flash[:notice] = t("mongoid_forums.topic.created")
|
47
|
+
redirect_to @topic
|
48
|
+
else
|
49
|
+
flash.now.alert = t("mongoid_forums.topic.not_created")
|
50
|
+
render :action => "new"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def register_view
|
57
|
+
@forum.register_view_by(mongoid_forums_user)
|
58
|
+
end
|
59
|
+
|
60
|
+
def topic_params
|
61
|
+
params.require(:topic).permit(:name, :posts => [:text])
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
require_dependency "mongoid_forums/application_controller"
|
2
|
+
|
3
|
+
module MongoidForums
|
4
|
+
class PostsController < ApplicationController
|
5
|
+
before_filter :find_topic
|
6
|
+
before_filter :authenticate_mongoid_forums_user, except: :show
|
7
|
+
before_filter :reject_locked_topic!, only: [:new, :create]
|
8
|
+
|
9
|
+
def new
|
10
|
+
authorize! :reply, @topic
|
11
|
+
@post = @topic.posts.build
|
12
|
+
@post.topic = @topic.id
|
13
|
+
if params[:reply_to_id]
|
14
|
+
find_reply_to_post
|
15
|
+
|
16
|
+
if @reply_to.id && @reply_to.id == @topic.posts.first.id
|
17
|
+
flash[:alert] = t("mongoid_forums.post.not_created_quote_original_post")
|
18
|
+
redirect_to @topic
|
19
|
+
return
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
if @topic.locked
|
24
|
+
flash[:alert] = t("mongoid_forums.post.not_created_topic_locked")
|
25
|
+
redirect_to @topic
|
26
|
+
return
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
def create
|
32
|
+
authorize! :reply, @topic
|
33
|
+
@post = @topic.posts.build(post_params)
|
34
|
+
@post.user = mongoid_forums_user
|
35
|
+
|
36
|
+
if @post.save
|
37
|
+
@topic.alert_subscribers(mongoid_forums_user.id)
|
38
|
+
@topic.forum.increment_posts_count
|
39
|
+
flash[:notice] = t("mongoid_forums.post.created")
|
40
|
+
redirect_to @topic
|
41
|
+
else
|
42
|
+
flash.now.alert = t("mongoid_forums.post.not_created")
|
43
|
+
render :action => "new"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def show
|
48
|
+
end
|
49
|
+
|
50
|
+
def edit
|
51
|
+
find_post
|
52
|
+
authorize! :edit_post, @topic.forum
|
53
|
+
end
|
54
|
+
|
55
|
+
def update
|
56
|
+
authorize! :edit_post, @topic.forum
|
57
|
+
find_post
|
58
|
+
|
59
|
+
if @post.owner_or_admin?(mongoid_forums_user) && @post.update_attributes(post_params)
|
60
|
+
redirect_to @topic, :notice => t('edited', :scope => 'mongoid_forums.post')
|
61
|
+
else
|
62
|
+
flash.now.alert = t("mongoid_forums.post.not_edited")
|
63
|
+
render :action => "edit"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def destroy
|
68
|
+
find_post
|
69
|
+
if @topic.posts.first == @post
|
70
|
+
flash[:alert] = t("mongoid_forums.post.cannot_delete_first_post")
|
71
|
+
redirect_to @topic
|
72
|
+
return
|
73
|
+
end
|
74
|
+
|
75
|
+
authorize! :destroy_post, @topic.forum
|
76
|
+
|
77
|
+
unless @post.owner_or_admin? mongoid_forums_user
|
78
|
+
flash[:alert] = t("mongoid_forums.post.cannot_delete")
|
79
|
+
redirect_to @topic and return
|
80
|
+
end
|
81
|
+
|
82
|
+
if @post.destroy
|
83
|
+
flash[:notice] = t("mongoid_forums.post.deleted")
|
84
|
+
redirect_to @topic
|
85
|
+
else
|
86
|
+
flash[:notice] = t("mongoid_forums.post.cannot_delete")
|
87
|
+
redirect_to @topic
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
private
|
92
|
+
|
93
|
+
#TODO: Decide if this should be used
|
94
|
+
def destroy_successful
|
95
|
+
if @post.topic.posts.count == 0
|
96
|
+
@post.topic.destroy
|
97
|
+
flash[:notice] = "Post was deleted successfully along with it's topic."
|
98
|
+
redirect_to @topic.forum
|
99
|
+
else
|
100
|
+
flash[:notice] = "Post was deleted successfully"
|
101
|
+
redirect_to @topic
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def reject_locked_topic!
|
106
|
+
if @topic.locked?
|
107
|
+
flash.alert = t("mongoid_forums.post.not_created_topic_locked")
|
108
|
+
redirect_to @topic and return
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def find_post
|
113
|
+
@post = current_resource
|
114
|
+
end
|
115
|
+
|
116
|
+
def find_topic
|
117
|
+
@topic = Topic.find params[:topic_id]
|
118
|
+
end
|
119
|
+
|
120
|
+
def current_resource
|
121
|
+
@current_resource ||= Post.find(params[:id]) if params[:id]
|
122
|
+
end
|
123
|
+
|
124
|
+
def post_params
|
125
|
+
params.require(:post).permit(:text, :reply_to_id)
|
126
|
+
end
|
127
|
+
|
128
|
+
def find_reply_to_post
|
129
|
+
@reply_to = @topic.posts.find(params[:reply_to_id])
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require_dependency "mongoid_forums/application_controller"
|
2
|
+
|
3
|
+
module MongoidForums
|
4
|
+
class RedirectController < ApplicationController
|
5
|
+
|
6
|
+
def forum
|
7
|
+
return redirect_to forum_path(params[:forum_id])
|
8
|
+
end
|
9
|
+
|
10
|
+
def topic
|
11
|
+
return redirect_to topic_path(params[:topic_id])
|
12
|
+
end
|
13
|
+
|
14
|
+
def posts
|
15
|
+
post = Post.find(params[:post_id])
|
16
|
+
return redirect_to root_path, :notice => "Post does not exist" if post.topic == nil
|
17
|
+
x = 0
|
18
|
+
|
19
|
+
posts = post.topic.posts
|
20
|
+
|
21
|
+
posts.each_with_index do |p, i|
|
22
|
+
x = i
|
23
|
+
break if p.id == post.id
|
24
|
+
end
|
25
|
+
return redirect_to topic_url(post.topic, :page => (x / MongoidForums.per_page) + 1) + "#" + post.id.to_s
|
26
|
+
end
|
27
|
+
|
28
|
+
def subscriptions
|
29
|
+
return redirect_to my_subscriptions_path
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require_dependency "mongoid_forums/application_controller"
|
2
|
+
|
3
|
+
module MongoidForums
|
4
|
+
class TopicsController < ApplicationController
|
5
|
+
before_filter :find_forum, :except => [:my_subscriptions, :my_posts, :my_topics]
|
6
|
+
|
7
|
+
def show
|
8
|
+
if find_topic
|
9
|
+
register_view
|
10
|
+
|
11
|
+
@posts = @topic.posts.order_by([:created_at, :asc])
|
12
|
+
@posts = @posts.page(params[:page]).per(MongoidForums.per_page)
|
13
|
+
|
14
|
+
if mongoid_forums_user.present?
|
15
|
+
Alert.where(user_id: mongoid_forums_user.id, read: false, subscription_id: Subscription.where(subscribable_id: @topic.id, subscriber_id: mongoid_forums_user.id).first).update_all(:read => true, :ready_at => Time.now)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def destroy
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
def my_subscriptions
|
25
|
+
@subscriptions = Subscription.where(:subscriber_id => mongoid_forums_user.id, :subscribable_type => "MongoidForums::Topic", :unsubscribed => false).desc(:updated_at)
|
26
|
+
@topics = @subscriptions.page(params[:page]).per(MongoidForums.per_page)
|
27
|
+
return @topics.sort_by!{:updated_at}
|
28
|
+
end
|
29
|
+
|
30
|
+
def my_posts
|
31
|
+
@posts = Post.where(:user_id => mongoid_forums_user.id).by_updated_at.page(params[:page]).per(MongoidForums.per_page)
|
32
|
+
end
|
33
|
+
|
34
|
+
def my_topics
|
35
|
+
@topics = Topic.where(:user_id => mongoid_forums_user.id).by_most_recent_post.page(params[:page]).per(MongoidForums.per_page)
|
36
|
+
end
|
37
|
+
|
38
|
+
def subscribe
|
39
|
+
if find_topic
|
40
|
+
@topic.subscribe_user(mongoid_forums_user.id)
|
41
|
+
flash[:notice] = t("mongoid_forums.topic.subscribed")
|
42
|
+
redirect_to topic_url(@topic)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def unsubscribe
|
47
|
+
if find_topic
|
48
|
+
@topic.unsubscribe_user(mongoid_forums_user.id)
|
49
|
+
flash[:notice] = t("mongoid_forums.topic.unsubscribed")
|
50
|
+
redirect_to topic_url(@topic)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def find_forum
|
57
|
+
@forum = Topic.find(params[:id]).forum
|
58
|
+
end
|
59
|
+
|
60
|
+
def find_topic
|
61
|
+
begin
|
62
|
+
scope = @forum.topics # TODO: pending review stuff
|
63
|
+
@topic = scope.find(params[:id])
|
64
|
+
authorize! :read, @topic
|
65
|
+
rescue Mongoid::Errors::DocumentNotFound
|
66
|
+
flash.alert = t("mongoid_forums.topic.not_found")
|
67
|
+
redirect_to @forum and return
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def register_view
|
72
|
+
@topic.register_view_by(mongoid_forums_user)
|
73
|
+
end
|
74
|
+
|
75
|
+
def current_resource
|
76
|
+
@current_resource ||= Topic.find(params[:id]) if params[:id]
|
77
|
+
end
|
78
|
+
|
79
|
+
def topic_params
|
80
|
+
params.require(:topic).permit(:name, posts: [:text])
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|