skinny_forum 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/Gemfile +14 -0
  4. data/Gemfile.lock +92 -0
  5. data/MIT-LICENSE +20 -0
  6. data/README.md +29 -0
  7. data/README.rdoc +3 -0
  8. data/Rakefile +34 -0
  9. data/app/assets/images/.keep +0 -0
  10. data/app/assets/images/skinny_forum/.keep +0 -0
  11. data/app/assets/images/skinny_forum/internet.png +0 -0
  12. data/app/assets/images/skinny_forum/myphoto.jpg +0 -0
  13. data/app/assets/images/skinny_forum/silver_selector.png +0 -0
  14. data/app/assets/javascripts/skinnyforum/application.js +22 -0
  15. data/app/assets/javascripts/skinnyforum/forum_admin.js.coffee +433 -0
  16. data/app/assets/javascripts/skinnyforum/forum_basic.js.coffee +269 -0
  17. data/app/assets/javascripts/skinnyforum/forum_translator.js.coffee +113 -0
  18. data/app/assets/javascripts/skinnyforum/forum_user.js.coffee +394 -0
  19. data/app/assets/javascripts/skinnyforum/global_java.js +141 -0
  20. data/app/assets/stylesheets/skinnyforum/application.css.scss +25 -0
  21. data/app/assets/stylesheets/skinnyforum/custom.css.scss +289 -0
  22. data/app/controllers/skinnyforum/application_controller.rb +24 -0
  23. data/app/controllers/skinnyforum/forums_controller.rb +130 -0
  24. data/app/helpers/skinnyforum/application_helper.rb +4 -0
  25. data/app/mailers/.keep +0 -0
  26. data/app/mailers/skinnyforum/user_mailer.rb +13 -0
  27. data/app/models/.keep +0 -0
  28. data/app/models/skinnyforum/forum.rb +251 -0
  29. data/app/models/skinnyforum/forum_category.rb +70 -0
  30. data/app/models/skinnyforum/forum_hyperlink.rb +50 -0
  31. data/app/models/skinnyforum/forum_language.rb +86 -0
  32. data/app/models/skinnyforum/forum_people_list.rb +183 -0
  33. data/app/models/skinnyforum/forum_photo.rb +62 -0
  34. data/app/models/skinnyforum/forum_topic.rb +137 -0
  35. data/app/models/skinnyforum/forum_translation.rb +109 -0
  36. data/app/views/layouts/skinnyforum/application.html.erb +14 -0
  37. data/app/views/skinnyforum/forums/_dummy.html.erb +0 -0
  38. data/app/views/skinnyforum/forums/_forum.html.erb +107 -0
  39. data/app/views/skinnyforum/forums/_forum_admin.html.erb +133 -0
  40. data/app/views/skinnyforum/forums/newforum_photo.js.erb +1 -0
  41. data/app/views/skinnyforum/user_mailer/note_to_forum_users.html.erb +32 -0
  42. data/app_data/forum_base.csv +8 -0
  43. data/app_data/forum_help.csv +24 -0
  44. data/app_data/reset cmds +13 -0
  45. data/config/locales/skinnyforum/forum_de.yml +88 -0
  46. data/config/locales/skinnyforum/forum_en.yml +88 -0
  47. data/config/locales/skinnyforum/forum_es.yml +88 -0
  48. data/config/locales/skinnyforum/forum_fr.yml +88 -0
  49. data/config/routes.rb +2 -0
  50. data/db/migrate/20130100_add_users.rb +11 -0
  51. data/db/migrate/20140601_add_forums.rb +164 -0
  52. data/lib/skinny_forum.rb +4 -0
  53. data/lib/skinny_forum/engine.rb +5 -0
  54. data/lib/skinny_forum/forum_shared_code.rb +94 -0
  55. data/lib/skinny_forum/version.rb +3 -0
  56. data/lib/tasks/forum_tasks.rake +52 -0
  57. data/lib/tasks/skinny_forum_tasks.rake +4 -0
  58. data/skinny_forum.gemspec +28 -0
  59. data/test/dummy/README.rdoc +28 -0
  60. data/test/dummy/Rakefile +6 -0
  61. data/test/dummy/app/assets/images/.keep +0 -0
  62. data/test/dummy/app/assets/javascripts/application.js +13 -0
  63. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  64. data/test/dummy/app/controllers/application_controller.rb +5 -0
  65. data/test/dummy/app/controllers/concerns/.keep +0 -0
  66. data/test/dummy/app/helpers/application_helper.rb +2 -0
  67. data/test/dummy/app/mailers/.keep +0 -0
  68. data/test/dummy/app/models/.keep +0 -0
  69. data/test/dummy/app/models/concerns/.keep +0 -0
  70. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  71. data/test/dummy/bin/bundle +3 -0
  72. data/test/dummy/bin/rails +4 -0
  73. data/test/dummy/bin/rake +4 -0
  74. data/test/dummy/config.ru +4 -0
  75. data/test/dummy/config/application.rb +23 -0
  76. data/test/dummy/config/boot.rb +5 -0
  77. data/test/dummy/config/database.yml +25 -0
  78. data/test/dummy/config/environment.rb +5 -0
  79. data/test/dummy/config/environments/development.rb +37 -0
  80. data/test/dummy/config/environments/production.rb +83 -0
  81. data/test/dummy/config/environments/test.rb +39 -0
  82. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  83. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  84. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  85. data/test/dummy/config/initializers/inflections.rb +16 -0
  86. data/test/dummy/config/initializers/mime_types.rb +4 -0
  87. data/test/dummy/config/initializers/session_store.rb +3 -0
  88. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  89. data/test/dummy/config/locales/en.yml +23 -0
  90. data/test/dummy/config/routes.rb +4 -0
  91. data/test/dummy/config/secrets.yml +22 -0
  92. data/test/dummy/lib/assets/.keep +0 -0
  93. data/test/dummy/public/404.html +67 -0
  94. data/test/dummy/public/422.html +67 -0
  95. data/test/dummy/public/500.html +66 -0
  96. data/test/dummy/public/favicon.ico +0 -0
  97. data/test/integration/navigation_test.rb +10 -0
  98. data/test/skinny_forum_test.rb +7 -0
  99. data/test/test_helper.rb +15 -0
  100. metadata +234 -0
