Class: Xforum::PeopleList
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Xforum::PeopleList
- Defined in:
- app/models/xforum/people_list.rb
Class Method Summary collapse
- .add_to_invitation(params, id, user_id) ⇒ Object
- .add_to_list(params, users) ⇒ Object
- .check_invitation(name, id, user_id, list_type) ⇒ Object
-
.check_people(params) ⇒ Object
owner_id,user_id,list).
- .check_restrictions(blist, user, list_type) ⇒ Object
- .find_people_list(params, forum_id) ⇒ Object
- .get_a_list(params, current_user) ⇒ Object
- .get_forum_emails(params, user) ⇒ Object
- .get_forum_people_lists(params, user) ⇒ Object
- .get_forum_users(params, user) ⇒ Object
- .get_people_id_list(user_id, list) ⇒ Object
- .get_this_list(user, params) ⇒ Object
- .get_voter_list(params) ⇒ Object
- .get_which_owner(params) ⇒ Object
- .is_a_moderator?(user_id) ⇒ Boolean
- .make_a_list(params) ⇒ Object
- .make_invitation(params, forum_id, user) ⇒ Object
- .manage_list(params, user_ids) ⇒ Object
Instance Method Summary collapse
Class Method Details
.add_to_invitation(params, id, user_id) ⇒ Object
220 221 222 223 |
# File 'app/models/xforum/people_list.rb', line 220 def self.add_to_invitation(params, id, user_id) peoplelist = PeopleList.find_people_list(params, id) peoplelist.invite_these_guys(PeopleList.get_people_id_list(user_id,params[:invitees])) unless peoplelist.nil? end |
.add_to_list(params, users) ⇒ Object
198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'app/models/xforum/people_list.rb', line 198 def self.add_to_list(params,users) if params[:name].nil? a_list=PeopleList.where(list: params[:list], owner_id: params[:owner]).first_or_create { |new| new.list=params[:list] new.owner_id=params[:owner] } else a_list=PeopleList.where(list: 'distribution', name: params[:list]).first_or_create { |new| new.list = 'distribution' new.name = params[:list] } end a_list.invite_these_guys(users) end |
.check_invitation(name, id, user_id, list_type) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'app/models/xforum/people_list.rb', line 132 def self.check_invitation(name,id,user_id,list_type) case list_type when 'topic' people_list=PeopleList.find_by(topic_id:id,list:'invitation') when 'category', 'categories' people_list=PeopleList.find_by(category_id:id,list:'invitation') when 'forum' people_list=PeopleList.find_by(forum_id:id,list:'invitation') else nil end people_list.nil? ? false : !JSON.load(people_list.people).include?(user_id) end |
.check_people(params) ⇒ Object
owner_id,user_id,list)
213 214 215 216 217 218 |
# File 'app/models/xforum/people_list.rb', line 213 def self.check_people(params) # owner_id,user_id,list) which=PeopleList.get_which_owner(params) which.store(:list,params[:llist]) people=PeopleList.where(which).pluck(:people)[0] (people.nil? || people.empty?) ? false : people.include?(params[:user_id].to_s) end |
.check_restrictions(blist, user, list_type) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'app/models/xforum/people_list.rb', line 109 def self.check_restrictions(blist, user, list_type) alist=blist.clone #so you can do list.each and delete items blist.each { |record| skip=false case list_type when 'topic' category= Category.find_by(id:record[:category_id]) when 'category','categories' category= Category.find_by(id:record[:id]) end if !category.nil? && category.restricted if PeopleList.check_invitation(record[:name],category.id, user.id, 'category') alist.delete(record) skip=true end end unless skip alist.delete(record) if record[:restricted] && PeopleList.check_invitation(record[:name],record[:id], user.id, list_type) end } alist end |
.find_people_list(params, forum_id) ⇒ Object
225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'app/models/xforum/people_list.rb', line 225 def self.find_people_list(params, forum_id) which=PeopleList.get_which_owner(params) which.store(:list,'invitation') list = PeopleList.find_by(which) if list.nil? parent=Forum.where(id: forum_id).pluck(:parent)[0] if parent == 0 topic=Forum.where(id:forum_id).pluck(:topic_id) PeopleList.find_by(topic_id:topic,list:params[:list]) else PeopleList.find_people_list(params, parent) unless parent.nil? end end end |
.get_a_list(params, current_user) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/models/xforum/people_list.rb', line 42 def self.get_a_list(params,current_user) case params[:list] when 'forum-user-names' PeopleList.get_forum_users(params, current_user) when 'forum-user-emails' PeopleList.get_forum_emails(params, current_user) when 'forum-distribution-lists', 'forum-restricted-list' ,'forum-every-list' Rails.logger.debug 'getting list' + params[:list] PeopleList.get_forum_people_lists(params,current_user) else end end |
.get_forum_emails(params, user) ⇒ Object
65 66 67 68 69 |
# File 'app/models/xforum/people_list.rb', line 65 def self.get_forum_emails(params, user) user.forum_admin? ? alist=Xforum.user_class.all.order(:email).pluck(:email, :id) : alist= [] alist.unshift([I18n.t('xForum.select_none'), 'select none', 0]) {list_data:ForumAssist.named_array(alist, [:value, :item]), name:params[:list]} end |
.get_forum_people_lists(params, user) ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'app/models/xforum/people_list.rb', line 146 def self.get_forum_people_lists(params,user) case params[:list] when 'forum-distribution-lists' alist=PeopleList.grab({list:'distribution'},[:id,:name,:private,:people],{}) when 'forum-restricted-list' alist=PeopleList.grab({list:'invitation'},[:id,:name,:private,:people],{}) when 'forum-every-list' alist=PeopleList.grab('all',[:id,:name,:private,:people],{}) else end if user.forum_admin? if alist.nil? || alist.empty? [] else blist=alist.clone alist.each{|record| blist.delete(record) if record[:private] && !JSON.load(record[:people]).include?(user.id) } clist=[] blist.each{|record| clist.push({value:record[:name],item:record[:id]}) } clist.unshift({value:I18n.t('xForum.select_list'),item:'select list'}) {list_data:clist, id:params[:list]} end end |
.get_forum_users(params, user) ⇒ Object
100 101 102 103 104 105 106 107 |
# File 'app/models/xforum/people_list.rb', line 100 def self.get_forum_users(params, user) user.forum_admin? ? alist = Xforum.user_class.all.order(:forum_post_name).pluck(:forum_post_name, :id) : alist =[] alist.unshift([I18n.t('xForum.select_none'), 'select none', 0]) blist=alist.clone #so you can do list.each and delete items blist.each { |record| alist.delete(record) if record[0].nil? || record[0]=='' } alist {list_data: ForumAssist.named_array(alist, [:value, :item]), name: params[:list]} end |
.get_people_id_list(user_id, list) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/models/xforum/people_list.rb', line 16 def self.get_people_id_list(user_id, list) people = [] people.push(user_id) unless list.nil? list.gsub(',', ';') new_list=list.split(';') email_list=[] user_list=[] new_list.each { |entry| if entry.include?('@') email_list.push(entry) else user_list.push(entry) end } user_list.each { |entry| id=Xforum.user_class.where(forum_post_name: entry).pluck(:id)[0] people.push id unless id.nil? } email_list.each { |entry| id=Xforum.user_class.where(email: entry).pluck(:id)[0] people.push id unless id.nil? } end people end |
.get_this_list(user, params) ⇒ Object
173 174 175 176 177 |
# File 'app/models/xforum/people_list.rb', line 173 def self.get_this_list(user,params) if user.forum_admin? {list:JSON.load(PeopleList.find_by(id:params[:list_id].to_i).people)} end end |
.get_voter_list(params) ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'app/models/xforum/people_list.rb', line 70 def self.get_voter_list(params) unless params[:topic_id].nil? people_list=PeopleList.find_or_create_by(topic_id:params[:topic_id],list:'voters'){ |me| me.name=Topic.where(id:topic_id).pluck(:name)[0] +'-voters' } JSON.load(people_list.people) end end |
.get_which_owner(params) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/models/xforum/people_list.rb', line 88 def self.get_which_owner(params) if !params[:topic].nil? {topic_id:params[:topic]} elsif !params[:forum].nil? {forum_id:params[:topic]} elsif !params[:category].nil? {category_id:params[:topic]} else {} end end |
.is_a_moderator?(user_id) ⇒ Boolean
179 180 181 182 183 184 185 186 187 |
# File 'app/models/xforum/people_list.rb', line 179 def self.is_a_moderator?(user_id) the_lists=PeopleList.where(list: 'moderator').pluck(:people) moderators=[] the_lists.each { |a_list| moderators+= a_list moderators.uniq! } moderators.include?(user_id) end |
.make_a_list(params) ⇒ Object
79 80 81 82 83 84 85 86 |
# File 'app/models/xforum/people_list.rb', line 79 def self.make_a_list(params) PeopleList.first_or_create {|joe| joe.topic_id=params[:topic_id] unless params[:topic_id].nil? joe.category_id=params[:topic_id] unless params[:category_id].nil? joe.forum_id =params[:topic_id] unless params[:forum_id].nil? joe.list ='voters' } end |
.make_invitation(params, forum_id, user) ⇒ Object
189 190 191 192 193 194 195 196 |
# File 'app/models/xforum/people_list.rb', line 189 def self.make_invitation(params, forum_id, user) invitees=PeopleList.get_people_id_list(user.id, params[:invitees]) people_list=PeopleList.where(list: 'invitation', owner_id: forum_id).first_or_create { |invitation| invitation.owner_id=forum_id invitation.list='invitation' } people_list.invite_these_guys(invitees) end |
.manage_list(params, user_ids) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/models/xforum/people_list.rb', line 54 def self.manage_list(params,user_ids) case params[:forum_action] when 'create list' PeopleList.find_or_create_by(name:params[:new_list_name], list:params[:list_type]){|list| list.people=user_ids.to_json } when 'edit list' PeopleList.where(id: params[:the_list]).update_all(people: user_ids.to_json) else end end |
Instance Method Details
#invite_these_guys(invitees) ⇒ Object
240 241 242 243 244 245 |
# File 'app/models/xforum/people_list.rb', line 240 def invite_these_guys(invitees) invitees += JSON.load(self.people) unless JSON.load(self.people).nil? invitees.uniq! self.people = invitees.to_json self.save end |