Commit 6387c1cbaa4c6d21dd6664cf880c41dfb5924032
1 parent
22cae98b
Exists in
master
refactoring email article plugin to adapt for article_extra_toolbar_buttons refactoring
Showing
7 changed files
with
85 additions
and
537 deletions
Show diff stats
controllers/email_article_plugin_myprofile_controller.rb
@@ -3,18 +3,6 @@ class EmailArticlePluginMyprofileController < MyProfileController | @@ -3,18 +3,6 @@ class EmailArticlePluginMyprofileController < MyProfileController | ||
3 | 3 | ||
4 | needs_profile | 4 | needs_profile |
5 | 5 | ||
6 | - | ||
7 | - # def send_email | ||
8 | - # if user.is_admin?(profile) | ||
9 | - # article = profile.articles.find(params[:id]) | ||
10 | - # #EmailArticlePluginMyprofileController::Sender.content(article).deliver | ||
11 | - # Sender.content(article) | ||
12 | - # render :text => "Email sent to queue" | ||
13 | - # else | ||
14 | - # render :status => :forbidden, :text => "Forbidden user" | ||
15 | - # end | ||
16 | - # end | ||
17 | - | ||
18 | def send_email | 6 | def send_email |
19 | unless user.is_admin?(profile) | 7 | unless user.is_admin?(profile) |
20 | render :status => :forbidden, :text => "Forbidden user" | 8 | render :status => :forbidden, :text => "Forbidden user" |
@@ -36,398 +24,4 @@ class EmailArticlePluginMyprofileController < MyProfileController | @@ -36,398 +24,4 @@ class EmailArticlePluginMyprofileController < MyProfileController | ||
36 | # end | 24 | # end |
37 | end | 25 | end |
38 | 26 | ||
39 | - # before_filter :check_access_to_profile, :except => [:join, :join_not_logged, :index, :add] | ||
40 | - # before_filter :store_location, :only => [:join, :join_not_logged, :report_abuse, :send_mail] | ||
41 | - # before_filter :login_required, :only => [:add, :join, :leave, :unblock, :leave_scrap, :remove_scrap, :remove_activity, :view_more_activities, :view_more_network_activities, :report_abuse, :register_report, :leave_comment_on_activity, :send_mail] | ||
42 | - # | ||
43 | - # helper TagsHelper | ||
44 | - # | ||
45 | - # protect 'send_mail_to_members', :profile, :only => [:send_mail] | ||
46 | - # | ||
47 | - # def index | ||
48 | - # @network_activities = !@profile.is_a?(Person) ? @profile.tracked_notifications.visible.paginate(:per_page => 15, :page => params[:page]) : [] | ||
49 | - # if logged_in? && current_person.follows?(@profile) | ||
50 | - # @network_activities = @profile.tracked_notifications.visible.paginate(:per_page => 15, :page => params[:page]) if @network_activities.empty? | ||
51 | - # @activities = @profile.activities.paginate(:per_page => 15, :page => params[:page]) | ||
52 | - # end | ||
53 | - # @tags = profile.article_tags | ||
54 | - # allow_access_to_page | ||
55 | - # end | ||
56 | - # | ||
57 | - # def tags | ||
58 | - # @tags_cache_key = "tags_profile_#{profile.id.to_s}" | ||
59 | - # if is_cache_expired?(@tags_cache_key) | ||
60 | - # @tags = profile.article_tags | ||
61 | - # end | ||
62 | - # end | ||
63 | - # | ||
64 | - # def content_tagged | ||
65 | - # @tag = params[:id] | ||
66 | - # @tag_cache_key = "tag_#{CGI.escape(@tag.to_s)}_#{profile.id.to_s}_page_#{params[:npage]}" | ||
67 | - # if is_cache_expired?(@tag_cache_key) | ||
68 | - # @tagged = profile.tagged_with(@tag).paginate(:per_page => 20, :page => params[:npage]) | ||
69 | - # end | ||
70 | - # end | ||
71 | - # | ||
72 | - # def tag_feed | ||
73 | - # @tag = params[:id] | ||
74 | - # tagged = profile.articles.paginate(:per_page => 20, :page => 1, :order => 'published_at DESC', :include => :tags, :conditions => ['tags.name LIKE ?', @tag]) | ||
75 | - # feed_writer = FeedWriter.new | ||
76 | - # data = feed_writer.write( | ||
77 | - # tagged, | ||
78 | - # :title => _("%s's contents tagged with \"%s\"") % [profile.name, @tag], | ||
79 | - # :description => _("%s's contents tagged with \"%s\"") % [profile.name, @tag], | ||
80 | - # :link => url_for(profile.url) | ||
81 | - # ) | ||
82 | - # render :text => data, :content_type => "text/xml" | ||
83 | - # end | ||
84 | - # | ||
85 | - # def communities | ||
86 | - # if is_cache_expired?(profile.communities_cache_key(params)) | ||
87 | - # @communities = profile.communities.includes(relations_to_include).paginate(:per_page => per_page, :page => params[:npage], :total_entries => profile.communities.count) | ||
88 | - # end | ||
89 | - # end | ||
90 | - # | ||
91 | - # def enterprises | ||
92 | - # @enterprises = profile.enterprises.includes(relations_to_include) | ||
93 | - # end | ||
94 | - # | ||
95 | - # def friends | ||
96 | - # if is_cache_expired?(profile.friends_cache_key(params)) | ||
97 | - # @friends = profile.friends.includes(relations_to_include).paginate(:per_page => per_page, :page => params[:npage], :total_entries => profile.friends.count) | ||
98 | - # end | ||
99 | - # end | ||
100 | - # | ||
101 | - # def members | ||
102 | - # if is_cache_expired?(profile.members_cache_key(params)) | ||
103 | - # @members = profile.members_by_name.includes(relations_to_include).paginate(:per_page => members_per_page, :page => params[:npage], :total_entries => profile.members.count) | ||
104 | - # end | ||
105 | - # end | ||
106 | - # | ||
107 | - # def fans | ||
108 | - # @fans = profile.fans.includes(relations_to_include) | ||
109 | - # end | ||
110 | - # | ||
111 | - # def favorite_enterprises | ||
112 | - # @favorite_enterprises = profile.favorite_enterprises.includes(relations_to_include) | ||
113 | - # end | ||
114 | - # | ||
115 | - # def sitemap | ||
116 | - # @articles = profile.top_level_articles.includes([:profile, :parent]) | ||
117 | - # end | ||
118 | - # | ||
119 | - # def join | ||
120 | - # if !user.memberships.include?(profile) | ||
121 | - # profile.add_member(user) | ||
122 | - # if !profile.members.include?(user) | ||
123 | - # render :text => {:message => _('%s administrator still needs to accept you as member.') % profile.name}.to_json | ||
124 | - # else | ||
125 | - # render :text => {:message => _('You just became a member of %s.') % profile.name}.to_json | ||
126 | - # end | ||
127 | - # else | ||
128 | - # render :text => {:message => _('You are already a member of %s.') % profile.name}.to_json | ||
129 | - # end | ||
130 | - # end | ||
131 | - # | ||
132 | - # def join_not_logged | ||
133 | - # session[:join] = profile.identifier | ||
134 | - # | ||
135 | - # if user | ||
136 | - # redirect_to :controller => 'profile', :action => 'join' | ||
137 | - # else | ||
138 | - # redirect_to :controller => '/account', :action => 'login' | ||
139 | - # end | ||
140 | - # end | ||
141 | - # | ||
142 | - # def leave | ||
143 | - # if current_person.memberships.include?(profile) | ||
144 | - # if current_person.is_last_admin?(profile) | ||
145 | - # render :text => {:redirect_to => url_for({:controller => 'profile_members', :action => 'last_admin', :person => current_person.id})}.to_json | ||
146 | - # else | ||
147 | - # render :text => current_person.leave(profile, params[:reload]) | ||
148 | - # end | ||
149 | - # else | ||
150 | - # render :text => {:message => _('You are not a member of %s.') % profile.name}.to_json | ||
151 | - # end | ||
152 | - # end | ||
153 | - # | ||
154 | - # def check_membership | ||
155 | - # unless logged_in? | ||
156 | - # render :text => '' | ||
157 | - # return | ||
158 | - # end | ||
159 | - # if user.memberships.include?(profile) | ||
160 | - # render :text => 'true' | ||
161 | - # else | ||
162 | - # render :text => 'false' | ||
163 | - # end | ||
164 | - # end | ||
165 | - # | ||
166 | - # def add | ||
167 | - # # FIXME this shouldn't be in Person model? | ||
168 | - # if !user.memberships.include?(profile) | ||
169 | - # AddFriend.create!(:person => user, :friend => profile) | ||
170 | - # render :text => _('%s still needs to accept being your friend.') % profile.name | ||
171 | - # else | ||
172 | - # render :text => _('You are already a friend of %s.') % profile.name | ||
173 | - # end | ||
174 | - # end | ||
175 | - # | ||
176 | - # def check_friendship | ||
177 | - # unless logged_in? | ||
178 | - # render :text => '' | ||
179 | - # return | ||
180 | - # end | ||
181 | - # if user == profile || user.already_request_friendship?(profile) || user.is_a_friend?(profile) | ||
182 | - # render :text => 'true' | ||
183 | - # else | ||
184 | - # render :text => 'false' | ||
185 | - # end | ||
186 | - # end | ||
187 | - # | ||
188 | - # def unblock | ||
189 | - # if current_user.person.is_admin?(profile.environment) | ||
190 | - # profile.unblock | ||
191 | - # session[:notice] = _("You have unblocked %s successfully. ") % profile.name | ||
192 | - # redirect_to :controller => 'profile', :action => 'index' | ||
193 | - # else | ||
194 | - # message = _('You are not allowed to unblock enterprises in this environment.') | ||
195 | - # render_access_denied(message) | ||
196 | - # end | ||
197 | - # end | ||
198 | - # | ||
199 | - # def leave_scrap | ||
200 | - # sender = params[:sender_id].nil? ? current_user.person : Person.find(params[:sender_id]) | ||
201 | - # receiver = params[:receiver_id].nil? ? @profile : Person.find(params[:receiver_id]) | ||
202 | - # @scrap = Scrap.new(params[:scrap]) | ||
203 | - # @scrap.sender= sender | ||
204 | - # @scrap.receiver= receiver | ||
205 | - # @tab_action = params[:tab_action] | ||
206 | - # @message = @scrap.save ? _("Message successfully sent.") : _("You can't leave an empty message.") | ||
207 | - # activities = @profile.activities.paginate(:per_page => 15, :page => params[:page]) if params[:not_load_scraps].nil? | ||
208 | - # render :partial => 'profile_activities_list', :locals => {:activities => activities} | ||
209 | - # end | ||
210 | - # | ||
211 | - # def leave_comment_on_activity | ||
212 | - # @comment = Comment.new(params[:comment]) | ||
213 | - # @comment.author = user | ||
214 | - # @activity = ActionTracker::Record.find(params[:source_id]) | ||
215 | - # @comment.source_type, @comment.source_id = (@activity.target_type == 'Article' ? ['Article', @activity.target_id] : [@activity.class.to_s, @activity.id]) | ||
216 | - # @tab_action = params[:tab_action] | ||
217 | - # @message = @comment.save ? _("Comment successfully added.") : _("You can't leave an empty comment.") | ||
218 | - # if @tab_action == 'wall' | ||
219 | - # activities = @profile.activities.paginate(:per_page => 15, :page => params[:page]) if params[:not_load_scraps].nil? | ||
220 | - # render :partial => 'profile_activities_list', :locals => {:activities => activities} | ||
221 | - # else | ||
222 | - # network_activities = @profile.tracked_notifications.visible.paginate(:per_page => 15, :page => params[:page]) | ||
223 | - # render :partial => 'profile_network_activities', :locals => {:network_activities => network_activities} | ||
224 | - # end | ||
225 | - # end | ||
226 | - # | ||
227 | - # def view_more_activities | ||
228 | - # @activities = @profile.activities.paginate(:per_page => 10, :page => params[:page]) | ||
229 | - # render :partial => 'profile_activities_list', :locals => {:activities => @activities} | ||
230 | - # end | ||
231 | - # | ||
232 | - # def view_more_network_activities | ||
233 | - # @activities = @profile.tracked_notifications.paginate(:per_page => 10, :page => params[:page]) | ||
234 | - # render :partial => 'profile_network_activities', :locals => {:network_activities => @activities} | ||
235 | - # end | ||
236 | - # | ||
237 | - # def more_comments | ||
238 | - # profile_filter = @profile.person? ? {:user_id => @profile} : {:target_id => @profile} | ||
239 | - # activity = ActionTracker::Record.find(:first, :conditions => {:id => params[:activity]}.merge(profile_filter)) | ||
240 | - # comments_count = activity.comments.count | ||
241 | - # comment_page = (params[:comment_page] || 1).to_i | ||
242 | - # comments_per_page = 5 | ||
243 | - # no_more_pages = comments_count <= comment_page * comments_per_page | ||
244 | - # | ||
245 | - # render :update do |page| | ||
246 | - # page.insert_html :bottom, 'profile-wall-activities-comments-'+params[:activity], | ||
247 | - # :partial => 'comment', :collection => activity.comments.flatten.paginate(:per_page => comments_per_page, :page => comment_page) | ||
248 | - # | ||
249 | - # if no_more_pages | ||
250 | - # page.remove 'profile-wall-activities-comments-more-'+params[:activity] | ||
251 | - # else | ||
252 | - # page.replace_html 'profile-wall-activities-comments-more-'+params[:activity], | ||
253 | - # :partial => 'more_comments', :locals => {:activity => activity, :comment_page => comment_page} | ||
254 | - # end | ||
255 | - # end | ||
256 | - # end | ||
257 | - # | ||
258 | - # def more_replies | ||
259 | - # activity = Scrap.find(:first, :conditions => {:id => params[:activity], :receiver_id => @profile, :scrap_id => nil}) | ||
260 | - # comments_count = activity.replies.count | ||
261 | - # comment_page = (params[:comment_page] || 1).to_i | ||
262 | - # comments_per_page = 5 | ||
263 | - # no_more_pages = comments_count <= comment_page * comments_per_page | ||
264 | - # | ||
265 | - # render :update do |page| | ||
266 | - # page.insert_html :bottom, 'profile-wall-activities-comments-'+params[:activity], | ||
267 | - # :partial => 'profile_scrap', :collection => activity.replies.paginate(:per_page => comments_per_page, :page => comment_page), :as => :scrap | ||
268 | - # | ||
269 | - # if no_more_pages | ||
270 | - # page.remove 'profile-wall-activities-comments-more-'+params[:activity] | ||
271 | - # else | ||
272 | - # page.replace_html 'profile-wall-activities-comments-more-'+params[:activity], | ||
273 | - # :partial => 'more_replies', :locals => {:activity => activity, :comment_page => comment_page} | ||
274 | - # end | ||
275 | - # end | ||
276 | - # end | ||
277 | - # | ||
278 | - # def remove_scrap | ||
279 | - # begin | ||
280 | - # scrap = current_user.person.scraps(params[:scrap_id]) | ||
281 | - # scrap.destroy | ||
282 | - # finish_successful_removal 'Scrap successfully removed.' | ||
283 | - # rescue | ||
284 | - # finish_unsuccessful_removal 'You could not remove this scrap.' | ||
285 | - # end | ||
286 | - # end | ||
287 | - # | ||
288 | - # def remove_activity | ||
289 | - # begin | ||
290 | - # raise if !can_edit_profile | ||
291 | - # activity = ActionTracker::Record.find(params[:activity_id]) | ||
292 | - # if params[:only_hide] | ||
293 | - # activity.update_attribute(:visible, false) | ||
294 | - # else | ||
295 | - # activity.destroy | ||
296 | - # end | ||
297 | - # finish_successful_removal 'Activity successfully removed.' | ||
298 | - # rescue | ||
299 | - # finish_unsuccessful_removal 'You could not remove this activity.' | ||
300 | - # end | ||
301 | - # end | ||
302 | - # | ||
303 | - # def remove_notification | ||
304 | - # begin | ||
305 | - # raise if !can_edit_profile | ||
306 | - # notification = ActionTrackerNotification.find(:first, :conditions => {:profile_id => profile.id, :action_tracker_id => params[:activity_id]}) | ||
307 | - # notification.destroy | ||
308 | - # render :text => _('Notification successfully removed.') | ||
309 | - # rescue | ||
310 | - # render :text => _('You could not remove this notification.') | ||
311 | - # end | ||
312 | - # end | ||
313 | - # | ||
314 | - # def finish_successful_removal(msg) | ||
315 | - # if request.xhr? | ||
316 | - # render :text => {'ok' => true}.to_json, :content_type => 'application/json' | ||
317 | - # else | ||
318 | - # session[:notice] = _(msg) | ||
319 | - # redirect_to :action => :index | ||
320 | - # end | ||
321 | - # end | ||
322 | - # | ||
323 | - # def finish_unsuccessful_removal(msg) | ||
324 | - # session[:notice] = _(msg) | ||
325 | - # if request.xhr? | ||
326 | - # render :text => {'redirect' => url_for(:action => :index)}.to_json, :content_type => 'application/json' | ||
327 | - # else | ||
328 | - # redirect_to :action => :index | ||
329 | - # end | ||
330 | - # end | ||
331 | - # | ||
332 | - # def report_abuse | ||
333 | - # @abuse_report = AbuseReport.new | ||
334 | - # render :layout => false | ||
335 | - # end | ||
336 | - # | ||
337 | - # def register_report | ||
338 | - # unless user.is_admin? || verify_recaptcha | ||
339 | - # render :text => { | ||
340 | - # :ok => false, | ||
341 | - # :error => { | ||
342 | - # :code => 1, | ||
343 | - # :message => _('You could not answer the captcha.') | ||
344 | - # } | ||
345 | - # }.to_json | ||
346 | - # else | ||
347 | - # begin | ||
348 | - # abuse_report = AbuseReport.new(params[:abuse_report]) | ||
349 | - # if !params[:content_type].blank? | ||
350 | - # article = params[:content_type].constantize.find(params[:content_id]) | ||
351 | - # abuse_report.content = article_reported_version(article) | ||
352 | - # end | ||
353 | - # | ||
354 | - # user.register_report(abuse_report, profile) | ||
355 | - # | ||
356 | - # if !params[:content_type].blank? | ||
357 | - # abuse_report = AbuseReport.find_by_reporter_id_and_abuse_complaint_id(user.id, profile.opened_abuse_complaint.id) | ||
358 | - # Delayed::Job.enqueue DownloadReportedImagesJob.new(abuse_report, article) | ||
359 | - # end | ||
360 | - # | ||
361 | - # render :text => { | ||
362 | - # :ok => true, | ||
363 | - # :message => _('Your abuse report was registered. The administrators are reviewing your report.'), | ||
364 | - # }.to_json | ||
365 | - # rescue Exception => exception | ||
366 | - # logger.error(exception.to_s) | ||
367 | - # render :text => { | ||
368 | - # :ok => false, | ||
369 | - # :error => { | ||
370 | - # :code => 2, | ||
371 | - # :message => _('Your report couldn\'t be saved due to some problem. Please contact the administrator.') | ||
372 | - # } | ||
373 | - # }.to_json | ||
374 | - # end | ||
375 | - # end | ||
376 | - # end | ||
377 | - # | ||
378 | - # def remove_comment | ||
379 | - # #FIXME Check whether these permissions are enough | ||
380 | - # @comment = Comment.find(params[:comment_id]) | ||
381 | - # if (user == @comment.author || user == profile || user.has_permission?(:moderate_comments, profile)) | ||
382 | - # @comment.destroy | ||
383 | - # finish_successful_removal 'Comment successfully removed.' | ||
384 | - # else | ||
385 | - # finish_unsuccessful_removal 'You could not remove this comment.' | ||
386 | - # end | ||
387 | - # end | ||
388 | - | ||
389 | - | ||
390 | - | ||
391 | - | ||
392 | - # protected | ||
393 | - # | ||
394 | - # def check_access_to_profile | ||
395 | - # unless profile.display_info_to?(user) | ||
396 | - # redirect_to :action => 'index' | ||
397 | - # end | ||
398 | - # end | ||
399 | - # | ||
400 | - # def store_location | ||
401 | - # if session[:previous_location].nil? | ||
402 | - # session[:previous_location] = request.referer | ||
403 | - # end | ||
404 | - # end | ||
405 | - # | ||
406 | - # def redirect_to_previous_location | ||
407 | - # back = session[:previous_location] | ||
408 | - # if back | ||
409 | - # session[:previous_location] = nil | ||
410 | - # redirect_to back | ||
411 | - # else | ||
412 | - # redirect_to profile.url | ||
413 | - # end | ||
414 | - # end | ||
415 | - # | ||
416 | - # def per_page | ||
417 | - # Noosfero::Constants::PROFILE_PER_PAGE | ||
418 | - # end | ||
419 | - # | ||
420 | - # def members_per_page | ||
421 | - # 20 | ||
422 | - # end | ||
423 | - # | ||
424 | - # def can_edit_profile | ||
425 | - # @can_edit_profile ||= user && user.has_permission?('edit_profile', profile) | ||
426 | - # end | ||
427 | - # helper_method :can_edit_profile | ||
428 | - # | ||
429 | - # def relations_to_include | ||
430 | - # [:image, :domains, :preferred_domain, :environment] | ||
431 | - # end | ||
432 | - | ||
433 | end | 27 | end |
controllers/email_article_plugin_myprofile_controller_old.rb
@@ -1,80 +0,0 @@ | @@ -1,80 +0,0 @@ | ||
1 | -require 'nokogiri' | ||
2 | - | ||
3 | -class EmailArticlePluginMyprofileController < MyProfileController | ||
4 | - | ||
5 | - needs_profile | ||
6 | - | ||
7 | - def send_email | ||
8 | - if user.is_admin?(profile) | ||
9 | - article = profile.articles.find(params[:id]) | ||
10 | - #EmailArticlePluginMyprofileController::Sender.content(article).deliver | ||
11 | - Sender.content(article) | ||
12 | - render :text => "Email sent to queue" | ||
13 | - else | ||
14 | - render :status => :forbidden, :text => "Forbidden user" | ||
15 | - end | ||
16 | - end | ||
17 | - | ||
18 | - class Sender | ||
19 | - def self.content(article) | ||
20 | - source = article.author.user.person | ||
21 | - mail = Mailing.new | ||
22 | - mail. | ||
23 | - # mailing = create(Mailing, :source => article.author.user.person, :subject => 'Hello', :body => 'We have some news', :person => article.author.user.person) | ||
24 | - end | ||
25 | - | ||
26 | - def absolute_url? url | ||
27 | - url.start_with?('http') || url.start_with?('ftp') | ||
28 | - end | ||
29 | - end | ||
30 | - | ||
31 | - | ||
32 | - class Sender < ActionMailer::Base | ||
33 | - def content(article) | ||
34 | - doc = Nokogiri::HTML(article.body) | ||
35 | - doc.css("a").each do |link| | ||
36 | - if !link.attribute("href").nil? and !absolute_url?(link.attribute("href").value) | ||
37 | - relative_path = link.attribute("href").value | ||
38 | - if relative_path.starts_with?('/') | ||
39 | - relative_path[0]='' | ||
40 | - end | ||
41 | - link.attribute("href").value = "http://#{article.environment.default_hostname}/#{relative_path}" | ||
42 | - end | ||
43 | - end | ||
44 | - | ||
45 | - doc.css("img").each do |link| | ||
46 | - unless link.attribute("src").nil? and absolute_url?(link.attribute("src").value) | ||
47 | - relative_path = link.attribute("src").value | ||
48 | - link.attribute("src").value = "http://#{article.environment.default_hostname}/#{relative_path}" | ||
49 | - end | ||
50 | - end | ||
51 | - | ||
52 | -# link.attributes["href"].value = "http://myproxy.com/?url=#{CGI.escape link.attributes["href"].value}" | ||
53 | -# http://#{environment.default_hostname}/#{relative_path[1]} | ||
54 | - | ||
55 | - | ||
56 | - body = doc.to_html | ||
57 | - sender = Person.find(article.author_id) | ||
58 | - members = article.profile.members | ||
59 | - emails = [] | ||
60 | - members.each{ |m| | ||
61 | - emails.push(m.user.email) | ||
62 | - } | ||
63 | - | ||
64 | - # mailing = create(Mailing, :source => article.author.user.person, :subject => 'Hello', :body => 'We have some news', :person => article.author.user.person) | ||
65 | - | ||
66 | - mail( | ||
67 | - content_type: 'text/html', | ||
68 | - to: emails, | ||
69 | - from: "#{article.author_name} <#{sender.contact_email}>", | ||
70 | - reply_to: article.author.user.email, | ||
71 | - subject: "[Artigo] " + article.title, | ||
72 | - body: body | ||
73 | -# body: set_absolute_path(article.body, article.environment) | ||
74 | - ) | ||
75 | - end | ||
76 | -end | ||
77 | - | ||
78 | - | ||
79 | - | ||
80 | -end |
lib/email_article_plugin.rb
@@ -8,25 +8,13 @@ class EmailArticlePlugin < Noosfero::Plugin | @@ -8,25 +8,13 @@ class EmailArticlePlugin < Noosfero::Plugin | ||
8 | _("A plugin that emails an article to the members of the community") | 8 | _("A plugin that emails an article to the members of the community") |
9 | end | 9 | end |
10 | 10 | ||
11 | - def article_toolbar_extra_buttons | ||
12 | - label = _("Send article to members") | ||
13 | - htmlclass = _("button with-text icon-menu-mail") | ||
14 | - title = _("Email article to all community members") | ||
15 | - proc do | ||
16 | - if !profile.blank? and !user.blank? and user.is_admin?(profile) and @page.kind_of?(TextArticle) | ||
17 | - link_to_remote( | ||
18 | - label, | ||
19 | - { | ||
20 | - :url => { :profile => profile.identifier, :controller => 'email_article_plugin_myprofile', :action => "send_email", :id => @page}, | ||
21 | - :method => :get, | ||
22 | - :success => "display_notice('" + _("Messages are being sent") + "')", | ||
23 | - :failure => "display_notice('" + _("Error sending emails") + "')", | ||
24 | - :confirm => _("Are you sure you want to email this article to all community members?"), | ||
25 | - }, | ||
26 | - :class => htmlclass, | ||
27 | - :title => title | ||
28 | - ) | ||
29 | - end | ||
30 | - end | 11 | + def article_extra_toolbar_buttons(article) |
12 | +#raise current_person.identifier.inspect + " " + profile.identifier.inspect + ' ' + current_person.is_admin?.inspect + " " + article.kind_of?(TextArticle).inspect + " " + profile.admins.include?(current_person).inspect | ||
13 | + return [] if !(profile.admins.include?(current_person) || current_person.is_admin?) || !article.kind_of?(TextArticle) | ||
14 | + { | ||
15 | + :icon => 'icon-menu-mail', | ||
16 | + :url => { :profile => profile.identifier, :controller => 'email_article_plugin_myprofile', :action => "send_email", :id => article}, | ||
17 | + :title => _("Send article to members") | ||
18 | + } | ||
31 | end | 19 | end |
32 | end | 20 | end |
test/functional/email_article_plugin_myprofile_controller_test.rb
@@ -32,7 +32,7 @@ class EmailArticlePluginMyprofileControllerTest < ActionController::TestCase | @@ -32,7 +32,7 @@ class EmailArticlePluginMyprofileControllerTest < ActionController::TestCase | ||
32 | assert_response 403 | 32 | assert_response 403 |
33 | end | 33 | end |
34 | 34 | ||
35 | - should 'show button at article_toolbar_extra_buttons' do | 35 | + should 'show button at article_extra_toolbar_buttons' do |
36 | @profile = Community.create!(:name => 'Another community', :identifier => 'another-community') | 36 | @profile = Community.create!(:name => 'Another community', :identifier => 'another-community') |
37 | @user = create_user('user-out-of-the-community') | 37 | @user = create_user('user-out-of-the-community') |
38 | login_as(@user.login) | 38 | login_as(@user.login) |
@@ -43,7 +43,7 @@ class EmailArticlePluginMyprofileControllerTest < ActionController::TestCase | @@ -43,7 +43,7 @@ class EmailArticlePluginMyprofileControllerTest < ActionController::TestCase | ||
43 | @article.save | 43 | @article.save |
44 | @plugin = EmailArticlePlugin.new | 44 | @plugin = EmailArticlePlugin.new |
45 | @plugin.stubs(:link_to_remote).returns(true) | 45 | @plugin.stubs(:link_to_remote).returns(true) |
46 | - send_mail_button = @plugin.article_toolbar_extra_buttons | 46 | + send_mail_button = @plugin.article_extra_toolbar_buttons(@article) |
47 | self.stubs(:profile).returns(@profile) | 47 | self.stubs(:profile).returns(@profile) |
48 | self.stubs(:user).returns(@user) | 48 | self.stubs(:user).returns(@user) |
49 | # self.stubs(:page).returns(@article) | 49 | # self.stubs(:page).returns(@article) |
test/unit/email_article_plugin_test.rb
@@ -3,9 +3,17 @@ require File.dirname(__FILE__) + '/../test_helper' | @@ -3,9 +3,17 @@ require File.dirname(__FILE__) + '/../test_helper' | ||
3 | class EmailArticlePluginTest < ActiveSupport::TestCase | 3 | class EmailArticlePluginTest < ActiveSupport::TestCase |
4 | 4 | ||
5 | def setup | 5 | def setup |
6 | - @plugin = EmailArticlePlugin.new | 6 | + @environment = Environment.default |
7 | + @user = create_user('testuser').person | ||
8 | + @profile = fast_create(Profile) | ||
9 | + context = mock() | ||
10 | + context.stubs(:current_person).returns(@user) | ||
11 | + context.stubs(:profile).returns(@profile) | ||
12 | + @plugin = EmailArticlePlugin.new(context) | ||
7 | end | 13 | end |
8 | 14 | ||
15 | + attr_accessor :plugin, :profile, :user, :environment | ||
16 | + | ||
9 | should 'be a noosfero plugin' do | 17 | should 'be a noosfero plugin' do |
10 | assert_kind_of Noosfero::Plugin, @plugin | 18 | assert_kind_of Noosfero::Plugin, @plugin |
11 | end | 19 | end |
@@ -18,4 +26,70 @@ class EmailArticlePluginTest < ActiveSupport::TestCase | @@ -18,4 +26,70 @@ class EmailArticlePluginTest < ActiveSupport::TestCase | ||
18 | assert_equal _("A plugin that emails an article to the members of the community"), EmailArticlePlugin.plugin_description | 26 | assert_equal _("A plugin that emails an article to the members of the community"), EmailArticlePlugin.plugin_description |
19 | end | 27 | end |
20 | 28 | ||
29 | + should 'display button to send email for all members of a community if the user is a community admin' do | ||
30 | + profile.add_admin(user) | ||
31 | + article = fast_create(TextArticle, :profile_id => profile.id) | ||
32 | + assert_not_equal [], plugin.article_extra_toolbar_buttons(article) | ||
33 | + end | ||
34 | + | ||
35 | + should 'display button to send email for all members of a community if the user is an environment administrator' do | ||
36 | +# profile.add_admin(user) | ||
37 | + environment.add_admin(user) | ||
38 | + article = fast_create(TextArticle, :profile_id => profile.id) | ||
39 | + assert_not_equal [], plugin.article_extra_toolbar_buttons(article) | ||
40 | + end | ||
41 | + | ||
42 | + should 'the title be Send article to members' do | ||
43 | + profile.add_admin(user) | ||
44 | + article = fast_create(TextArticle, :profile_id => profile.id) | ||
45 | + assert_equal 'Send article to members', plugin.article_extra_toolbar_buttons(article)[:title] | ||
46 | + end | ||
47 | + | ||
48 | + should 'the icon be icon-menu-mail' do | ||
49 | + profile.add_admin(user) | ||
50 | + article = fast_create(TextArticle, :profile_id => profile.id) | ||
51 | + assert_equal 'icon-menu-mail', plugin.article_extra_toolbar_buttons(article)[:icon] | ||
52 | + end | ||
53 | + | ||
54 | + should 'not display button to send email for members if the user is not a community admin' do | ||
55 | + article = fast_create(TextArticle, :profile_id => profile.id) | ||
56 | + assert_equal [], plugin.article_extra_toolbar_buttons(article) | ||
57 | + end | ||
58 | + | ||
59 | + should 'not display button to send email for members if the article is a Blog' do | ||
60 | + profile.add_admin(user) | ||
61 | + article = fast_create(Blog, :profile_id => profile.id) | ||
62 | + assert_equal [], plugin.article_extra_toolbar_buttons(article) | ||
63 | + end | ||
64 | + | ||
65 | + should 'not display button to send email for members if the article is a Folder' do | ||
66 | + profile.add_admin(user) | ||
67 | + article = fast_create(Folder, :profile_id => profile.id) | ||
68 | + assert_equal [], plugin.article_extra_toolbar_buttons(article) | ||
69 | + end | ||
70 | + | ||
71 | + should 'not display button to send email for members if the article is a UploadedFile' do | ||
72 | + profile.add_admin(user) | ||
73 | + article = fast_create(UploadedFile, :profile_id => profile.id) | ||
74 | + assert_equal [], plugin.article_extra_toolbar_buttons(article) | ||
75 | + end | ||
76 | + | ||
77 | + should 'display button to send email for members if the article is a TextArticle' do | ||
78 | + profile.add_admin(user) | ||
79 | + article = fast_create(TextArticle, :profile_id => profile.id) | ||
80 | + assert_not_equal [], plugin.article_extra_toolbar_buttons(article) | ||
81 | + end | ||
82 | + | ||
83 | + should 'display button to send email for members if the article is a TextileArticle' do | ||
84 | + profile.add_admin(user) | ||
85 | + article = fast_create(TextileArticle, :profile_id => profile.id) | ||
86 | + assert_not_equal [], plugin.article_extra_toolbar_buttons(article) | ||
87 | + end | ||
88 | + | ||
89 | + should 'display button to send email for members if the article is a TinyMceArticle' do | ||
90 | + profile.add_admin(user) | ||
91 | + article = fast_create(TinyMceArticle, :profile_id => profile.id) | ||
92 | + assert_not_equal [], plugin.article_extra_toolbar_buttons(article) | ||
93 | + end | ||
94 | + | ||
21 | end | 95 | end |
test/unit/test_email_article_article_mailer.rb
@@ -1,21 +0,0 @@ | @@ -1,21 +0,0 @@ | ||
1 | -require File.dirname(__FILE__) + '/../test_helper' | ||
2 | - | ||
3 | -class EmailArticlePluginTest < ActiveSupport::TestCase | ||
4 | - | ||
5 | - def setup | ||
6 | - @plugin = EmailArticlePlugin.new | ||
7 | - end | ||
8 | - | ||
9 | - should 'be a noosfero plugin' do | ||
10 | - assert_kind_of Noosfero::Plugin, @plugin | ||
11 | - end | ||
12 | - | ||
13 | - should 'have name' do | ||
14 | - assert_equal 'Email Article to Community Members Plugin', EmailArticlePlugin.plugin_name | ||
15 | - end | ||
16 | - | ||
17 | - should 'have description' do | ||
18 | - assert_equal _("A plugin that emails an article to the members of the community"), EmailArticlePlugin.plugin_description | ||
19 | - end | ||
20 | - | ||
21 | -end |
test/unit/test_email_article_plugin_article_mailer.rb
@@ -69,13 +69,6 @@ class EmailArticlePluginArticleMailerTest < ActiveSupport::TestCase | @@ -69,13 +69,6 @@ class EmailArticlePluginArticleMailerTest < ActiveSupport::TestCase | ||
69 | assert_equal "#{community.environment.top_url}/#{community.name.to_slug}/", mailing.url | 69 | assert_equal "#{community.environment.top_url}/#{community.name.to_slug}/", mailing.url |
70 | end | 70 | end |
71 | 71 | ||
72 | - should 'deliver mailing to each member after create' do | ||
73 | - mailing = create(OrganizationMailing, :source => community, :subject => 'Hello', :body => 'We have some news', :person => person) | ||
74 | - community.reload | ||
75 | - process_delayed_job_queue | ||
76 | - assert_equal 2, ActionMailer::Base.deliveries.count | ||
77 | - end | ||
78 | - | ||
79 | should 'deliver mailing when there are many mailings created' do | 72 | should 'deliver mailing when there are many mailings created' do |
80 | 50.times { create(OrganizationMailing, :source => community, :subject => 'Hello', :body => 'We have some news', :person => person) } | 73 | 50.times { create(OrganizationMailing, :source => community, :subject => 'Hello', :body => 'We have some news', :person => person) } |
81 | community.reload | 74 | community.reload |