@@ -0,0 +1,24 @@
1
+ class ApplicationController < ActionController::Base
2
+
3
+ include ApplicationHelper
4
+ include SharedCode
5
+ before_filter :set_locale
6
+
7
+ # Prevent CSRF attacks by raising an exception.
8
+ # For APIs, you may want to use :null_session instead.
9
+ protect_from_forgery with: :exception
10
+ # Force signout to prevent CSRF attacks
11
+
12
+ def handle_unverified_request
13
+ sign_out
14
+ super
15
+ end
16
+
17
+ private
18
+ def set_locale
19
+ I18n.locale = params[:locale] if params[:locale].present?
20
+ end
21
+ def default_url_options(options = {})
22
+ {locale: I18n.locale}
23
+ end
24
+ end
@@ -0,0 +1,130 @@
1
+ #
2
+ # id :integer not null, primary key
3
+ # user_id :integer
4
+ # centurians :binary
5
+ # subscribers :binary
6
+ # topic :string(255)
7
+ # root :boolean
8
+ # index :integer
9
+ # content :text
10
+ # parent :integer
11
+ # resolution :string(255)
12
+ # state :string(255)
13
+
14
+ class ForumsController < ApplicationController
15
+ def forum_ajax
16
+ if signed_in_user?
17
+ case params[:function]
18
+ when 'get list'
19
+ case params[:list]
20
+ when 'admin actions' then
21
+ render json: Forum.get_forum_actions(params, current_user.id)
22
+ when 'admin users' then
23
+ render json: ForumPeopleList.get_forum_users(params, current_user.id)
24
+ when 'admin emails' then
25
+ render json: ForumPeopleList.get_forum_emails(params, current_user.id)
26
+ when 'admin distributions' then
27
+ render json: ForumPeopleList.get_forum_distribution_lists(current_user.id)
28
+ else
29
+ end
30
+ when 'forum admin action'
31
+ render json: Forum.do_admin_action(params, current_user.id)
32
+ when 'categories'
33
+ render json: ForumCategory.categories(params, current_user.id)
34
+ when 'post'
35
+ render json: Forum.add_comment(params, current_user.id)
36
+ when 'get forum photo'
37
+ render json: ForumPhoto.get_photo(params)
38
+ when 'add hot link'
39
+ render json:ForumHyperlink.add_one(params)
40
+ when 'get language set'
41
+ render json: ForumLanguage.languages(params)
42
+ when 'toggle language'
43
+ render json: ForumLanguage.toggle_language(params, current_user.id)
44
+ when 'get translations'
45
+ render json: ForumTranslation.get_translations(params)
46
+ when 'add to list'
47
+ case params[:list]
48
+ when 'category'
49
+ response=ForumCategory.add_category(params, current_user.id)
50
+ when 'topic'
51
+ response=ForumTopic.add_topic(params, current_user.id)
52
+ when 'langauge'
53
+ response= ForumLanguage.activate_language(params, current_user.id)
54
+ else
55
+ end
56
+ render json: response
57
+ when 'get senate'
58
+ render json: Forum.senate(params, current_user.id)
59
+ when 'get topics'
60
+ render json: ForumTopic.topics(params, current_user.id)
61
+ when 'accept', 'reject'
62
+ render json: Forum.change_state(params, current_user.id)
63
+ when 'edit forum topic'
64
+ render json: ForumTopic.edit_topic(params, current_user.id)
65
+ when 'remove forum object'
66
+ case params[:which_list]
67
+ when 'category'
68
+ response=ForumCategory.remove_object(params, current_user.id)
69
+ when 'topic'
70
+ response=ForumTopic.remove_object(params, current_user.id)
71
+ when 'language'
72
+ response=ForumLanguage.deactivate_language(params, current_user.id)
73
+ else
74
+ end
75
+ render json: response
76
+ when 'vote'
77
+ render json: {votes: ForumTopic.cast_vote(params[:topic], current_user.id, params[:vote])}
78
+ when 'add voting'
79
+ render json: ForumTopic.voting_booth?(params)
80
+ when 'subscribe'
81
+ render json: ForumTopic.subscribe(params[:topic], current_user.id)
82
+ when 'get suggestions'
83
+ case params[:ist]
84
+ when 'category'
85
+ response=ForumCategory.get_suggestions(params, current_user.id)
86
+ when 'topic'
87
+ response=ForumTopic.get_suggestions(params, current_user.id)
88
+ when 'language'
89
+ response=ForumLanguage.get_suggestions(params, current_user.id)
90
+ else
91
+ end
92
+ render json: response
93
+ when 'suggestion'
94
+ case params[:list]
95
+ when 'category'
96
+ response=ForumCategory.suggestions(params, current_user.id)
97
+ when 'topic'
98
+ response=ForumTopic.suggestions(params, current_user.id)
99
+ when 'language'
100
+ response=ForumLanguage.suggestions(params, current_user.id)
101
+ else
102
+ end
103
+ render json: response
104
+ when 'suggestion close'
105
+ case params[:list]
106
+ when 'category'
107
+ response=ForumCategory.suggestion_close(params, current_user.id)
108
+ when 'topic'
109
+ response=ForumTopic.suggestion_close(params, current_user.id)
110
+ when 'language'
111
+ response=ForumLanguage.suggestion_close(params, current_user.id)
112
+ else
113
+ end
114
+ render json: response
115
+ when 'set_the_rest'
116
+ render json: Forum.set_the_rest(params, current_user.id)
117
+ else
118
+ render json: {answer: 'what did you want'}
119
+ end
120
+ else
121
+ render json: {chill_out: 'chill_out'}
122
+ end
123
+ end
124
+
125
+ def newforum_photo
126
+ ForumPhoto.upload(params,current_user.id)
127
+ end
128
+
129
+
130
+ end
@@ -0,0 +1,4 @@
1
+ module ApplicationHelper
2
+
3
+
4
+ end
File without changes
@@ -0,0 +1,13 @@
1
+ class UserMailer < ActionMailer::Base
2
+ default from: 'bnacreationss@gmail.com'
3
+
4
+ def note_to_forum_users(params,user_ids)
5
+ emails=[]
6
+ users_ids.each{
7
+ emails.push(User.where(id:id).pluck(:email)[0])
8
+ }
9
+ #attachments["notes"] =file.read("notes")
10
+ @content=params[:body].split("\n")
11
+ mail(to: emails, subject: params[:subject])
12
+ end
13
+ end
File without changes
@@ -0,0 +1,251 @@
1
+ # == Schema Information
2
+ #
3
+ # Table name: forums
4
+ #
5
+ # id :integer not null, primary key
6
+ # user_id :integer
7
+ # forum_topic_id :integer
8
+ # owner_name :string(50) default("")
9
+ # parent :integer default(0)
10
+ # state :string(50) default("new")
11
+ # tag :integer default(-1)
12
+ # hold :boolean default(FALSE)
13
+ # content :text
14
+ # closed :boolean default(FALSE)
15
+ # response :string(255) default("none")
16
+ # restricted :boolean default(FALSE)
17
+ # needs_translating :boolean default(FALSE)
18
+ # has_photo :boolean default(FALSE)
19
+ # resolution :text
20
+ # created_at :datetime
21
+ # updated_at :datetime
22
+ #
23
+
24
+ # noinspection RubyQuotedStringsInspection
25
+ class Forum < ActiveRecord::Base
26
+ include ForumSharedCode
27
+ require 'json'
28
+ belongs_to :forum_topic
29
+ has_many :forum_translations, dependent: :destroy
30
+ has_many :forum_photos, dependent: :destroy
31
+ has_many :forum_people_lists, dependent: :destroy
32
+ has_many :forum_hyperlinks, dependent: :destroy
33
+
34
+ #todo add hyperlinks in comments
35
+
36
+ USER_BLOCK_SIZE= 300
37
+
38
+ def self.do_admin_action(params,user_id)
39
+ params[:users1]=[] if params[:users1].nil?
40
+ params[:users2]=[] if params[:users2].nil?
41
+ user_ids=(params[:users1] + params[:users2])
42
+ user_ids.uniq!
43
+ (0...user_ids.size).each{|i| user_ids[i]=user_ids[i].to_i}
44
+ user_ids.delete(0)
45
+ case params[:forum_action]
46
+ when 'suspend posting'
47
+ users_ids.each{|user| User.where(id:user).update_all(forum_posting_priviages:false)}
48
+ when 'suspend all'
49
+ users_ids.each{|user| User.where(id:user).update_all(forum_reading_priviages:false)}
50
+ users_ids.each{|user| User.where(id:user).update_all(forum_posting_priviages:false)}
51
+ when 'send email to'
52
+ UserMailer.note_to_forum_users(params,user_ids).deliver
53
+ when 'create distribution' 'add to distribution' ,'remove from distro'
54
+ ForumPeopleList.manage_list(params,user_ids)
55
+ when 'add topic monitor'
56
+ ForumTopic.add_topic_monitor(params,user_ids)
57
+ else
58
+ # type code here
59
+ end if User.forum_admin?(user_id)
60
+ {action:'nothing to do'}
61
+ end
62
+
63
+ def self.senate(params,user_id)
64
+ if params[:topic]== "select topic"
65
+ {to_do:'nothing'}
66
+ else
67
+ admin= User.forum_admin?(user_id)
68
+ topic_id=ForumTopic.where(name:params[:topic]).pluck(:id)[0]
69
+ index=Forum.clear_user_topic(user_id,topic_id)
70
+ the_list=[]
71
+ plucking= [:id, :parent, :content, :user_id,:owner_name,:state,:restricted,:tag,:has_photo]
72
+ plucking_names= [:id, :parent, :content,:owner,:owner_name,:comment_state,:restricted,:tag,:has_photo,:needs_translation,:empty_list] #we're going to append empty list to the reply
73
+ moderator=ForumPeopleList.check_people({topic:topic_id,user_id:user_id,list:'moderator'}) || admin
74
+ if params[:review]=='true' && moderator
75
+ test=Forum.where(forum_topic_id:topic_id,state:'new').pluck(:id)
76
+ unless test.empty?
77
+ item1=ForumAssist.named_array(ForumTranslation.get_localized_forum(ForumLanguage.get_me(params),{lookup:{forum_topic_id:topic_id},plucking:plucking,size:0}),plucking_names, d2=false)
78
+ item1.store(:moderator,true)
79
+ item1.store(:review,true)
80
+ new_list= ForumAssist.named_array( ForumTranslation.get_localized_forum(ForumLanguage.get_me(params),{lookup:{forum_topic_id:topic_id,state:'new'},ordering:([:topic]),plucking:plucking,size:'all'}),plucking_names , d2=true)
81
+ new_list.unshift(item1)
82
+ the_list=new_list
83
+ end
84
+ else
85
+ senate_list=ForumAssist.named_array(ForumTranslation.get_localized_forum(ForumLanguage.get_me(params),{lookup:{forum_topic_id:topic_id,hold:false},ordering:[:parent,:created_at],plucking:plucking,size:'all'}), plucking_names , d2=true)
86
+ if senate_list.empty?
87
+ []
88
+ else
89
+ voting=ForumAssist.named_array(ForumTopic.where(id:topic_id).pluck(:vote,:votes)[0],[:vote,:votes],d2=false)
90
+ voting[:vote] ? votes=ForumTopic.count_votes(voting[:votes].clone) : votes=0
91
+ parent=Forum.look_for_key(senate_list,:parent,0)
92
+ new_list=[]
93
+ subscribed=ForumPeopleList.check_people({topic:topic_id,user_id:user_id,list:'subscribers'})
94
+ parent=set_new_senate_entry(senate_list,new_list,parent,user_id, {moderator:moderator,vote:voting[:vote],votes:votes,subscribed:subscribed}) unless parent.nil?
95
+ Forum.is_child_there?(senate_list,new_list,0,parent,user_id) #push first child
96
+ new_list.delete_if {|record|
97
+ test=ForumPeopleList.check_people_list({topic:record[:id], user_id:user_id,list:'invitation'}) if (record[:restricted] && !record[:owner])
98
+ if test.nil?
99
+ case record[:state]
100
+ when 'reject' then test= false
101
+ when 'new' then test= !(ENV['FORUM_NEW_RULE']=='no')
102
+ else test=true
103
+ end
104
+ end
105
+ !test
106
+ }
107
+ the_list=new_list
108
+ end
109
+ end
110
+ {the_list:the_list,index:index}
111
+ end
112
+ end
113
+
114
+ def self.clear_user_topic(user_id,topic_id)
115
+ comments=ForumAssist.named_array(Forum.where(forum_topic_id:topic_id).order(:tag).pluck(:id,:tag),[:id,:tag],d2=true)
116
+ tags=[]
117
+ test_comments=comments.clone
118
+ test_comments.each{ |comment|
119
+ if (comment[:tag].to_i) < USER_BLOCK_SIZE*user_id && comment[:tag].to_i <= USER_BLOCK_SIZE*(user_id+1)
120
+ comments.delete_at(comments.index(comment))
121
+ else
122
+ tags.push((comment[:tag].to_i)%USER_BLOCK_SIZE )
123
+ comment[:tag]= tags.last
124
+ end
125
+ }
126
+ if tags.empty?
127
+ index=0
128
+ elsif tags.index(USER_BLOCK_SIZE*1/3).nil? && tags.index(USER_BLOCK_SIZE*2/3).nil?
129
+ index=USER_BLOCK_SIZE*1/3
130
+ elsif tags.index(USER_BLOCK_SIZE*2/3).nil?
131
+ index= USER_BLOCK_SIZE*2/3
132
+ (0...tags.size).each {|i|
133
+ Forum.where(id:comments[i][:id]).update_all(tag:-1) if tags[i] < USER_BLOCK_SIZE*1/3
134
+ }
135
+ elsif tags.index(USER_BLOCK_SIZE*0/3).nil?
136
+ index=0
137
+ (0...tags.size).each {|i|
138
+ Forum.where(id:comments[i][:id]).update_all(tag:-1) if tags[i] >= USER_BLOCK_SIZE*1/3 && tags[i]< USER_BLOCK_SIZE*2/3
139
+ }
140
+ else tags.index(USER_BLOCK_SIZE*1/3).nil?
141
+ index=USER_BLOCK_SIZE*1/3
142
+ (0...tags.size).each {|i|
143
+ Forum.where(id:comments[i][:id]).update_all(tag:-1) if tags[i] >= USER_BLOCK_SIZE*2/3
144
+ }
145
+ end
146
+ index+user_id*USER_BLOCK_SIZE
147
+ end
148
+
149
+ def self.set_new_senate_entry(senate_list,new_list,index,user_id,options)
150
+ senate_list[index].store(:photos,ForumPhoto.get_photos(senate_list[index][:id])) if senate_list[index][:has_photo]
151
+ senate_list[index].store(:hyperlinks,ForumHyperlink.get_links(senate_list[index][:id]))
152
+ senate_list[index].store(:indent,Forum.get_indent(senate_list[index][:id],0) )
153
+ senate_list[index][:owner]= senate_list[index][:owner]==user_id
154
+ senate_list[index].store(:moderator,options[:moderator]) unless options[:moderator].nil?
155
+ senate_list[index].store(:vote,options[:vote]) unless options[:vote].nil?
156
+ senate_list[index].store(:votes,options[:votes]) unless options[:votes].nil?
157
+ senate_list[index].store(:admin,options[:admin]) unless options[:admin].nil?
158
+ senate_list[index].store(:subscribed,options[:subscribed]) unless options[:subscribed].nil?
159
+
160
+ new_list.push(senate_list[index])
161
+ id=senate_list[index][:id]
162
+ senate_list.delete_at(index)
163
+ id
164
+ end
165
+
166
+ def self.get_indent(id,index)
167
+ parent=Forum.where(id:id).pluck(:parent)[0]
168
+ index=Forum.get_indent(parent,index+1) unless parent==0 || parent.nil?
169
+ index
170
+ end
171
+
172
+ def self.look_for_key(list,key,test)
173
+ index_out=nil
174
+ (list.size-1).downto(0).each { |index|
175
+ index_out=index if list[index][key]==test
176
+ } unless list.empty?
177
+ index_out
178
+ end
179
+
180
+ def self.owner(user_id,id)
181
+ Forum.where(id:id).pluck(:user_id)[0]==user_id
182
+ end
183
+
184
+ def self.add_comment(params,user_id)
185
+ topic_id=ForumTopic.where(name:params[:topic]).pluck(:id)[0]
186
+ unless params[:comment].nil? || params[:comment].empty? || !User.where(id:user_id).pluck(:forum_posting_privileges)[0]
187
+ has_photo=params[:already_has_photo] == 'true' || params[:needs_photo] == 'true'
188
+ params[:id]=Forum.where(user_id:user_id,tag:params[:tag].to_s).pluck(:id)[0] if params[:id].nil?
189
+ if params[:edit]=='true' && (user_id==Forum.where(id:params[:id]).pluck(:user_id)[0] || User.forum_admin?(user_id))
190
+ forum_id=params[:id]
191
+ Forum.where(id: params[:id]).update_all(content: params[:comment],has_photo:has_photo, parent: params[:parent],restricted:params[:restricted])
192
+ else
193
+ owner_name=User.where(id:user_id).pluck(:forum_post_name)[0]
194
+ forum_id= Forum.create(parent:params[:parent],forum_topic_id:topic_id,tag:params[:tag], has_photo:has_photo, user_id:user_id,content:params[:comment],restricted:params[:restricted],owner_name:owner_name).id
195
+ end
196
+ ForumTranslation.add_one(params,topic_id,user_id,forum_id) if params[:translating] && User.forum_translating_privileges?(user_id)
197
+ ForumPeopleList.make_invitation(params,forum_id,user_id) if params[:restricted]=='true'
198
+ ForumPeopleList.add_to_invitation(params,forum_id,user_id) unless params[:invitees].nil?
199
+ ForumHyperlink.add_set(params,forum_id) unless params[:link_ref].nil?
200
+ end
201
+ {parent:params[:parent],id:forum_id,topic_id:topic_id,tag:params[:tag],edit:params[:edit]=='true'}
202
+ end
203
+
204
+ def self.get_forum_actions(params,user_id)
205
+ alist= []
206
+ alist.push(['select action',I18n.t('forum.select_action')])
207
+ if User.forum_admin?(user_id)
208
+ alist.push(['suspend posting',I18n.t('forum.suspend_posting')])
209
+ alist.push(['suspend all',I18n.t('forum.suspend_all')])
210
+ alist.push(['send email to',I18n.t('forum.send_email_to')])
211
+ alist.push(['create distribution',I18n.t('forum.create_distribution')])
212
+ alist.push(['add to distribution',I18n.t('forum.add_to_distribution') ])
213
+ alist.push(['add topic monitor',I18n.t('forum.Add_Topic_Monitor') ])
214
+
215
+ end
216
+ {list_data:ForumAssist.named_array(alist,[:item,:value],d2=true),id:'forum-actions'}
217
+ end
218
+
219
+ def self.change_state(params,user_id)
220
+ Forum.where(id:params[:id]).update_all(state: params[:function],resolution:params[:resolution]) if ForumPeopleList.check_people({topic:params[:id], user_id:user_id,list:'moderator'}) || User.forum_admin?(user_id)
221
+ {action:'nothing to do'}
222
+ end
223
+
224
+ def self.set_the_rest(params,user_id)
225
+ topic_id=ForumTopic.where(name:params[:topic]).pluck(:id)[0]
226
+ Forum.where(forum_topic_id:topic_id, state: 'new').update_all(state: params[:state]) if ForumPeopleList.check_people({topic:topic_id,user_id:user_id,list:'moderator'}) || User.forum_admin?(user_id)
227
+ {action:'nothing to do'}
228
+ end
229
+
230
+ def self.is_child_there?(senate_list,new_list, parent,me,user_id)
231
+ child=Forum.look_for_key(senate_list,:parent,me)
232
+ unless child.nil?
233
+ child=Forum.set_new_senate_entry(senate_list, new_list, child, user_id, {})
234
+ is_child_there?(senate_list, new_list, me, child, user_id) unless senate_list.empty?
235
+ end
236
+ if me!=parent && me!=0
237
+ Forum.is_child_there?(senate_list, new_list,parent ,parent, user_id) unless senate_list.empty?
238
+ end
239
+ end
240
+
241
+ rails_admin do
242
+ list do
243
+ field :id
244
+ field :user_id
245
+ field :forum_topic_id
246
+ field :restricted
247
+ field :parent
248
+ field :state
249
+ end
250
+ end
251
+ end
@@ -0,0 +1,70 @@
1
+ # == Schema Information
2
+ #
3
+ # Table name: forum_categories
4
+ #
5
+ # id :integer not null, primary key
6
+ # user_id :integer
7
+ # name :string(50)
8
+ # state :string(50)
9
+ # suggestion :boolean
10
+ # closed :boolean default(FALSE)
11
+ # created_at :datetime
12
+ # updated_at :datetime
13
+ #
14
+
15
+ class ForumCategory < ActiveRecord::Base
16
+ include ForumSharedCode
17
+ require 'json'
18
+
19
+ has_many :forum_topics, dependent: :destroy
20
+ has_many :forum_people_lists, dependent: :destroy
21
+
22
+ def self.add_category(params,user_id)
23
+ params[:user_id]=user_id if params[:user_id] == 'me'
24
+ User.forum_admin?(user_id) ? id= ForumCategory.create(name:params[:new_item]).id : 'not happening'
25
+ {id:id}
26
+ end
27
+
28
+ def self.remove_category(params,user_id)
29
+ case(params[:state_action])
30
+ when 'del' then Forum.where(id:params[:id]).update_all(closed:true)
31
+ when 'open' then Forum.where(id:params[:id]).update_all(closed:false)
32
+ else
33
+ # type code here
34
+ end if User.forum_admin?(user_id)
35
+ {action:'nothing to do'}
36
+ end
37
+
38
+ def self.get_suggestion(params,user_id)
39
+ data= ForumCategory.where(state:'suggestion').pluck(:suggestion, :user_id,:id,:owner_name)
40
+ data=ForumAssist.named_array(data, [:suggestion, :user,:id, :owner_name], d2=true) unless data.empty?
41
+ data=Forum.add_user_name(data.clone) unless data.empty?
42
+ User.forum_admin?(user_id) ? {data: data, list: 'category-prososals-list'} : {response: 'nothing doing'}
43
+ end
44
+
45
+ def self.suggestion(params,user_id) #add new category or topic
46
+ ForumCategory.create(suggestion:true,content:params[:suggestion],user_id:user_id,hold:true)
47
+ {response:'nothing to do'}
48
+ end
49
+
50
+ def self.suggestion_close(params,user_id)
51
+ ForumCategory.where(id:params[:id]).update_all(state:'closed') if User.forum_admin?(user_id)
52
+ end
53
+
54
+ def self.categories(params,user_id)
55
+ if ForumCategory.first.nil?
56
+ ForumCategory.create(name:'request new category',closed:false)
57
+ ForumCategory.create(name:'select category',closed:false)
58
+ end
59
+ params[:hold_test]=='true' ?
60
+ category_list= ForumAssist.named_array(ForumCategory.where(closed:false).pluck(:id,:name,:closed),[:id,:name,:closed],d2=true) :
61
+ category_list= ForumAssist.named_array(ForumCategory.all.pluck(:id,:name,:closed),[:id,:name,:closed],d2=true)
62
+ category_list=ForumAssist.make_last(category_list.clone, {key: :id,ref:ForumCategory.where(name:'request new category').pluck(:id)[0]})
63
+ category_list=ForumAssist.make_first(category_list.clone,{key: :id,ref:ForumCategory.where(name:'select category').pluck(:id)[0]})
64
+ category_list=ForumPeopleList.check_restrictions(category_list.clone,user_id) if params[:restricted]=='true'
65
+ category_list=ForumTranslation.translate_list(category_list.clone,params[:language],'category')
66
+ category_list.push({id:0, item:'admin',value: I18n.t('forum.Admin_name')}) if User.forum_admin?(user_id)
67
+ {list_data:category_list,id:params[:list]}
68
+ end
69
+
70
+ end