ack-mongoid-forums 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +120 -0
- data/app/assets/javascripts/mongoid_forums.coffee +1 -0
- data/app/assets/stylesheets/mongoid_forums.sass +1 -0
- data/app/controllers/mongoid_forums/admin/categories_controller.rb +3 -3
- data/app/controllers/mongoid_forums/admin/forums_controller.rb +1 -1
- data/app/controllers/mongoid_forums/admin/users_controller.rb +4 -4
- data/app/controllers/mongoid_forums/application_controller.rb +2 -2
- data/app/controllers/mongoid_forums/forums_controller.rb +7 -1
- data/app/controllers/mongoid_forums/posts_controller.rb +24 -1
- data/app/controllers/mongoid_forums/redirect_controller.rb +12 -12
- data/app/controllers/mongoid_forums/topics_controller.rb +5 -0
- data/app/helpers/mongoid_forums/application_helper.rb +4 -0
- data/app/models/mongoid_forums/ability.rb +8 -0
- data/app/models/mongoid_forums/alert.rb +10 -0
- data/app/models/mongoid_forums/category.rb +22 -5
- data/app/models/mongoid_forums/forum.rb +24 -5
- data/app/models/mongoid_forums/group.rb +13 -1
- data/app/models/mongoid_forums/post.rb +16 -1
- data/app/models/mongoid_forums/subscription.rb +6 -0
- data/app/models/mongoid_forums/topic.rb +32 -11
- data/app/models/mongoid_forums/view.rb +9 -0
- data/app/views/layouts/mongoid_forums/application.haml +13 -11
- data/app/views/mongoid_forums/forums/index.haml +1 -1
- data/app/views/mongoid_forums/posts/_post.haml +14 -3
- data/app/views/mongoid_forums/posts/_quoted.haml +7 -1
- data/app/views/mongoid_forums/{admin → posts/admin}/base/index.haml +3 -0
- data/app/views/mongoid_forums/{admin → posts/admin}/categories/edit.haml +0 -1
- data/app/views/mongoid_forums/{admin → posts/admin}/categories/index.haml +0 -0
- data/app/views/mongoid_forums/{admin → posts/admin}/categories/new.haml +0 -1
- data/app/views/mongoid_forums/{admin → posts/admin}/categories/show.haml +0 -0
- data/app/views/mongoid_forums/{admin → posts/admin}/forums/edit.haml +0 -1
- data/app/views/mongoid_forums/{admin → posts/admin}/forums/index.haml +0 -0
- data/app/views/mongoid_forums/{admin → posts/admin}/forums/new.haml +0 -1
- data/app/views/mongoid_forums/{admin → posts/admin}/forums/show.haml +0 -0
- data/app/views/mongoid_forums/{admin → posts/admin}/groups/edit.haml +0 -0
- data/app/views/mongoid_forums/{admin → posts/admin}/groups/index.haml +0 -0
- data/app/views/mongoid_forums/{admin → posts/admin}/groups/new.haml +0 -0
- data/app/views/mongoid_forums/{admin → posts/admin}/groups/show.haml +0 -0
- data/app/views/mongoid_forums/{admin → posts/admin}/users/index.haml +0 -0
- data/app/views/mongoid_forums/topics/show.haml +5 -1
- data/config/routes.rb +3 -1
- data/lib/{ack_mongoid_forums.rb → ack-mongoid-forums.rb} +0 -0
- data/lib/manual_slug.rb +11 -0
- data/lib/mongoid_forums.rb +7 -6
- data/lib/mongoid_forums/default_permissions.rb +13 -0
- data/lib/mongoid_forums/version.rb +1 -1
- metadata +35 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d52971438d595ba7c1ec41ae9271a9d546627ad4
|
4
|
+
data.tar.gz: c2f8d9d7c42f3692706cc8ac1869415b67f4e119
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4e4e2b6a17ba4db617876dbbf3b881005fbfd23c4c090058ddae1318394b18af39b16a959b9c1c44a0022643b66652d3ed20399c571041ee557bc650c7ffe17
|
7
|
+
data.tar.gz: 984bfa740b097985edefff7bda6c54cef4255a29e21e24c21fc3b9d04a865ff3b075dbb5657ef276abb30e658edd9fb8f4650f7f3540c70a0cbf950f6d66435d
|
data/README.md
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
MongoidForums
|
2
|
+
============
|
3
|
+
|
4
|
+
A forum system for Rails 4 and Mongoid.
|
5
|
+
Inspired by Forem.
|
6
|
+
|
7
|
+
Created due to lack of functioning Rails 4 mongoid engines.
|
8
|
+
|
9
|
+
# Installation
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'mongoid-forums'
|
13
|
+
```
|
14
|
+
|
15
|
+
## Run the installer
|
16
|
+
|
17
|
+
**Ensure that you first of all have a `User` model and some sort of authentication system set up**. We would recommend going with [Devise](http://github.com/plataformatec/devise), but it's up to
|
18
|
+
you. All MongoidForums needs is a model to link topics and posts to.
|
19
|
+
|
20
|
+
Run the installer and answer any questions that pop up. There's sensible defaults there if you don't want to answer them.
|
21
|
+
|
22
|
+
```shell
|
23
|
+
rails g mongoid_forums:install
|
24
|
+
```
|
25
|
+
|
26
|
+
## Set up helper methods in your user model
|
27
|
+
|
28
|
+
MongoidForums depends on a `forum_display_name` (which defaults as `to_s`) method being available on your `User` model so that it can display the user's name in posts. Define it in your model like this:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
def forum_display_name
|
32
|
+
name
|
33
|
+
end
|
34
|
+
```
|
35
|
+
Or simply return the user's display name as the `to_s` method in your user model.
|
36
|
+
|
37
|
+
Please note that if you are using Devise, User model does not have `name` field by default,
|
38
|
+
so you either should add it or use another column (`email` for example).
|
39
|
+
|
40
|
+
The routes (along with some other designs such as Alerts system) for this project are based around Overcast Network's forum system (https://oc.tc/forums)
|
41
|
+
|
42
|
+
See here for an old open source version of oc.tc/forums that this project is based on (and borrows some code from):
|
43
|
+
https://github.com/kultus/forem-2
|
44
|
+
|
45
|
+
|
46
|
+
## Features
|
47
|
+
|
48
|
+
Here's a comprehensive list of the features currently in Mongoid Forumsf:
|
49
|
+
|
50
|
+
* Forums
|
51
|
+
* CRUD operations (provided by an admin backend)
|
52
|
+
* Topics
|
53
|
+
* Viewing all topics for a forum
|
54
|
+
* Creating of new topics
|
55
|
+
* Editing topics
|
56
|
+
* Locking topics
|
57
|
+
* Hiding topics
|
58
|
+
* Pinning topics
|
59
|
+
* Posts
|
60
|
+
* Replying to topics
|
61
|
+
* Deleting own posts
|
62
|
+
* Blocking replies to locked topics
|
63
|
+
* Editing posts
|
64
|
+
* Text Formatting
|
65
|
+
* Posts are HTML escaped and pre tagged by default.
|
66
|
+
* Pluggable formatters for other behaviour
|
67
|
+
* [A flexible permissions system](https://github.com/radar/forem/wiki/Authorization-System) (Works exactly as Forem does, using CanCanCan and allowing overrides)
|
68
|
+
* [Translations](https://github.com/radar/forem/wiki/Translations) (Not complete, some messages currently are hardcoded in English)
|
69
|
+
* [Flexible configuration](https://github.com/radar/forem/wiki/Configuration) (All features of Forem except avatars, profile links, and theme. We are working hard on adding these, but you can also add them to your own project if needed through the default method of overriding rails engine controllers, models, and views!)
|
70
|
+
|
71
|
+
## View Customisation
|
72
|
+
|
73
|
+
If you want to customise Forem, you can copy over the views using the `mongoid_forums:views` generator:
|
74
|
+
|
75
|
+
rails g mongoid_forums:views
|
76
|
+
|
77
|
+
You will then be able to edit the forem views inside the `app/views/mongoid_forums` of your application. These views will take precedence over those in the engine.
|
78
|
+
|
79
|
+
|
80
|
+
## Extending Classes
|
81
|
+
|
82
|
+
All of MongoidForum's business logic (models, controllers, helpers, etc) can easily be extended / overridden to meet your exact requirements using standard Ruby idioms.
|
83
|
+
|
84
|
+
Standard practice for including such changes in your application or extension is to create a directory app/decorators. place file within the relevant app/decorators/models or app/decorators/controllers directory with the original class name with _decorator appended.
|
85
|
+
|
86
|
+
### Adding a custom method to the Post model:
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
# app/decorators/models/mongoid_forums/post_decorator.rb
|
90
|
+
|
91
|
+
MongoidForums::Post.class_eval do
|
92
|
+
def some_method
|
93
|
+
...
|
94
|
+
end
|
95
|
+
end
|
96
|
+
```
|
97
|
+
|
98
|
+
### Adding a custom method to the PostsController:
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
# app/decorators/controllers/mongoid_forums/posts_controller_decorator.rb
|
102
|
+
|
103
|
+
MongoidForums::PostsController.class_eval do
|
104
|
+
def some_action
|
105
|
+
...
|
106
|
+
end
|
107
|
+
end
|
108
|
+
```
|
109
|
+
|
110
|
+
|
111
|
+
Planned Features:
|
112
|
+
- [ ] [emoji](http://www.emoji-cheat-sheet.com/)
|
113
|
+
- [ ] Mass moderation
|
114
|
+
- [ ] Option to have to approve topics/posts manually
|
115
|
+
- [ ] Block spammers feature
|
116
|
+
- [ ] Archiving
|
117
|
+
- [ ] Theming
|
118
|
+
- [ ] User profile links
|
119
|
+
- [ ] Avatars
|
120
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
#= require mongoid_forums/application
|
@@ -0,0 +1 @@
|
|
1
|
+
@import mongoid_forums/application
|
@@ -6,8 +6,8 @@ module MongoidForums
|
|
6
6
|
before_action :set_category, only: [:add_group, :remove_group]
|
7
7
|
|
8
8
|
def index
|
9
|
-
@forums = Forum.
|
10
|
-
@categories = Category.
|
9
|
+
@forums = Forum.sorted
|
10
|
+
@categories = Category.sorted
|
11
11
|
end
|
12
12
|
|
13
13
|
def show
|
@@ -72,7 +72,7 @@ module MongoidForums
|
|
72
72
|
private
|
73
73
|
|
74
74
|
def category_params
|
75
|
-
params.require(:category).permit(:name
|
75
|
+
params.require(:category).permit(:name)
|
76
76
|
end
|
77
77
|
|
78
78
|
def set_category
|
@@ -7,18 +7,18 @@ module MongoidForums
|
|
7
7
|
before_action :set_user, only: [:add_admin, :remove_admin]
|
8
8
|
|
9
9
|
def index
|
10
|
-
@admins = User.
|
11
|
-
@non_admins = User.
|
10
|
+
@admins = User.mongoid_forums_admins
|
11
|
+
@non_admins = User.non_mongoid_forums_admins
|
12
12
|
end
|
13
13
|
|
14
14
|
def add_admin
|
15
|
-
@user.
|
15
|
+
@user.roles << "mongoid_forums_admin"
|
16
16
|
@user.save
|
17
17
|
redirect_to admin_users_path
|
18
18
|
end
|
19
19
|
|
20
20
|
def remove_admin
|
21
|
-
@user.
|
21
|
+
@user.roles.delete "mongoid_forums_admin"
|
22
22
|
@user.save
|
23
23
|
redirect_to admin_users_path
|
24
24
|
end
|
@@ -23,10 +23,10 @@ class MongoidForums::ApplicationController < ApplicationController
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def set_categories
|
26
|
-
@categories = MongoidForums::Category.
|
26
|
+
@categories = MongoidForums::Category.sorted
|
27
27
|
end
|
28
28
|
|
29
|
-
|
29
|
+
def authenticate_mongoid_forums_user
|
30
30
|
if !mongoid_forums_user
|
31
31
|
session["user_return_to"] = request.fullpath
|
32
32
|
flash.alert = t("mongoid_forums.errors.not_signed_in")
|
@@ -6,7 +6,10 @@ module MongoidForums
|
|
6
6
|
before_filter :authenticate_mongoid_forums_user, :only => [:create, :new]
|
7
7
|
|
8
8
|
def index
|
9
|
-
@categories = Category.
|
9
|
+
@categories = Category.sorted
|
10
|
+
unless mongoid_forums_user.mongoid_forums_admin?
|
11
|
+
@categories = @categories.enabled
|
12
|
+
end
|
10
13
|
end
|
11
14
|
|
12
15
|
def show
|
@@ -14,6 +17,9 @@ module MongoidForums
|
|
14
17
|
register_view
|
15
18
|
|
16
19
|
@topics = @forum.topics
|
20
|
+
unless mongoid_forums_user.mongoid_forums_admin?
|
21
|
+
@topics = @topics.enabled
|
22
|
+
end
|
17
23
|
@topics = @topics.by_pinned_or_most_recent_post.page(params[:page]).per(MongoidForums.per_page)
|
18
24
|
end
|
19
25
|
|
@@ -79,7 +79,8 @@ module MongoidForums
|
|
79
79
|
redirect_to @topic and return
|
80
80
|
end
|
81
81
|
|
82
|
-
if @post.destroy
|
82
|
+
# if @post.destroy
|
83
|
+
if @post.update_attributes(is_deleted: true)
|
83
84
|
flash[:notice] = t("mongoid_forums.post.deleted")
|
84
85
|
redirect_to @topic
|
85
86
|
else
|
@@ -88,6 +89,26 @@ module MongoidForums
|
|
88
89
|
end
|
89
90
|
end
|
90
91
|
|
92
|
+
def recovery
|
93
|
+
find_post
|
94
|
+
|
95
|
+
authorize! :recovery_post, @topic.forum
|
96
|
+
|
97
|
+
unless @post.owner_or_admin? mongoid_forums_user
|
98
|
+
flash[:alert] = t("mongoid_forums.post.cannot_recover")
|
99
|
+
redirect_to @topic and return
|
100
|
+
end
|
101
|
+
|
102
|
+
# if @post.destroy
|
103
|
+
if @post.update_attributes(is_deleted: false)
|
104
|
+
flash[:notice] = t("mongoid_forums.post.recovered")
|
105
|
+
redirect_to @topic
|
106
|
+
else
|
107
|
+
flash[:notice] = t("mongoid_forums.post.cannot_recover")
|
108
|
+
redirect_to @topic
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
91
112
|
private
|
92
113
|
|
93
114
|
#TODO: Decide if this should be used
|
@@ -119,6 +140,8 @@ module MongoidForums
|
|
119
140
|
|
120
141
|
def current_resource
|
121
142
|
@current_resource ||= Post.find(params[:id]) if params[:id]
|
143
|
+
@current_resource ||= Post.find(params[:post_id]) if params[:post_id]
|
144
|
+
@current_resource
|
122
145
|
end
|
123
146
|
|
124
147
|
def post_params
|
@@ -4,29 +4,29 @@ module MongoidForums
|
|
4
4
|
class RedirectController < ApplicationController
|
5
5
|
|
6
6
|
def forum
|
7
|
-
|
7
|
+
return redirect_to forum_path(params[:forum_id])
|
8
8
|
end
|
9
9
|
|
10
10
|
def topic
|
11
|
-
|
11
|
+
return redirect_to topic_path(params[:topic_id])
|
12
12
|
end
|
13
13
|
|
14
14
|
def posts
|
15
|
-
|
16
|
-
|
17
|
-
|
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
18
|
|
19
|
-
|
19
|
+
posts = post.topic.posts
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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
26
|
end
|
27
27
|
|
28
28
|
def subscriptions
|
29
|
-
|
29
|
+
return redirect_to my_subscriptions_path
|
30
30
|
end
|
31
31
|
|
32
32
|
end
|
@@ -60,6 +60,9 @@ module MongoidForums
|
|
60
60
|
def find_topic
|
61
61
|
begin
|
62
62
|
scope = @forum.topics # TODO: pending review stuff
|
63
|
+
unless mongoid_forums_user.mongoid_forums_admin?
|
64
|
+
scope = scope.enabled
|
65
|
+
end
|
63
66
|
@topic = scope.find(params[:id])
|
64
67
|
authorize! :read, @topic
|
65
68
|
rescue Mongoid::Errors::DocumentNotFound
|
@@ -74,6 +77,8 @@ module MongoidForums
|
|
74
77
|
|
75
78
|
def current_resource
|
76
79
|
@current_resource ||= Topic.find(params[:id]) if params[:id]
|
80
|
+
@current_resource ||= Topic.find(params[:topic_id]) if params[:topic_id]
|
81
|
+
@current_resource
|
77
82
|
end
|
78
83
|
|
79
84
|
def topic_params
|
@@ -3,6 +3,10 @@ module MongoidForums
|
|
3
3
|
include FormattingHelper
|
4
4
|
# processes text with installed markup formatter
|
5
5
|
def mongoid_forums_format(text, *options)
|
6
|
+
text = text.gsub(URI::regexp){ |url|
|
7
|
+
url = Addressable::URI.parse(url).normalize
|
8
|
+
"<a href='#{url}'>#{url.display_uri}</a>"
|
9
|
+
}.html_safe
|
6
10
|
as_formatted_html(text)
|
7
11
|
end
|
8
12
|
|
@@ -49,6 +49,14 @@ module MongoidForums
|
|
49
49
|
user.can_destroy_mongoid_forums_posts?(forum)
|
50
50
|
end
|
51
51
|
|
52
|
+
can :recovery_post, MongoidForums::Forum do |forum|
|
53
|
+
user.can_recovery_mongoid_forums_posts?(forum)
|
54
|
+
end
|
55
|
+
|
56
|
+
can :show_deleted_post, MongoidForums::Forum do |forum|
|
57
|
+
user.can_show_deleted_mongoid_forums_posts?(forum)
|
58
|
+
end
|
59
|
+
|
52
60
|
can :moderate, MongoidForums::Forum do |forum|
|
53
61
|
user.can_moderate_mongoid_forums_forum?(forum) || user.mongoid_forums_admin?
|
54
62
|
end
|
@@ -75,6 +75,16 @@ module MongoidForums
|
|
75
75
|
end
|
76
76
|
return str
|
77
77
|
end
|
78
|
+
|
79
|
+
rails_admin do
|
80
|
+
field :read, :toggle
|
81
|
+
field :read_at
|
82
|
+
field :subscription
|
83
|
+
field :user
|
84
|
+
field :mongoid_forums_topic_replier
|
85
|
+
field :mongoid_forums_topic_count
|
86
|
+
field :mongoid_forums_topic_post
|
87
|
+
end
|
78
88
|
end
|
79
89
|
|
80
90
|
end
|
@@ -1,16 +1,23 @@
|
|
1
1
|
module MongoidForums
|
2
2
|
class Category
|
3
3
|
include Mongoid::Document
|
4
|
+
include ::Mongoid::Timestamps
|
4
5
|
|
5
|
-
|
6
|
-
|
6
|
+
include Enableable
|
7
|
+
# include Seoable
|
8
|
+
include SortField
|
7
9
|
|
10
|
+
include ::ManualSlug
|
8
11
|
|
9
|
-
field :name
|
12
|
+
field :name, type: String
|
13
|
+
manual_slug :name
|
10
14
|
validates :name, :presence => true
|
11
15
|
|
12
|
-
|
13
|
-
|
16
|
+
acts_as_nested_set
|
17
|
+
scope :sorted, -> { order_by([:lft, :asc]) }
|
18
|
+
|
19
|
+
has_many :forums, :class_name => "MongoidForums::Forum", dependent: :destroy
|
20
|
+
has_and_belongs_to_many :moderator_groups, :class_name => "MongoidForums::Group", inverse_of: nil
|
14
21
|
|
15
22
|
def moderator?(user)
|
16
23
|
return false unless user
|
@@ -27,5 +34,15 @@ module MongoidForums
|
|
27
34
|
end
|
28
35
|
return array
|
29
36
|
end
|
37
|
+
|
38
|
+
rails_admin do
|
39
|
+
field :enabled, :toggle
|
40
|
+
field :name
|
41
|
+
field :created_at
|
42
|
+
field :updated_at
|
43
|
+
field :moderator_groups
|
44
|
+
|
45
|
+
nested_set({max_depth: 1})
|
46
|
+
end
|
30
47
|
end
|
31
48
|
end
|
@@ -1,8 +1,22 @@
|
|
1
1
|
module MongoidForums
|
2
2
|
class Forum
|
3
3
|
include Mongoid::Document
|
4
|
+
include ::Mongoid::Timestamps
|
4
5
|
include MongoidForums::Concerns::Viewable
|
5
6
|
|
7
|
+
include Enableable
|
8
|
+
# include Seoable
|
9
|
+
include SortField
|
10
|
+
|
11
|
+
include ::ManualSlug
|
12
|
+
|
13
|
+
field :name, type: String
|
14
|
+
manual_slug :name
|
15
|
+
validates :name, :presence => true
|
16
|
+
|
17
|
+
acts_as_nested_set
|
18
|
+
scope :sorted, -> { order_by([:lft, :asc]) }
|
19
|
+
|
6
20
|
belongs_to :category, :class_name => "MongoidForums::Category"
|
7
21
|
validates :category, :presence => true
|
8
22
|
|
@@ -11,14 +25,9 @@ module MongoidForums
|
|
11
25
|
# Caching
|
12
26
|
field :posts_count, :type => Integer
|
13
27
|
|
14
|
-
field :name
|
15
28
|
|
16
29
|
has_and_belongs_to_many :moderator_groups, :class_name => "MongoidForums::Group", inverse_of: nil
|
17
30
|
|
18
|
-
validates :category, :name, :presence => true
|
19
|
-
field :position, :type => Integer, :default => 0
|
20
|
-
validates :position, numericality: { only_integer: true }
|
21
|
-
|
22
31
|
def unread_topic_count(user)
|
23
32
|
view = View.where(:viewable_id => id, :user_id => user.id).first
|
24
33
|
return topics.count unless view.present?
|
@@ -62,6 +71,16 @@ module MongoidForums
|
|
62
71
|
return array
|
63
72
|
end
|
64
73
|
|
74
|
+
rails_admin do
|
75
|
+
field :enabled, :toggle
|
76
|
+
field :name
|
77
|
+
field :created_at
|
78
|
+
field :updated_at
|
79
|
+
field :category
|
80
|
+
field :posts_count
|
81
|
+
field :moderator_groups
|
65
82
|
|
83
|
+
nested_set({max_depth: 1})
|
84
|
+
end
|
66
85
|
end
|
67
86
|
end
|
@@ -1,15 +1,27 @@
|
|
1
1
|
module MongoidForums
|
2
2
|
class Group
|
3
3
|
include Mongoid::Document
|
4
|
+
include ::Mongoid::Timestamps
|
5
|
+
|
6
|
+
include Enableable
|
4
7
|
|
5
8
|
validates :name, :moderator, :presence => true
|
6
9
|
|
7
10
|
field :name, type: String
|
8
11
|
field :moderator, type: Boolean
|
9
|
-
|
12
|
+
has_and_belongs_to_many :members, class_name: MongoidForums.user_class.to_s, inverse_of: nil
|
10
13
|
|
11
14
|
def to_s
|
12
15
|
name
|
13
16
|
end
|
17
|
+
|
18
|
+
rails_admin do
|
19
|
+
field :enabled, :toggle
|
20
|
+
field :name
|
21
|
+
field :created_at
|
22
|
+
field :updated_at
|
23
|
+
field :moderator
|
24
|
+
field :members
|
25
|
+
end
|
14
26
|
end
|
15
27
|
end
|
@@ -3,6 +3,11 @@ module MongoidForums
|
|
3
3
|
include Mongoid::Document
|
4
4
|
include Mongoid::Timestamps
|
5
5
|
|
6
|
+
include Enableable
|
7
|
+
|
8
|
+
field :is_deleted, type: Boolean, default: false
|
9
|
+
alias :deleted :is_deleted
|
10
|
+
|
6
11
|
after_create :set_topic_last_post_at
|
7
12
|
|
8
13
|
belongs_to :topic, :class_name => "MongoidForums::Topic"
|
@@ -32,9 +37,19 @@ module MongoidForums
|
|
32
37
|
user == other_user || (other_user.mongoid_forums_admin? || topic.forum.moderator?(other_user))
|
33
38
|
end
|
34
39
|
|
40
|
+
rails_admin do
|
41
|
+
field :enabled, :toggle
|
42
|
+
field :is_deleted, :toggle
|
43
|
+
field :created_at
|
44
|
+
field :updated_at
|
45
|
+
field :topic
|
46
|
+
field :user
|
47
|
+
field :text
|
48
|
+
end
|
49
|
+
|
35
50
|
protected
|
36
51
|
def set_topic_last_post_at
|
37
52
|
self.topic.update_attribute(:last_post_at, self.created_at)
|
38
53
|
end
|
39
|
-
|
54
|
+
end
|
40
55
|
end
|
@@ -5,14 +5,29 @@ module MongoidForums
|
|
5
5
|
include MongoidForums::Concerns::Subscribable
|
6
6
|
include MongoidForums::Concerns::Viewable
|
7
7
|
|
8
|
+
include Mongoid::Document
|
9
|
+
include ::Mongoid::Timestamps
|
10
|
+
|
11
|
+
include Enableable
|
12
|
+
# include Seoable
|
13
|
+
# include SortField
|
14
|
+
|
15
|
+
include ::ManualSlug
|
16
|
+
|
17
|
+
field :name, type: String
|
18
|
+
manual_slug :name
|
19
|
+
validates :name, :presence => true
|
20
|
+
|
21
|
+
# acts_as_nested_set
|
22
|
+
# scope :sorted, -> { order_by([:lft, :asc]) }
|
23
|
+
|
8
24
|
after_create :subscribe_creator
|
9
25
|
|
10
|
-
belongs_to :forum,
|
11
|
-
has_many :posts,
|
26
|
+
belongs_to :forum, :class_name => "MongoidForums::Forum"
|
27
|
+
has_many :posts, :class_name => "MongoidForums::Post", dependent: :destroy
|
12
28
|
|
13
29
|
belongs_to :user, :class_name => MongoidForums.user_class.to_s
|
14
30
|
|
15
|
-
field :name
|
16
31
|
|
17
32
|
field :locked, type: Boolean, default: false
|
18
33
|
field :pinned, type: Boolean, default: false
|
@@ -21,6 +36,9 @@ module MongoidForums
|
|
21
36
|
validates :name, :presence => true, :length => { maximum: 255 }
|
22
37
|
validates :user, :presence => true
|
23
38
|
|
39
|
+
scope :by_most_recent_post, order_by([:last_post_at, :desc])
|
40
|
+
scope :by_pinned_or_most_recent_post, order_by([:pinned, :desc], [:last_post_at, :desc])
|
41
|
+
|
24
42
|
def can_be_replied_to?
|
25
43
|
!locked?
|
26
44
|
end
|
@@ -42,14 +60,17 @@ module MongoidForums
|
|
42
60
|
return count
|
43
61
|
end
|
44
62
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
63
|
+
rails_admin do
|
64
|
+
field :enabled, :toggle
|
65
|
+
field :locked, :toggle
|
66
|
+
field :pinned, :toggle
|
67
|
+
field :hidden, :toggle
|
68
|
+
field :created_at
|
69
|
+
field :updated_at
|
70
|
+
# field :view_count
|
71
|
+
field :name
|
72
|
+
field :forum
|
73
|
+
field :user
|
53
74
|
end
|
54
75
|
end
|
55
76
|
end
|
@@ -21,6 +21,15 @@ module MongoidForums
|
|
21
21
|
updated_at
|
22
22
|
end
|
23
23
|
|
24
|
+
rails_admin do
|
25
|
+
field :created_at
|
26
|
+
field :updated_at
|
27
|
+
field :current_viewed_at
|
28
|
+
field :past_viewed_at
|
29
|
+
field :viewable
|
30
|
+
field :user
|
31
|
+
end
|
32
|
+
|
24
33
|
private
|
25
34
|
def set_viewed_at_to_now
|
26
35
|
self.current_viewed_at = Time.now
|
@@ -2,20 +2,22 @@
|
|
2
2
|
%html
|
3
3
|
%head
|
4
4
|
%title Forums
|
5
|
-
= stylesheet_link_tag '
|
6
|
-
= javascript_include_tag '
|
5
|
+
= stylesheet_link_tag 'mongoid_forums', media: 'all', async: true
|
6
|
+
= javascript_include_tag 'mongoid_forums'
|
7
7
|
= csrf_meta_tags
|
8
8
|
%body
|
9
9
|
- if mongoid_forums_user.present?
|
10
|
-
- @alerts.
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
10
|
+
- unless @alerts.blank?
|
11
|
+
- @alerts.each do |al|
|
12
|
+
= al.mongoid_forums_topic_replier
|
13
|
+
replied to
|
14
|
+
- topic = MongoidForums::Post.find(al.mongoid_forums_topic_post_id).topic
|
15
|
+
= link_to topic.name, al.link
|
16
|
+
= time_ago_in_words(al.created_at)
|
17
|
+
ago
|
17
18
|
|
18
|
-
- flash.
|
19
|
-
|
19
|
+
- unless flash.blank?
|
20
|
+
- flash.each do |name, msg|
|
21
|
+
= content_tag :p, msg if msg.is_a?(String)
|
20
22
|
|
21
23
|
= yield
|
@@ -10,15 +10,26 @@ ago
|
|
10
10
|
= link_to 'Quote', new_topic_post_path(post.topic_id, :reply_to_id => post.id)
|
11
11
|
- if mongoid_forums_user && post.owner_or_admin?(mongoid_forums_user)
|
12
12
|
- if can?(:edit_post, post.topic.forum)
|
13
|
+
|
|
13
14
|
= link_to "Edit", edit_topic_post_path(post.topic_id, post)
|
14
|
-
- if can?(:destroy_post, post.topic.forum)
|
15
|
-
|
15
|
+
- if !post.deleted and can?(:destroy_post, post.topic.forum)
|
16
|
+
|
|
17
|
+
= link_to "Delete", topic_post_path(post.topic_id, post), data: {method: :delete}
|
18
|
+
- if post.deleted and can?(:recovery_post, post.topic.forum)
|
19
|
+
|
|
20
|
+
= link_to "Recovery", topic_post_recovery_path(post.topic_id, post), data: {method: :post}
|
16
21
|
|
17
22
|
|
18
23
|
%br
|
19
24
|
- if post.reply_to_id
|
20
25
|
= render :partial => 'mongoid_forums/posts/quoted', :locals => {:post => post}
|
21
26
|
%br
|
22
|
-
|
27
|
+
- if !post.deleted or can?(:show_deleted_post, post.topic.forum)
|
28
|
+
- if post.deleted and can?(:show_deleted_post, post.topic.forum)
|
29
|
+
= "Deleted"
|
30
|
+
%br
|
31
|
+
= mongoid_forums_format(post.text)
|
32
|
+
- else
|
33
|
+
= "Deleted"
|
23
34
|
%br
|
24
35
|
%hr
|
@@ -6,4 +6,10 @@
|
|
6
6
|
ago
|
7
7
|
%br
|
8
8
|
>
|
9
|
-
|
9
|
+
- if !reply_to.deleted or can?(:show_deleted_post, reply_to.topic.forum)
|
10
|
+
- if reply_to.deleted and can?(:show_deleted_post, reply_to.topic.forum)
|
11
|
+
= "Deleted"
|
12
|
+
%br
|
13
|
+
= mongoid_forums_format(reply_to.text)
|
14
|
+
- else
|
15
|
+
= "Deleted"
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,14 +1,18 @@
|
|
1
1
|
%h1 Viewing Topic "#{@topic.name}"
|
2
2
|
- if mongoid_forums_admin?
|
3
3
|
= link_to t("mongoid_forums.topics.actions.hide.#{@topic.hidden}"), toggle_hide_admin_topic_path(@forum, @topic), :class => "btn"
|
4
|
+
|
|
4
5
|
= link_to t("mongoid_forums.topics.actions.lock.#{@topic.locked}"), toggle_lock_admin_topic_path(@forum, @topic), :class => "btn"
|
6
|
+
|
|
5
7
|
= link_to t("mongoid_forums.topics.actions.pin.#{@topic.pinned}"), toggle_pin_admin_topic_path(@forum, @topic), :class => "btn"
|
6
8
|
|
7
9
|
- if @topic.can_be_replied_to? && can?(:reply, @topic)
|
10
|
+
|
|
8
11
|
= link_to "Reply to topic", new_topic_post_path(@topic)
|
12
|
+
|
|
9
13
|
- if mongoid_forums_user && @topic.subscriber?(mongoid_forums_user.id)
|
10
14
|
= link_to "Unsubscribe", unsubscribe_topic_path(@topic)
|
11
|
-
-elsif mongoid_forums_user
|
15
|
+
- elsif mongoid_forums_user
|
12
16
|
= link_to "Subscribe", subscribe_topic_path(@topic)
|
13
17
|
%br
|
14
18
|
= paginate @posts
|
data/config/routes.rb
CHANGED
File without changes
|
data/lib/manual_slug.rb
ADDED
data/lib/mongoid_forums.rb
CHANGED
@@ -7,6 +7,7 @@ require 'mongoid_forums/default_permissions'
|
|
7
7
|
require 'sanitize'
|
8
8
|
require 'haml'
|
9
9
|
require "mongoid"
|
10
|
+
require 'ack_rocket_cms_mongoid'
|
10
11
|
|
11
12
|
module MongoidForums
|
12
13
|
mattr_accessor :per_page, :user_class, :formatter, :email_from_address, :sign_in_path
|
@@ -19,15 +20,15 @@ module MongoidForums
|
|
19
20
|
has_many :mongoid_forums_posts, :class_name => "MongoidForums::Post", :foreign_key => "user_id"
|
20
21
|
has_many :mongoid_forums_topics, :class_name => "MongoidForums::Topic", :foreign_key => "user_id"
|
21
22
|
|
22
|
-
field :mongoid_admin, type: Boolean, default: false
|
23
|
-
|
24
|
-
def mongoid_forums_admin?
|
25
|
-
|
26
|
-
end unless method_defined? :mongoid_forums_admin
|
23
|
+
# field :mongoid_admin, type: Boolean, default: false
|
24
|
+
#
|
25
|
+
# def mongoid_forums_admin?
|
26
|
+
# mongoid_admin
|
27
|
+
# end unless method_defined? :mongoid_forums_admin
|
27
28
|
|
28
29
|
# Using +to_s+ by default for backwards compatibility
|
29
30
|
def forum_display_name
|
30
|
-
|
31
|
+
name_or_login
|
31
32
|
end unless method_defined? :forum_display_name
|
32
33
|
|
33
34
|
end
|
@@ -47,6 +47,19 @@ module MongoidForums
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
+
unless method_defined?(:can_recovery_mongoid_forums_posts?)
|
51
|
+
def can_recovery_mongoid_forums_posts?(forum)
|
52
|
+
true
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
unless method_defined?(:can_show_deleted_mongoid_forums_posts?)
|
57
|
+
def can_show_deleted_mongoid_forums_posts?(forum)
|
58
|
+
true
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
|
50
63
|
unless method_defined?(:can_read_mongoid_forums_topic?)
|
51
64
|
def can_read_mongoid_forums_topic?(topic)
|
52
65
|
!topic.hidden? || mongoid_forums_admin?
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ack-mongoid-forums
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ack43
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-11-
|
12
|
+
date: 2015-11-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -123,6 +123,20 @@ dependencies:
|
|
123
123
|
- - ">="
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: ack_rocket_cms
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
type: :runtime
|
134
|
+
prerelease: false
|
135
|
+
version_requirements: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
126
140
|
- !ruby/object:Gem::Dependency
|
127
141
|
name: devise
|
128
142
|
requirement: !ruby/object:Gem::Requirement
|
@@ -174,7 +188,9 @@ extensions: []
|
|
174
188
|
extra_rdoc_files: []
|
175
189
|
files:
|
176
190
|
- MIT-LICENSE
|
191
|
+
- README.md
|
177
192
|
- Rakefile
|
193
|
+
- app/assets/javascripts/mongoid_forums.coffee
|
178
194
|
- app/assets/javascripts/mongoid_forums/admin/base.js
|
179
195
|
- app/assets/javascripts/mongoid_forums/admin/categories.js
|
180
196
|
- app/assets/javascripts/mongoid_forums/admin/forums.js
|
@@ -184,6 +200,7 @@ files:
|
|
184
200
|
- app/assets/javascripts/mongoid_forums/forums.js
|
185
201
|
- app/assets/javascripts/mongoid_forums/posts.js
|
186
202
|
- app/assets/javascripts/mongoid_forums/topics.js
|
203
|
+
- app/assets/stylesheets/mongoid_forums.sass
|
187
204
|
- app/assets/stylesheets/mongoid_forums/admin/base.css
|
188
205
|
- app/assets/stylesheets/mongoid_forums/admin/categories.css
|
189
206
|
- app/assets/stylesheets/mongoid_forums/admin/forums.css
|
@@ -228,26 +245,26 @@ files:
|
|
228
245
|
- app/models/mongoid_forums/topic.rb
|
229
246
|
- app/models/mongoid_forums/view.rb
|
230
247
|
- app/views/layouts/mongoid_forums/application.haml
|
231
|
-
- app/views/mongoid_forums/admin/base/index.haml
|
232
|
-
- app/views/mongoid_forums/admin/categories/edit.haml
|
233
|
-
- app/views/mongoid_forums/admin/categories/index.haml
|
234
|
-
- app/views/mongoid_forums/admin/categories/new.haml
|
235
|
-
- app/views/mongoid_forums/admin/categories/show.haml
|
236
|
-
- app/views/mongoid_forums/admin/forums/edit.haml
|
237
|
-
- app/views/mongoid_forums/admin/forums/index.haml
|
238
|
-
- app/views/mongoid_forums/admin/forums/new.haml
|
239
|
-
- app/views/mongoid_forums/admin/forums/show.haml
|
240
|
-
- app/views/mongoid_forums/admin/groups/edit.haml
|
241
|
-
- app/views/mongoid_forums/admin/groups/index.haml
|
242
|
-
- app/views/mongoid_forums/admin/groups/new.haml
|
243
|
-
- app/views/mongoid_forums/admin/groups/show.haml
|
244
|
-
- app/views/mongoid_forums/admin/users/index.haml
|
245
248
|
- app/views/mongoid_forums/forums/index.haml
|
246
249
|
- app/views/mongoid_forums/forums/new.haml
|
247
250
|
- app/views/mongoid_forums/forums/show.haml
|
248
251
|
- app/views/mongoid_forums/posts/_form.haml
|
249
252
|
- app/views/mongoid_forums/posts/_post.haml
|
250
253
|
- app/views/mongoid_forums/posts/_quoted.haml
|
254
|
+
- app/views/mongoid_forums/posts/admin/base/index.haml
|
255
|
+
- app/views/mongoid_forums/posts/admin/categories/edit.haml
|
256
|
+
- app/views/mongoid_forums/posts/admin/categories/index.haml
|
257
|
+
- app/views/mongoid_forums/posts/admin/categories/new.haml
|
258
|
+
- app/views/mongoid_forums/posts/admin/categories/show.haml
|
259
|
+
- app/views/mongoid_forums/posts/admin/forums/edit.haml
|
260
|
+
- app/views/mongoid_forums/posts/admin/forums/index.haml
|
261
|
+
- app/views/mongoid_forums/posts/admin/forums/new.haml
|
262
|
+
- app/views/mongoid_forums/posts/admin/forums/show.haml
|
263
|
+
- app/views/mongoid_forums/posts/admin/groups/edit.haml
|
264
|
+
- app/views/mongoid_forums/posts/admin/groups/index.haml
|
265
|
+
- app/views/mongoid_forums/posts/admin/groups/new.haml
|
266
|
+
- app/views/mongoid_forums/posts/admin/groups/show.haml
|
267
|
+
- app/views/mongoid_forums/posts/admin/users/index.haml
|
251
268
|
- app/views/mongoid_forums/posts/edit.haml
|
252
269
|
- app/views/mongoid_forums/posts/new.haml
|
253
270
|
- app/views/mongoid_forums/topics/_topic.haml
|
@@ -257,10 +274,11 @@ files:
|
|
257
274
|
- app/views/mongoid_forums/topics/show.haml
|
258
275
|
- config/locales/en.yml
|
259
276
|
- config/routes.rb
|
260
|
-
- lib/
|
277
|
+
- lib/ack-mongoid-forums.rb
|
261
278
|
- lib/generators/mongoid_forums/install/templates/initializer.rb
|
262
279
|
- lib/generators/mongoid_forums/install_generator.rb
|
263
280
|
- lib/generators/mongoid_forums/views_generator.rb
|
281
|
+
- lib/manual_slug.rb
|
264
282
|
- lib/mongoid_forums.rb
|
265
283
|
- lib/mongoid_forums/default_permissions.rb
|
266
284
|
- lib/mongoid_forums/engine.rb
|