ack-mongoid-forums 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (170) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +35 -0
  4. data/app/assets/javascripts/mongoid_forums/admin/base.js +2 -0
  5. data/app/assets/javascripts/mongoid_forums/admin/categories.js +2 -0
  6. data/app/assets/javascripts/mongoid_forums/admin/forums.js +2 -0
  7. data/app/assets/javascripts/mongoid_forums/admin/groups.js +2 -0
  8. data/app/assets/javascripts/mongoid_forums/admin/users.js +2 -0
  9. data/app/assets/javascripts/mongoid_forums/application.js +15 -0
  10. data/app/assets/javascripts/mongoid_forums/forums.js +2 -0
  11. data/app/assets/javascripts/mongoid_forums/posts.js +2 -0
  12. data/app/assets/javascripts/mongoid_forums/topics.js +2 -0
  13. data/app/assets/stylesheets/mongoid_forums/admin/base.css +4 -0
  14. data/app/assets/stylesheets/mongoid_forums/admin/categories.css +4 -0
  15. data/app/assets/stylesheets/mongoid_forums/admin/forums.css +4 -0
  16. data/app/assets/stylesheets/mongoid_forums/admin/groups.css +4 -0
  17. data/app/assets/stylesheets/mongoid_forums/admin/users.css +4 -0
  18. data/app/assets/stylesheets/mongoid_forums/application.css +15 -0
  19. data/app/assets/stylesheets/mongoid_forums/forums.css +4 -0
  20. data/app/assets/stylesheets/mongoid_forums/posts.css +4 -0
  21. data/app/assets/stylesheets/mongoid_forums/topics.css +4 -0
  22. data/app/assets/stylesheets/scaffold.css +56 -0
  23. data/app/controllers/mongoid_forums/admin/base_controller.rb +18 -0
  24. data/app/controllers/mongoid_forums/admin/categories_controller.rb +83 -0
  25. data/app/controllers/mongoid_forums/admin/forums_controller.rb +83 -0
  26. data/app/controllers/mongoid_forums/admin/groups_controller.rb +83 -0
  27. data/app/controllers/mongoid_forums/admin/topics_controller.rb +48 -0
  28. data/app/controllers/mongoid_forums/admin/users_controller.rb +34 -0
  29. data/app/controllers/mongoid_forums/application_controller.rb +57 -0
  30. data/app/controllers/mongoid_forums/forums_controller.rb +66 -0
  31. data/app/controllers/mongoid_forums/posts_controller.rb +133 -0
  32. data/app/controllers/mongoid_forums/redirect_controller.rb +33 -0
  33. data/app/controllers/mongoid_forums/topics_controller.rb +83 -0
  34. data/app/decorators/lib/mongoid_forums/user_class_decorator.rb +1 -0
  35. data/app/helpers/mongoid_forums/admin/base_helper.rb +4 -0
  36. data/app/helpers/mongoid_forums/admin/categories_helper.rb +4 -0
  37. data/app/helpers/mongoid_forums/admin/forums_helper.rb +4 -0
  38. data/app/helpers/mongoid_forums/admin/groups_helper.rb +4 -0
  39. data/app/helpers/mongoid_forums/admin/users_helper.rb +4 -0
  40. data/app/helpers/mongoid_forums/application_helper.rb +20 -0
  41. data/app/helpers/mongoid_forums/formatting_helper.rb +28 -0
  42. data/app/helpers/mongoid_forums/forums_helper.rb +15 -0
  43. data/app/helpers/mongoid_forums/posts_helper.rb +4 -0
  44. data/app/helpers/mongoid_forums/topics_helper.rb +4 -0
  45. data/app/models/mongoid_forums/ability.rb +65 -0
  46. data/app/models/mongoid_forums/alert.rb +80 -0
  47. data/app/models/mongoid_forums/category.rb +31 -0
  48. data/app/models/mongoid_forums/concerns/subscribable.rb +76 -0
  49. data/app/models/mongoid_forums/concerns/viewable.rb +60 -0
  50. data/app/models/mongoid_forums/forum.rb +67 -0
  51. data/app/models/mongoid_forums/group.rb +15 -0
  52. data/app/models/mongoid_forums/post.rb +40 -0
  53. data/app/models/mongoid_forums/subscription.rb +65 -0
  54. data/app/models/mongoid_forums/topic.rb +55 -0
  55. data/app/models/mongoid_forums/view.rb +30 -0
  56. data/app/views/layouts/mongoid_forums/application.haml +21 -0
  57. data/app/views/mongoid_forums/admin/base/index.haml +6 -0
  58. data/app/views/mongoid_forums/admin/categories/edit.haml +4 -0
  59. data/app/views/mongoid_forums/admin/categories/index.haml +21 -0
  60. data/app/views/mongoid_forums/admin/categories/new.haml +4 -0
  61. data/app/views/mongoid_forums/admin/categories/show.haml +21 -0
  62. data/app/views/mongoid_forums/admin/forums/edit.haml +5 -0
  63. data/app/views/mongoid_forums/admin/forums/index.haml +25 -0
  64. data/app/views/mongoid_forums/admin/forums/new.haml +5 -0
  65. data/app/views/mongoid_forums/admin/forums/show.haml +21 -0
  66. data/app/views/mongoid_forums/admin/groups/edit.haml +4 -0
  67. data/app/views/mongoid_forums/admin/groups/index.haml +23 -0
  68. data/app/views/mongoid_forums/admin/groups/new.haml +5 -0
  69. data/app/views/mongoid_forums/admin/groups/show.haml +26 -0
  70. data/app/views/mongoid_forums/admin/users/index.haml +24 -0
  71. data/app/views/mongoid_forums/forums/index.haml +46 -0
  72. data/app/views/mongoid_forums/forums/new.haml +15 -0
  73. data/app/views/mongoid_forums/forums/show.haml +47 -0
  74. data/app/views/mongoid_forums/posts/_form.haml +4 -0
  75. data/app/views/mongoid_forums/posts/_post.haml +24 -0
  76. data/app/views/mongoid_forums/posts/_quoted.haml +9 -0
  77. data/app/views/mongoid_forums/posts/edit.haml +17 -0
  78. data/app/views/mongoid_forums/posts/new.haml +17 -0
  79. data/app/views/mongoid_forums/topics/_topic.haml +2 -0
  80. data/app/views/mongoid_forums/topics/my_posts.haml +6 -0
  81. data/app/views/mongoid_forums/topics/my_subscriptions.haml +5 -0
  82. data/app/views/mongoid_forums/topics/my_topics.haml +6 -0
  83. data/app/views/mongoid_forums/topics/show.haml +16 -0
  84. data/config/locales/en.yml +196 -0
  85. data/config/routes.rb +62 -0
  86. data/lib/ack_mongoid_forums.rb +1 -0
  87. data/lib/generators/mongoid_forums/install/templates/initializer.rb +5 -0
  88. data/lib/generators/mongoid_forums/install_generator.rb +90 -0
  89. data/lib/generators/mongoid_forums/views_generator.rb +27 -0
  90. data/lib/mongoid_forums.rb +53 -0
  91. data/lib/mongoid_forums/default_permissions.rb +63 -0
  92. data/lib/mongoid_forums/engine.rb +20 -0
  93. data/lib/mongoid_forums/sanitizer.rb +10 -0
  94. data/lib/mongoid_forums/version.rb +3 -0
  95. data/lib/tasks/mongoid_forums_tasks.rake +4 -0
  96. data/test/controllers/mongoid_forums/admin/base_controller_test.rb +11 -0
  97. data/test/controllers/mongoid_forums/admin/categories_controller_test.rb +31 -0
  98. data/test/controllers/mongoid_forums/admin/forums_controller_test.rb +31 -0
  99. data/test/controllers/mongoid_forums/admin/groups_controller_test.rb +41 -0
  100. data/test/controllers/mongoid_forums/admin/users_controller_test.rb +11 -0
  101. data/test/controllers/mongoid_forums/forums_controller_test.rb +16 -0
  102. data/test/controllers/mongoid_forums/posts_controller_test.rb +36 -0
  103. data/test/controllers/mongoid_forums/topics_controller_test.rb +36 -0
  104. data/test/dummy/README.rdoc +28 -0
  105. data/test/dummy/Rakefile +6 -0
  106. data/test/dummy/app/assets/javascripts/application.js +15 -0
  107. data/test/dummy/app/assets/javascripts/welcome.js +2 -0
  108. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  109. data/test/dummy/app/assets/stylesheets/scaffold.css +56 -0
  110. data/test/dummy/app/assets/stylesheets/welcome.css +4 -0
  111. data/test/dummy/app/controllers/application_controller.rb +11 -0
  112. data/test/dummy/app/controllers/welcome_controller.rb +4 -0
  113. data/test/dummy/app/helpers/application_helper.rb +2 -0
  114. data/test/dummy/app/helpers/welcome_helper.rb +2 -0
  115. data/test/dummy/app/models/concerns/zero_oid_fix.rb +10 -0
  116. data/test/dummy/app/models/user.rb +43 -0
  117. data/test/dummy/app/views/layouts/application.haml +13 -0
  118. data/test/dummy/app/views/partials/_nav.haml +6 -0
  119. data/test/dummy/app/views/welcome/index.html.erb +2 -0
  120. data/test/dummy/bin/bundle +3 -0
  121. data/test/dummy/bin/rails +4 -0
  122. data/test/dummy/bin/rake +4 -0
  123. data/test/dummy/bin/setup +29 -0
  124. data/test/dummy/config.ru +4 -0
  125. data/test/dummy/config/application.rb +29 -0
  126. data/test/dummy/config/boot.rb +5 -0
  127. data/test/dummy/config/environment.rb +5 -0
  128. data/test/dummy/config/environments/development.rb +41 -0
  129. data/test/dummy/config/environments/production.rb +76 -0
  130. data/test/dummy/config/environments/test.rb +42 -0
  131. data/test/dummy/config/initializers/assets.rb +11 -0
  132. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  133. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  134. data/test/dummy/config/initializers/devise.rb +259 -0
  135. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  136. data/test/dummy/config/initializers/inflections.rb +16 -0
  137. data/test/dummy/config/initializers/kaminari_config.rb +10 -0
  138. data/test/dummy/config/initializers/mime_types.rb +4 -0
  139. data/test/dummy/config/initializers/mongoid_forums.rb +5 -0
  140. data/test/dummy/config/initializers/session_store.rb +3 -0
  141. data/test/dummy/config/initializers/simple_form.rb +166 -0
  142. data/test/dummy/config/initializers/wrap_parameters.rb +9 -0
  143. data/test/dummy/config/locales/devise.en.yml +60 -0
  144. data/test/dummy/config/locales/en.yml +23 -0
  145. data/test/dummy/config/locales/simple_form.en.yml +31 -0
  146. data/test/dummy/config/mongoid.yml +69 -0
  147. data/test/dummy/config/routes.rb +7 -0
  148. data/test/dummy/config/secrets.yml +22 -0
  149. data/test/dummy/lib/templates/erb/scaffold/_form.html.erb +13 -0
  150. data/test/dummy/public/404.html +67 -0
  151. data/test/dummy/public/422.html +67 -0
  152. data/test/dummy/public/500.html +66 -0
  153. data/test/dummy/public/favicon.ico +0 -0
  154. data/test/dummy/test/controllers/welcome_controller_test.rb +9 -0
  155. data/test/dummy/test/fixtures/users.yml +11 -0
  156. data/test/dummy/test/models/user_test.rb +7 -0
  157. data/test/fixtures/mongoid_forums/categories.yml +11 -0
  158. data/test/fixtures/mongoid_forums/forums.yml +11 -0
  159. data/test/fixtures/mongoid_forums/posts.yml +11 -0
  160. data/test/fixtures/mongoid_forums/ranks.yml +11 -0
  161. data/test/fixtures/mongoid_forums/topics.yml +11 -0
  162. data/test/integration/navigation_test.rb +9 -0
  163. data/test/models/mongoid_forums/category_test.rb +9 -0
  164. data/test/models/mongoid_forums/forum_test.rb +9 -0
  165. data/test/models/mongoid_forums/post_test.rb +9 -0
  166. data/test/models/mongoid_forums/rank_test.rb +9 -0
  167. data/test/models/mongoid_forums/topic_test.rb +9 -0
  168. data/test/mongoid_forums_test.rb +7 -0
  169. data/test/test_helper.rb +17 -0
  170. metadata +442 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ac7de5fe678b102b183d345d7b983856cf81f89e
