mongoid-forums 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/assets/javascripts/mongoid_forums/admin/groups.js +2 -0
- data/app/assets/javascripts/mongoid_forums/application.js +2 -0
- data/app/assets/stylesheets/mongoid_forums/admin/groups.css +4 -0
- data/app/controllers/mongoid_forums/admin/base_controller.rb +8 -1
- data/app/controllers/mongoid_forums/admin/categories_controller.rb +52 -1
- data/app/controllers/mongoid_forums/admin/forums_controller.rb +54 -4
- data/app/controllers/mongoid_forums/admin/groups_controller.rb +87 -0
- data/app/controllers/mongoid_forums/application_controller.rb +32 -21
- data/app/controllers/mongoid_forums/forums_controller.rb +8 -1
- data/app/controllers/mongoid_forums/posts_controller.rb +13 -1
- data/app/controllers/mongoid_forums/topics_controller.rb +1 -2
- data/app/helpers/mongoid_forums/admin/groups_helper.rb +4 -0
- data/app/models/mongoid_forums/ability.rb +65 -0
- data/app/models/mongoid_forums/category.rb +18 -1
- data/app/models/mongoid_forums/forum.rb +23 -1
- data/app/models/mongoid_forums/group.rb +15 -0
- data/app/models/mongoid_forums/post.rb +3 -0
- data/app/models/mongoid_forums/subscription.rb +0 -1
- data/app/models/mongoid_forums/topic.rb +5 -1
- data/app/views/mongoid_forums/admin/base/index.haml +3 -2
- data/app/views/mongoid_forums/admin/categories/edit.haml +3 -0
- data/app/views/mongoid_forums/admin/categories/index.haml +21 -0
- data/app/views/mongoid_forums/admin/categories/show.haml +21 -0
- data/app/views/mongoid_forums/admin/forums/edit.haml +4 -0
- data/app/views/mongoid_forums/admin/forums/index.haml +25 -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 +19 -0
- data/app/views/mongoid_forums/forums/index.haml +2 -0
- data/app/views/mongoid_forums/forums/show.haml +27 -25
- data/app/views/mongoid_forums/posts/_post.haml +5 -4
- data/app/views/mongoid_forums/topics/show.haml +2 -3
- data/config/routes.rb +12 -3
- data/lib/mongoid_forums.rb +9 -1
- data/lib/mongoid_forums/default_permissions.rb +63 -0
- data/lib/mongoid_forums/version.rb +1 -1
- data/test/controllers/mongoid_forums/admin/groups_controller_test.rb +41 -0
- data/test/dummy/log/development.log +35218 -145038
- data/test/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/25a167c7563d6fe8ec6b13ec1ac09274 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/2dedb8177c20286c4259c1d58c5646cc +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/371bf96e99717688ed7313a0c53f4212 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/37b103f4623089af1456b90830fe941c +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/37f7e269b2ddbd05160232e59bf0288f +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/510da110ae528e2d22533be39ff696c5 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/6b12ee5284cadf70954a584a88b6c529 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/6fc757c2c8329244ca95d6909865bbc2 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/e2c4f946939f2d7d0b42d86383755cae +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- metadata +35 -10
- data/app/models/mongoid_forums/permission.rb +0 -96
- data/app/models/mongoid_forums/rank.rb +0 -9
- data/app/views/mongoid_forums/admin/categories/edit.html.erb +0 -2
- data/app/views/mongoid_forums/admin/forums/edit.html.erb +0 -2
- data/test/dummy/log/test.log +0 -51
- data/test/dummy/tmp/pids/server.pid +0 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9a4337469d2a29dedec4dbc0a39450cca125016e
|
|
4
|
+
data.tar.gz: c363a39163571c395122ce2cc9d58687907a182f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 53b729da9a4e57e9c5e7fd5ede064670055da5f661cdc60536edc1175642e1b9a15b8dcbae1a5a69367e7b94dcbc7f15220f4b5e4f1e8fd50ed4375e0604aa8d
|
|
7
|
+
data.tar.gz: 357b1cd80ee8136c9354f724a4c9c4b20f85a9881d0403f0ce1018612cbc605555307adf1e1d65e776daacefa0e6a647ac0fb9e40c889b2a9ded3a5f47ed97b0
|
|
@@ -2,10 +2,17 @@ require_dependency "mongoid_forums/application_controller"
|
|
|
2
2
|
|
|
3
3
|
module MongoidForums
|
|
4
4
|
class Admin::BaseController < ApplicationController
|
|
5
|
-
|
|
5
|
+
before_filter :authenticate_mongoid_forums_admin
|
|
6
6
|
|
|
7
7
|
def index
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
+
def authenticate_mongoid_forums_admin
|
|
11
|
+
if !mongoid_forums_user || !mongoid_forums_user.mongoid_forums_admin?
|
|
12
|
+
flash.alert = t("mongoid_forums.errors.access_denied")
|
|
13
|
+
redirect_to forums_path #TODO: Redirect to last URL
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
10
17
|
end
|
|
11
18
|
end
|
|
@@ -3,6 +3,18 @@ require_dependency "mongoid_forums/application_controller"
|
|
|
3
3
|
module MongoidForums
|
|
4
4
|
module Admin
|
|
5
5
|
class CategoriesController < BaseController
|
|
6
|
+
before_action :set_category, only: [:add_group, :remove_group]
|
|
7
|
+
|
|
8
|
+
def index
|
|
9
|
+
@forums = Forum.all
|
|
10
|
+
@categories = Category.all
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def show
|
|
14
|
+
@category = Category.find(params[:id])
|
|
15
|
+
@groups = Group.all.where(moderator: true).select{ |group| !@category.moderator_groups.include?(group) }
|
|
16
|
+
end
|
|
17
|
+
|
|
6
18
|
def new
|
|
7
19
|
@category = Category.new
|
|
8
20
|
end
|
|
@@ -10,7 +22,7 @@ module MongoidForums
|
|
|
10
22
|
def create
|
|
11
23
|
if @category = Category.create(name: params[:category][:name])
|
|
12
24
|
flash[:notice] = "Category created successfully"
|
|
13
|
-
redirect_to
|
|
25
|
+
redirect_to admin_categories_path
|
|
14
26
|
else
|
|
15
27
|
flash.now.alert = "Category could not be created"
|
|
16
28
|
render :action => "new"
|
|
@@ -18,19 +30,58 @@ module MongoidForums
|
|
|
18
30
|
end
|
|
19
31
|
|
|
20
32
|
def edit
|
|
33
|
+
@category = Category.find(params[:id])
|
|
21
34
|
end
|
|
22
35
|
|
|
23
36
|
def update
|
|
37
|
+
@category = Category.find(params[:id])
|
|
38
|
+
if @category.update(category_params)
|
|
39
|
+
flash[:notice] = "Category updated successfully"
|
|
40
|
+
redirect_to admin_categories_path
|
|
41
|
+
else
|
|
42
|
+
flash.now.alert = "Category could not be updated"
|
|
43
|
+
render :action => "edit"
|
|
44
|
+
end
|
|
24
45
|
end
|
|
25
46
|
|
|
26
47
|
def destroy
|
|
48
|
+
@category = Category.find(params[:id])
|
|
49
|
+
if @category.destroy
|
|
50
|
+
flash[:notice] = "Category destroyed successfully"
|
|
51
|
+
redirect_to admin_categories_path
|
|
52
|
+
else
|
|
53
|
+
flash.now.alert = "Category could not be destroyed"
|
|
54
|
+
render :action => "index"
|
|
55
|
+
end
|
|
27
56
|
end
|
|
28
57
|
|
|
58
|
+
### Temporary Methods - Try Not To Cringe Too Much <3 ###
|
|
59
|
+
def add_group
|
|
60
|
+
group = Group.find(params[:group][:id])
|
|
61
|
+
@category.moderator_groups << group
|
|
62
|
+
@category.save
|
|
63
|
+
|
|
64
|
+
redirect_to admin_category_path(@category)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def remove_group
|
|
68
|
+
group = Group.find(params[:group][:id])
|
|
69
|
+
@category.moderator_groups.delete(group)
|
|
70
|
+
@category.save
|
|
71
|
+
|
|
72
|
+
redirect_to admin_category_path(@category)
|
|
73
|
+
end
|
|
74
|
+
#########################################################
|
|
75
|
+
|
|
29
76
|
private
|
|
30
77
|
|
|
31
78
|
def category_params
|
|
32
79
|
params.require(:category).permit(:name)
|
|
33
80
|
end
|
|
81
|
+
|
|
82
|
+
def set_category
|
|
83
|
+
@category = Category.find(params[:category_id])
|
|
84
|
+
end
|
|
34
85
|
end
|
|
35
86
|
end
|
|
36
87
|
end
|
|
@@ -3,34 +3,84 @@ require_dependency "mongoid_forums/application_controller"
|
|
|
3
3
|
module MongoidForums
|
|
4
4
|
module Admin
|
|
5
5
|
class Admin::ForumsController < BaseController
|
|
6
|
+
before_action :set_forum, only: [:add_group, :remove_group]
|
|
7
|
+
|
|
8
|
+
def index
|
|
9
|
+
@forums = Forum.all
|
|
10
|
+
end
|
|
11
|
+
|
|
6
12
|
def new
|
|
7
13
|
@forum = Forum.new
|
|
8
14
|
end
|
|
9
15
|
|
|
10
16
|
def create
|
|
11
17
|
if @forum = Forum.create(name: params[:forum][:name], category: params[:forum][:category])
|
|
12
|
-
flash[:notice] = "
|
|
13
|
-
redirect_to @forum
|
|
18
|
+
flash[:notice] = "Forum created successfully"
|
|
19
|
+
redirect_to [:admin, @forum]
|
|
14
20
|
else
|
|
15
|
-
flash.now.alert = "
|
|
21
|
+
flash.now.alert = "Forum could not be created"
|
|
16
22
|
render :action => "new"
|
|
17
23
|
end
|
|
18
24
|
end
|
|
19
25
|
|
|
26
|
+
def show
|
|
27
|
+
@forum = Forum.find(params[:id])
|
|
28
|
+
@groups = Group.all.where(moderator: true).select{ |group| !@forum.moderator_groups.include?(group) }
|
|
29
|
+
end
|
|
30
|
+
|
|
20
31
|
def edit
|
|
32
|
+
@forum = Forum.find(params[:id])
|
|
21
33
|
end
|
|
22
34
|
|
|
23
35
|
def update
|
|
36
|
+
@forum = Forum.find(params[:id])
|
|
37
|
+
if @forum.update(forum_params)
|
|
38
|
+
flash[:notice] = "Forum updated successfully"
|
|
39
|
+
redirect_to @forum
|
|
40
|
+
else
|
|
41
|
+
flash.now.alert = "Forum could not be updated"
|
|
42
|
+
render :action => "edit"
|
|
43
|
+
end
|
|
24
44
|
end
|
|
25
45
|
|
|
26
46
|
def destroy
|
|
47
|
+
@forum = Forum.find(params[:id])
|
|
48
|
+
if @forum.destroy
|
|
49
|
+
flash[:notice] = "Forum destroyed successfully"
|
|
50
|
+
redirect_to admin_forums_path
|
|
51
|
+
else
|
|
52
|
+
flash.now.alert = "Forum could not be destroyed"
|
|
53
|
+
render :action => "index"
|
|
54
|
+
end
|
|
27
55
|
end
|
|
28
56
|
|
|
57
|
+
### Temporary Methods - Try Not To Cringe Too Much <3 ###
|
|
58
|
+
def add_group
|
|
59
|
+
group = Group.find(params[:group][:id])
|
|
60
|
+
@forum.moderator_groups << group
|
|
61
|
+
@forum.save
|
|
62
|
+
|
|
63
|
+
redirect_to admin_forum_path(@forum)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def remove_group
|
|
67
|
+
group = Group.find(params[:group][:id])
|
|
68
|
+
@forum.moderator_groups.delete(group)
|
|
69
|
+
@forum.save
|
|
70
|
+
|
|
71
|
+
redirect_to admin_forum_path(@forum)
|
|
72
|
+
end
|
|
73
|
+
#########################################################
|
|
74
|
+
|
|
29
75
|
private
|
|
30
76
|
|
|
31
|
-
def
|
|
77
|
+
def forum_params
|
|
32
78
|
params.require(:forum).permit(:name, :category)
|
|
33
79
|
end
|
|
80
|
+
|
|
81
|
+
def set_forum
|
|
82
|
+
@forum = Forum.find(params[:forum_id])
|
|
83
|
+
end
|
|
34
84
|
end
|
|
35
85
|
end
|
|
36
86
|
end
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
require_dependency "mongoid_forums/application_controller"
|
|
2
|
+
|
|
3
|
+
module MongoidForums
|
|
4
|
+
module Admin
|
|
5
|
+
class GroupsController < BaseController
|
|
6
|
+
|
|
7
|
+
def index
|
|
8
|
+
@groups = Group.all
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def new
|
|
12
|
+
@group = Group.new
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def create
|
|
16
|
+
if @group = Group.create(params.require(:group).permit(:name, :moderator, :members))
|
|
17
|
+
flash[:notice] = "Group created successfully"
|
|
18
|
+
redirect_to [:admin, @group]
|
|
19
|
+
else
|
|
20
|
+
flash.now.alert = "Group could not be created"
|
|
21
|
+
render :action => "new"
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def edit
|
|
26
|
+
@group = Group.find(params[:id])
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def update
|
|
30
|
+
@group = Group.find(params[:id])
|
|
31
|
+
if @group.update_attributes(params.require(:group).permit(:name, :members))
|
|
32
|
+
flash[:notice] = "Group updated successfully"
|
|
33
|
+
redirect_to [:admin, @group]
|
|
34
|
+
else
|
|
35
|
+
flash[:notice] = "Group could not be updated"
|
|
36
|
+
render :action => "edit"
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def show
|
|
41
|
+
@group = Group.find(params[:id])
|
|
42
|
+
@group_members = @group.members.map {|member_id| User.find(member_id) }
|
|
43
|
+
@users = User.all
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def destroy
|
|
47
|
+
@group = Group.find(params[:id])
|
|
48
|
+
|
|
49
|
+
if @group.destroy
|
|
50
|
+
flash[:notice] = "Group destroyed successfully"
|
|
51
|
+
redirect_to admin_groups_path
|
|
52
|
+
else
|
|
53
|
+
flash.now.alert = "Group could not be destroyed"
|
|
54
|
+
redirect_to admin_groups_path
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
### Temporary Methods - Try Not To Cringe Too Much <3 ###
|
|
59
|
+
def add_member
|
|
60
|
+
group = Group.find(params.require(:group_id))
|
|
61
|
+
user = User.find(params[:user][:id])
|
|
62
|
+
|
|
63
|
+
group.members << user.id unless group.members.include?(user.id)
|
|
64
|
+
group.save
|
|
65
|
+
|
|
66
|
+
redirect_to admin_group_path(group)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def remove_member
|
|
70
|
+
group = Group.find(params.require(:group_id))
|
|
71
|
+
user = User.find(params[:user][:id])
|
|
72
|
+
|
|
73
|
+
group.members.delete(user.id)
|
|
74
|
+
group.save
|
|
75
|
+
|
|
76
|
+
redirect_to admin_group_path(group)
|
|
77
|
+
end
|
|
78
|
+
#########################################################
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
private
|
|
82
|
+
|
|
83
|
+
def group_params
|
|
84
|
+
params.require(:group).permit(:name, :members)
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
+
require 'cancan'
|
|
2
|
+
|
|
1
3
|
class MongoidForums::ApplicationController < ApplicationController
|
|
2
4
|
helper MongoidForums::Engine.helpers
|
|
3
5
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
before_filter :authorize
|
|
6
|
+
rescue_from CanCan::AccessDenied do
|
|
7
|
+
redirect_to root_path, :alert => t("mongoid.access_denied")
|
|
8
|
+
end
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
def current_ability
|
|
11
|
+
MongoidForums::Ability.new(mongoid_forums_user)
|
|
12
|
+
end
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
before_action :set_categories
|
|
15
|
+
before_action :set_alerts
|
|
14
16
|
|
|
15
17
|
private
|
|
16
18
|
|
|
@@ -24,23 +26,32 @@ class MongoidForums::ApplicationController < ApplicationController
|
|
|
24
26
|
@categories = MongoidForums::Category.all
|
|
25
27
|
end
|
|
26
28
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
def authenticate_mongoid_forums_user
|
|
30
|
+
if !mongoid_forums_user
|
|
31
|
+
session["user_return_to"] = request.fullpath
|
|
32
|
+
flash.alert = "You must be 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
|
|
30
45
|
end
|
|
31
46
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
nil
|
|
47
|
+
def mongoid_forums_admin?
|
|
48
|
+
mongoid_forums_user && mongoid_forums_user.mongoid_forums_admin?
|
|
35
49
|
end
|
|
50
|
+
helper_method :mongoid_forums_admin?
|
|
36
51
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if current_permission.allow? params[:controller], params[:action], current_resource
|
|
40
|
-
#current_permission.permit_params! params
|
|
41
|
-
else
|
|
42
|
-
redirect_to root_path, alert: "Not authorized"
|
|
43
|
-
end
|
|
52
|
+
def mongoid_forums_admin_or_moderator?(forum)
|
|
53
|
+
mongoid_forums_user && (mongoid_forums_user.mongoid_forums_admin? || forum.moderator?(mongoid_forums_user))
|
|
44
54
|
end
|
|
55
|
+
helper_method :mongoid_forums_admin_or_moderator?
|
|
45
56
|
|
|
46
57
|
end
|
|
@@ -2,6 +2,9 @@ require_dependency "mongoid_forums/application_controller"
|
|
|
2
2
|
|
|
3
3
|
module MongoidForums
|
|
4
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
|
+
|
|
5
8
|
def index
|
|
6
9
|
@categories = Category.all.order_by([:order, :asc])
|
|
7
10
|
end
|
|
@@ -18,14 +21,18 @@ module MongoidForums
|
|
|
18
21
|
# it is to create a new TOPIC within a forum
|
|
19
22
|
def new
|
|
20
23
|
@forum = Forum.find(params[:forum_id])
|
|
24
|
+
authorize! :create_topic, @forum
|
|
25
|
+
|
|
21
26
|
@topic = Topic.new
|
|
22
27
|
@topic.forum = @forum.id
|
|
23
28
|
end
|
|
24
|
-
|
|
29
|
+
|
|
25
30
|
# Note: This is not an action to make a new Forum!
|
|
26
31
|
# it is to create a new TOPIC within a forum
|
|
27
32
|
def create
|
|
28
33
|
@forum = Forum.find(params[:forum_id])
|
|
34
|
+
authorize! :create_topic, @forum
|
|
35
|
+
|
|
29
36
|
@topic = Topic.new
|
|
30
37
|
@topic.name = topic_params[:name]
|
|
31
38
|
@topic.user = mongoid_forums_user.id
|
|
@@ -3,8 +3,10 @@ require_dependency "mongoid_forums/application_controller"
|
|
|
3
3
|
module MongoidForums
|
|
4
4
|
class PostsController < ApplicationController
|
|
5
5
|
before_filter :find_topic
|
|
6
|
+
before_filter :authenticate_mongoid_forums_user, except: :show
|
|
6
7
|
|
|
7
8
|
def new
|
|
9
|
+
authorize! :reply, @topic
|
|
8
10
|
@post = @topic.posts.build
|
|
9
11
|
@post.topic = @topic.id
|
|
10
12
|
if params[:reply_to_id]
|
|
@@ -13,6 +15,7 @@ module MongoidForums
|
|
|
13
15
|
end
|
|
14
16
|
|
|
15
17
|
def create
|
|
18
|
+
authorize! :reply, @topic
|
|
16
19
|
@post = @topic.posts.build(post_params)
|
|
17
20
|
@post.user = mongoid_forums_user
|
|
18
21
|
|
|
@@ -44,6 +47,7 @@ module MongoidForums
|
|
|
44
47
|
|
|
45
48
|
def edit
|
|
46
49
|
find_post
|
|
50
|
+
authorize! :edit_post, @topic.forum
|
|
47
51
|
end
|
|
48
52
|
|
|
49
53
|
def update
|
|
@@ -52,9 +56,10 @@ module MongoidForums
|
|
|
52
56
|
redirect_to [@topic] and return
|
|
53
57
|
end
|
|
54
58
|
|
|
59
|
+
authorize! :edit_post, @topic.forum
|
|
55
60
|
find_post
|
|
56
61
|
|
|
57
|
-
if @post.update_attributes(post_params)
|
|
62
|
+
if @post.owner_or_admin?(mongoid_forums_user) && @post.update_attributes(post_params)
|
|
58
63
|
flash[:notice] = "Reply updated successfully"
|
|
59
64
|
redirect_to @topic
|
|
60
65
|
else
|
|
@@ -71,6 +76,13 @@ module MongoidForums
|
|
|
71
76
|
return
|
|
72
77
|
end
|
|
73
78
|
|
|
79
|
+
authorize! :destroy_post, @topic.forum
|
|
80
|
+
|
|
81
|
+
unless @post.owner_or_admin? mongoid_forums_user
|
|
82
|
+
flash[:alert] = t("mongoid_forums.post.cannot_delete")
|
|
83
|
+
redirect_to @topic and return
|
|
84
|
+
end
|
|
85
|
+
|
|
74
86
|
if @post.destroy
|
|
75
87
|
flash[:notice] = "Post deleted successfully"
|
|
76
88
|
redirect_to @topic
|