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
|
@@ -18,6 +18,7 @@ module MongoidForums
|
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
def destroy
|
|
21
|
+
|
|
21
22
|
end
|
|
22
23
|
|
|
23
24
|
def my_subscriptions
|
|
@@ -54,14 +55,12 @@ module MongoidForums
|
|
|
54
55
|
|
|
55
56
|
def find_forum
|
|
56
57
|
@forum = Topic.find(params[:id]).forum
|
|
57
|
-
allow? "mongoid_forums/forums", :show, @forum
|
|
58
58
|
end
|
|
59
59
|
|
|
60
60
|
def find_topic
|
|
61
61
|
begin
|
|
62
62
|
scope = @forum.topics # TODO: pending review stuff
|
|
63
63
|
@topic = scope.find(params[:id])
|
|
64
|
-
allow? "mongoid_forums/topics", :show, @topic
|
|
65
64
|
rescue Mongoid::Errors::DocumentNotFound
|
|
66
65
|
flash.alert = t("forem.topic.not_found")
|
|
67
66
|
redirect_to @forum and return
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
module MongoidForums
|
|
2
|
+
class Ability
|
|
3
|
+
include CanCan::Ability
|
|
4
|
+
class_attribute :abilities
|
|
5
|
+
self.abilities = Set.new
|
|
6
|
+
|
|
7
|
+
# Allows us to go beyond the standard cancan initialize method which makes it difficult for engines to
|
|
8
|
+
# modify the default +Ability+ of an application. The +ability+ argument must be a class that includes
|
|
9
|
+
# the +CanCan::Ability+ module. The registered ability should behave properly as a stand-alone class
|
|
10
|
+
# and therefore should be easy to test in isolation.
|
|
11
|
+
def self.register_ability(ability)
|
|
12
|
+
self.abilities.add(ability)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.remove_ability(ability)
|
|
16
|
+
self.abilities.delete(ability)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def initialize(user)
|
|
20
|
+
user ||= MongoidForums.user_class.new
|
|
21
|
+
|
|
22
|
+
can :read, MongoidForums::Category do |category|
|
|
23
|
+
user.can_read_mongoid_forums_category?(category)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
can :read, MongoidForums::Topic do |topic|
|
|
27
|
+
user.can_read_mongoid_forums_forum?(topic.forum) && user.can_read_mongoid_forums_topic?(topic)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
if user.can_read_mongoid_forums_forums?
|
|
31
|
+
can :read, MongoidForums::Forum do |forum|
|
|
32
|
+
user.can_read_mongoid_forums_category?(forum.category) && user.can_read_mongoid_forums_forum?(forum)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
can :create_topic, MongoidForums::Forum do |forum|
|
|
37
|
+
can?(:read, forum) && user.can_create_mongoid_forums_topics?(forum)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
can :reply, MongoidForums::Topic do |topic|
|
|
41
|
+
can?(:read, topic.forum) && user.can_reply_to_mongoid_forums_topic?(topic)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
can :edit_post, MongoidForums::Forum do |forum|
|
|
45
|
+
user.can_edit_mongoid_forums_posts?(forum)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
can :destroy_post, MongoidForums::Forum do |forum|
|
|
49
|
+
user.can_destroy_mongoid_forums_posts?(forum)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
can :moderate, MongoidForums::Forum do |forum|
|
|
53
|
+
user.can_moderate_mongoid_forums_forum?(forum) || user.mongoid_forums_admin?
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
#include any abilities registered by extensions, etc.
|
|
57
|
+
Ability.abilities.each do |clazz|
|
|
58
|
+
ability = clazz.send(:new, user)
|
|
59
|
+
@rules = rules + ability.send(:rules)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
end
|
|
65
|
+
end
|
|
@@ -2,12 +2,29 @@ module MongoidForums
|
|
|
2
2
|
class Category
|
|
3
3
|
include Mongoid::Document
|
|
4
4
|
|
|
5
|
-
has_many :forums, :class_name => "MongoidForums::Forum"
|
|
5
|
+
has_many :forums, :class_name => "MongoidForums::Forum", dependent: :destroy
|
|
6
|
+
has_and_belongs_to_many :moderator_groups, :class_name => "MongoidForums::Group", inverse_of: nil
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
field :name
|
|
9
10
|
validates :name, :presence => true
|
|
10
11
|
|
|
11
12
|
field :order, :type => Integer, :default => 0
|
|
13
|
+
|
|
14
|
+
def moderator?(user)
|
|
15
|
+
return false unless user
|
|
16
|
+
moderator_groups.each do |group|
|
|
17
|
+
return true if group.moderator && group.members.include?(user.id)
|
|
18
|
+
end
|
|
19
|
+
false
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def moderators
|
|
23
|
+
array = Array.new
|
|
24
|
+
self.moderator_groups.each do |g|
|
|
25
|
+
array << g.group.members
|
|
26
|
+
end
|
|
27
|
+
return array
|
|
28
|
+
end
|
|
12
29
|
end
|
|
13
30
|
end
|
|
@@ -4,7 +4,7 @@ module MongoidForums
|
|
|
4
4
|
include MongoidForums::Concerns::Viewable
|
|
5
5
|
|
|
6
6
|
belongs_to :category, :class_name => "MongoidForums::Category"
|
|
7
|
-
has_many :topics, :class_name => "MongoidForums::Topic"
|
|
7
|
+
has_many :topics, :class_name => "MongoidForums::Topic", dependent: :destroy
|
|
8
8
|
|
|
9
9
|
# Caching
|
|
10
10
|
field :posts_count, :type => Integer
|
|
@@ -12,6 +12,8 @@ module MongoidForums
|
|
|
12
12
|
field :name
|
|
13
13
|
validates :name, :presence => true
|
|
14
14
|
|
|
15
|
+
has_and_belongs_to_many :moderator_groups, :class_name => "MongoidForums::Group", inverse_of: nil
|
|
16
|
+
|
|
15
17
|
field :order, :type => Integer, :default => 0
|
|
16
18
|
|
|
17
19
|
def unread_topic_count(user)
|
|
@@ -38,5 +40,25 @@ module MongoidForums
|
|
|
38
40
|
end
|
|
39
41
|
self.save
|
|
40
42
|
end
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def moderator?(user)
|
|
46
|
+
return false unless user
|
|
47
|
+
return true if category.moderator?(user)
|
|
48
|
+
moderator_groups.each do |group|
|
|
49
|
+
return true if group.moderator && group.members.include?(user.id)
|
|
50
|
+
end
|
|
51
|
+
false
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def moderators
|
|
55
|
+
array = Array.new
|
|
56
|
+
self.moderator_groups.each do |g|
|
|
57
|
+
array << g.group.members
|
|
58
|
+
end
|
|
59
|
+
return array
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
|
|
41
63
|
end
|
|
42
64
|
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module MongoidForums
|
|
2
|
+
class Group
|
|
3
|
+
include Mongoid::Document
|
|
4
|
+
|
|
5
|
+
validates :name, :presence => true
|
|
6
|
+
|
|
7
|
+
field :name, type: String
|
|
8
|
+
field :moderator, type: Boolean
|
|
9
|
+
field :members, type: Array, default: []
|
|
10
|
+
|
|
11
|
+
def to_s
|
|
12
|
+
name
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -8,7 +8,7 @@ module MongoidForums
|
|
|
8
8
|
after_create :subscribe_creator
|
|
9
9
|
|
|
10
10
|
belongs_to :forum, :class_name => "MongoidForums::Forum"
|
|
11
|
-
has_many :posts, :class_name => "MongoidForums::Post"
|
|
11
|
+
has_many :posts, :class_name => "MongoidForums::Post", dependent: :destroy
|
|
12
12
|
|
|
13
13
|
belongs_to :user, :class_name => MongoidForums.user_class.to_s
|
|
14
14
|
|
|
@@ -20,6 +20,10 @@ module MongoidForums
|
|
|
20
20
|
field :hidden, type: Boolean, default: false
|
|
21
21
|
|
|
22
22
|
|
|
23
|
+
def can_be_replied_to?
|
|
24
|
+
!locked?
|
|
25
|
+
end
|
|
26
|
+
|
|
23
27
|
def unread_post_count(user)
|
|
24
28
|
view = View.where(:viewable_id => id, :user_id => user.id).first
|
|
25
29
|
return posts.count unless view.present?
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
%h1 Manage categories
|
|
2
|
+
|
|
3
|
+
%h2 Create a new category
|
|
4
|
+
= link_to "New category", new_admin_category_path
|
|
5
|
+
|
|
6
|
+
%h2 Listing all categories
|
|
7
|
+
%table{:border => "1"}
|
|
8
|
+
%tr
|
|
9
|
+
%th
|
|
10
|
+
Name
|
|
11
|
+
|
|
12
|
+
- @categories.each do |category|
|
|
13
|
+
%tr
|
|
14
|
+
%td
|
|
15
|
+
= link_to category.name, [:admin, category]
|
|
16
|
+
%td
|
|
17
|
+
= link_to "Show", admin_category_path(category)
|
|
18
|
+
%td
|
|
19
|
+
= link_to "Edit", edit_admin_category_path(category)
|
|
20
|
+
%td
|
|
21
|
+
= button_to "Destroy", admin_category_path(category), method: :delete, data: { confirm: 'Are you certain you want to delete this?' }
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
%h2 Listing all moderator groups for: #{@category.name}
|
|
2
|
+
%table{:border => "1"}
|
|
3
|
+
%tr
|
|
4
|
+
%th
|
|
5
|
+
Name
|
|
6
|
+
|
|
7
|
+
- @category.moderator_groups.each do |group|
|
|
8
|
+
%tr
|
|
9
|
+
%td
|
|
10
|
+
= link_to group.name, [:admin, group]
|
|
11
|
+
%td
|
|
12
|
+
= link_to "Show", admin_group_path(group)
|
|
13
|
+
%td
|
|
14
|
+
= link_to "Edit", edit_admin_group_path(group)
|
|
15
|
+
%td
|
|
16
|
+
= button_to "Remove", admin_category_rem_group_path(category_id: params[:id], group: {id: group.id}), method: :post, data: { confirm: 'Are you certain you want to delete this?' }
|
|
17
|
+
|
|
18
|
+
= form_tag admin_category_add_group_path(@category), :method => :post do
|
|
19
|
+
= collection_select(:group, :id, @groups, :id, :name, {:prompt => true})
|
|
20
|
+
%button
|
|
21
|
+
Add
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
%h1 Manage forums
|
|
2
|
+
|
|
3
|
+
%h2 Create a new forum
|
|
4
|
+
= link_to "New forum", new_admin_forum_path
|
|
5
|
+
|
|
6
|
+
%h2 Listing all forums
|
|
7
|
+
%table{:border => "1"}
|
|
8
|
+
%tr
|
|
9
|
+
%th
|
|
10
|
+
Name
|
|
11
|
+
%th
|
|
12
|
+
Category
|
|
13
|
+
|
|
14
|
+
- @forums.each do |forum|
|
|
15
|
+
%tr
|
|
16
|
+
%td
|
|
17
|
+
= link_to forum.name, [:admin, forum]
|
|
18
|
+
%td
|
|
19
|
+
= link_to forum.category.name, [:admin, forum.category]
|
|
20
|
+
%td
|
|
21
|
+
= link_to "Show", admin_forum_path(forum)
|
|
22
|
+
%td
|
|
23
|
+
= link_to "Edit", edit_admin_forum_path(forum)
|
|
24
|
+
%td
|
|
25
|
+
= button_to "Destroy", admin_forum_path(forum), method: :delete, data: { confirm: 'Are you certain you want to delete this?' }
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
%h2 Listing all moderator groups for: #{@forum.name}
|
|
2
|
+
%table{:border => "1"}
|
|
3
|
+
%tr
|
|
4
|
+
%th
|
|
5
|
+
Name
|
|
6
|
+
|
|
7
|
+
- @forum.moderator_groups.each do |group|
|
|
8
|
+
%tr
|
|
9
|
+
%td
|
|
10
|
+
= link_to group.name, [:admin, group]
|
|
11
|
+
%td
|
|
12
|
+
= link_to "Show", admin_group_path(group)
|
|
13
|
+
%td
|
|
14
|
+
= link_to "Edit", edit_admin_group_path(group)
|
|
15
|
+
%td
|
|
16
|
+
= button_to "Remove", admin_forum_rem_group_path(forum_id: params[:id], group: {id: group.id}), method: :post, data: { confirm: 'Are you certain you want to delete this?' }
|
|
17
|
+
|
|
18
|
+
= form_tag admin_forum_add_group_path(@forum), :method => :post do
|
|
19
|
+
= collection_select(:group, :id, @groups, :id, :name, {:prompt => true})
|
|
20
|
+
%button
|
|
21
|
+
Add
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
%h1 Manage groups
|
|
2
|
+
|
|
3
|
+
%h2 Create a new group
|
|
4
|
+
= link_to "New group", new_admin_group_path
|
|
5
|
+
|
|
6
|
+
%h2 Listing all groups
|
|
7
|
+
%table{:border => "1"}
|
|
8
|
+
%tr
|
|
9
|
+
%th
|
|
10
|
+
Name
|
|
11
|
+
%th
|
|
12
|
+
Moderator
|
|
13
|
+
|
|
14
|
+
- @groups.each_with_index do |group, i|
|
|
15
|
+
%tr
|
|
16
|
+
%td
|
|
17
|
+
= link_to group.name, [:admin, group]
|
|
18
|
+
%td
|
|
19
|
+
= group.moderator
|
|
20
|
+
%td
|
|
21
|
+
= link_to "Edit", edit_admin_group_path(group)
|
|
22
|
+
%td
|
|
23
|
+
= button_to "Destroy", admin_group_path(group), method: :delete, data: { confirm: 'Are you certain you want to delete this?' }
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
%h2
|
|
2
|
+
= @group.name
|
|
3
|
+
%h3 Listing all members
|
|
4
|
+
%table{:border => "1"}
|
|
5
|
+
%tr
|
|
6
|
+
%th
|
|
7
|
+
Name
|
|
8
|
+
|
|
9
|
+
- @group.members.each do |member|
|
|
10
|
+
%tr
|
|
11
|
+
%td
|
|
12
|
+
= MongoidForums.user_class.find(member).forum_display_name
|
|
13
|
+
%td
|
|
14
|
+
= button_to "Remove", admin_group_rem_user_path(group_id: @group.id, user: {id: member}), method: :post, data: { confirm: 'Are you certain you want to delete this?' }
|
|
15
|
+
|
|
16
|
+
= form_tag admin_group_add_user_path(@group), :method => :post do
|
|
17
|
+
= collection_select(:user, :id, @users, :id, :email, {:prompt => true})
|
|
18
|
+
%button
|
|
19
|
+
Add
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
%h1 Viewing Forum "#{@forum.name}"
|
|
2
|
-
|
|
2
|
+
- if @forum.moderator?(mongoid_forums_user)
|
|
3
|
+
%b You are a moderator on this forum.
|
|
4
|
+
%br
|
|
3
5
|
%br
|
|
6
|
+
= link_to "Add a topic", forum_path(@forum) + '/new'
|
|
4
7
|
%br
|
|
5
8
|
%h2 Topics:
|
|
6
9
|
%table{:border => "1"}
|
|
@@ -19,27 +22,26 @@
|
|
|
19
22
|
Views
|
|
20
23
|
|
|
21
24
|
- @topics.each do |topic|
|
|
22
|
-
|
|
23
|
-
%
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
= topic.views_count ? topic.views_count : "None"
|
|
25
|
+
%tr
|
|
26
|
+
%td
|
|
27
|
+
- if topic.locked
|
|
28
|
+
🔒
|
|
29
|
+
- if topic.hidden
|
|
30
|
+
⚠
|
|
31
|
+
- if topic.pinned
|
|
32
|
+
*
|
|
33
|
+
= link_to topic.name, topic
|
|
34
|
+
%td
|
|
35
|
+
= topic.user.forum_display_name
|
|
36
|
+
= time_ago_in_words( topic.created_at )
|
|
37
|
+
ago
|
|
38
|
+
%td
|
|
39
|
+
= topic.posts.last.user.forum_display_name
|
|
40
|
+
= time_ago_in_words( topic.posts.last.created_at )
|
|
41
|
+
ago
|
|
42
|
+
%td
|
|
43
|
+
= mongoid_forums_user ? topic.unread_post_count(mongoid_forums_user) : ""
|
|
44
|
+
%td
|
|
45
|
+
= topic.posts.count
|
|
46
|
+
%td
|
|
47
|
+
= topic.views_count ? topic.views_count : "None"
|