4
+ data.tar.gz: 5faabb438669005167b24827c6ec1e8bd4a5d65e
5
+ SHA512:
6
+ metadata.gz: 9af4a429a661a84276968f6b7c8b835b7b144b97b5e23e11d2c371074576ed2218a8c4c82637e562763647265172ce55d472c6d9b5ab40c11c54c0b06a09782b
7
+ data.tar.gz: 743d8a79aa8cc23f30bf764a5ad9cb4528bede9f970d3679e6f3a551d038b055b58cd742efb86db24e2acad167ddb6a40d4b9b9158f92168faf013b671423989
@@ -0,0 +1,20 @@
1
+ Copyright 2015 ack43
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,35 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'MongoidForums'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+ load 'rails/tasks/statistics.rake'
20
+
21
+
22
+
23
+ Bundler::GemHelper.install_tasks
24
+
25
+ require 'rake/testtask'
26
+
27
+ Rake::TestTask.new(:test) do |t|
28
+ t.libs << 'lib'
29
+ t.libs << 'test'
30
+ t.pattern = 'test/**/*_test.rb'
31
+ t.verbose = false
32
+ end
33
+
34
+
35
+ task default: :test
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require_tree .
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,56 @@
1
+ body { background-color: #fff; color: #333; }
2
+
3
+ body, p, ol, ul, td {
4
+ font-family: verdana, arial, helvetica, sans-serif;
5
+ font-size: 13px;
6
+ line-height: 18px;
7
+ }
8
+
9
+ pre {
10
+ background-color: #eee;
11
+ padding: 10px;
12
+ font-size: 11px;
13
+ }
14
+
15
+ a { color: #000; }
16
+ a:visited { color: #666; }
17
+ a:hover { color: #fff; background-color:#000; }
18
+
19
+ div.field, div.actions {
20
+ margin-bottom: 10px;
21
+ }
22
+
23
+ #notice {
24
+ color: green;
25
+ }
26
+
27
+ .field_with_errors {
28
+ padding: 2px;
29
+ background-color: red;
30
+ display: table;
31
+ }
32
+
33
+ #error_explanation {
34
+ width: 450px;
35
+ border: 2px solid red;
36
+ padding: 7px;
37
+ padding-bottom: 0;
38
+ margin-bottom: 20px;
39
+ background-color: #f0f0f0;
40
+ }
41
+
42
+ #error_explanation h2 {
43
+ text-align: left;
44
+ font-weight: bold;
45
+ padding: 5px 5px 5px 15px;
46
+ font-size: 12px;
47
+ margin: -7px;
48
+ margin-bottom: 0px;
49
+ background-color: #c00;
50
+ color: #fff;
51
+ }
52
+
53
+ #error_explanation ul li {
54
+ font-size: 12px;
55
+ list-style: square;
56
+ }
@@ -0,0 +1,18 @@
1
+ require_dependency "mongoid_forums/application_controller"
2
+
3
+ module MongoidForums
4
+ class Admin::BaseController < ApplicationController
5
+ before_filter :authenticate_mongoid_forums_admin
6
+
7
+ def index
8
+ end
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
+
17
+ end
18
+ end
@@ -0,0 +1,83 @@
1
+ require_dependency "mongoid_forums/application_controller"
2
+
3
+ module MongoidForums
4
+ module Admin
5
+ class CategoriesController < BaseController
6
+ before_action :set_category, only: [:add_group, :remove_group]
7
+
8
+ def index
9
+ @forums = Forum.asc(:position)
10
+ @categories = Category.asc(:position)
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
+
18
+ def new
19
+ @category = Category.new
20
+ end
21
+
22
+ def create
23
+ if @category = Category.create(category_params)
24
+ flash[:notice] = t("mongoid_forums.admin.category.created")
25
+ redirect_to admin_categories_path
26
+ else
27
+ flash.now.alert = t("mongoid_forums.admin.category.not_created")
28
+ render :action => "new"
29
+ end
30
+ end
31
+
32
+ def edit
33
+ @category = Category.find(params[:id])
34
+ end
35
+
36
+ def update
37
+ @category = Category.find(params[:id])
38
+ if @category.update(category_params)
39
+ flash[:notice] = t("mongoid_forums.admin.category.updated")
40
+ redirect_to admin_categories_path
41
+ else
42
+ flash[:notice] = t("mongoid_forums.admin.category.not_updated")
43
+ render :action => "edit"
44
+ end
45
+ end
46
+
47
+ def destroy
48
+ @category = Category.find(params[:id])
49
+ @category.destroy
50
+ flash[:notice] = t("mongoid_forums.admin.category.deleted")
51
+ redirect_to admin_categories_path
52
+ end
53
+
54
+ ### Temporary Methods - Try Not To Cringe Too Much <3 ###
55
+ def add_group
56
+ group = Group.find(params[:group][:id])
57
+ @category.moderator_groups << group
58
+ @category.save
59
+
60
+ redirect_to admin_category_path(@category)
61
+ end
62
+
63
+ def remove_group
64
+ group = Group.find(params[:group][:id])
65
+ @category.moderator_groups.delete(group)
66
+ @category.save
67
+
68
+ redirect_to admin_category_path(@category)
69
+ end
70
+ #########################################################
71
+
72
+ private
73
+
74
+ def category_params
75
+ params.require(:category).permit(:name, :position)
76
+ end
77
+
78
+ def set_category
79
+ @category = Category.find(params[:category_id])
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,83 @@
1
+ require_dependency "mongoid_forums/application_controller"
2
+
3
+ module MongoidForums
4
+ module Admin
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
+
12
+ def new
13
+ @forum = Forum.new
14
+ end
15
+
16
+ def create
17
+ @forum = Forum.new(forum_params)
18
+ if @forum.save
19
+ flash[:notice] = t("mongoid_forums.admin.forum.created")
20
+ redirect_to [:admin, @forum]
21
+ else
22
+ flash.now.alert = t("mongoid_forums.admin.forum.not_created")
23
+ render :action => "new"
24
+ end
25
+ end
26
+
27
+ def show
28
+ @forum = Forum.find(params[:id])
29
+ @groups = Group.all.where(moderator: true).select{ |group| !@forum.moderator_groups.include?(group) }
30
+ end
31
+
32
+ def edit
33
+ @forum = Forum.find(params[:id])
34
+ end
35
+
36
+ def update
37
+ @forum = Forum.find(params[:id])
38
+ if @forum.update(forum_params)
39
+ flash[:notice] = t("mongoid_forums.admin.forum.updated")
40
+ redirect_to @forum
41
+ else
42
+ flash.now.alert = t("mongoid_forums.admin.forum.not_updated")
43
+ render :action => "edit"
44
+ end
45
+ end
46
+
47
+ def destroy
48
+ @forum = Forum.find(params[:id])
49
+ @forum.destroy
50
+ flash[:notice] = t("mongoid_forums.admin.forum.deleted")
51
+ redirect_to admin_forums_path
52
+ end
53
+
54
+ ### Temporary Methods - Try Not To Cringe Too Much <3 ###
55
+ def add_group
56
+ group = Group.find(params[:group][:id])
57
+ @forum.moderator_groups << group
58
+ @forum.save
59
+
60
+ redirect_to admin_forum_path(@forum)
61
+ end
62
+
63
+ def remove_group
64
+ group = Group.find(params[:group][:id])
65
+ @forum.moderator_groups.delete(group)
66
+ @forum.save
67
+
68
+ redirect_to admin_forum_path(@forum)
69
+ end
70
+ #########################################################
71
+
72
+ private
73
+
74
+ def forum_params
75
+ params.require(:forum).permit(:name, :category, :position)
76
+ end
77
+
78
+ def set_forum
79
+ @forum = Forum.find(params[:forum_id])
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,83 @@
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
+ @group = Group.new(params.require(:group).permit(:name, :moderator, :members))
17
+ if @group.save
18
+ flash[:notice] = t("mongoid_forums.admin.group.created")
19
+ redirect_to [:admin, @group]
20
+ else
21
+ flash[:notice] = t("mongoid_forums.admin.group.not_created")
22
+ render :action => "new"
23
+ end
24
+ end
25
+
26
+ def edit
27
+ @group = Group.find(params[:id])
28
+ end
29
+
30
+ def update
31
+ @group = Group.find(params[:id])
32
+ if @group.update_attributes(params.require(:group).permit(:name, :members))
33
+ flash[:notice] = t("mongoid_forums.admin.group.updated")
34
+ redirect_to [:admin, @group]
35
+ else
36
+ flash[:notice] = t("mongoid_forums.admin.group.not_updated")
37
+ render :action => "edit"
38
+ end
39
+ end
40
+
41
+ def show
42
+ @group = Group.find(params[:id])
43
+ @group_members = @group.members.map{|member_id| User.find(member_id) }
44
+ @users = User.all.select{ |user| !@group.members.include?(user.id) }
45
+ end
46
+
47
+ def destroy
48
+ @group = Group.find(params[:id])
49
+ @group.destroy
50
+ flash[:notice] = t("mongoid_forums.admin.group.deleted")
51
+ redirect_to admin_groups_path
52
+ end
53
+
54
+ ### Temporary Methods - Try Not To Cringe Too Much <3 ###
55
+ def add_member
56
+ group = Group.find(params.require(:group_id))
57
+ user = User.find(params[:user][:id])
58
+
59
+ group.members << user.id unless group.members.include?(user.id)
60
+ group.save
61
+
62
+ redirect_to admin_group_path(group)
63
+ end
64
+
65
+ def remove_member
66
+ group = Group.find(params.require(:group_id))
67
+ user = User.find(params[:user][:id])
68
+
69
+ group.members.delete(user.id)
70
+ group.save
71
+
72
+ redirect_to admin_group_path(group)
73
+ end
74
+ #########################################################
75
+ end
76
+
77
+ private
78
+
79
+ def group_params
80
+ params.require(:group).permit(:name, :members)
81
+ end
82
+ end
83
+ end