Commit be05a8621f2f2e81e7aa24054face5e53ce9c3b0
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Merge branch 'I227-add_members_community' into stable
Showing
7 changed files
with
121 additions
and
11 deletions
Show diff stats
app/controllers/public/invite_controller.rb
@@ -62,20 +62,36 @@ class InviteController < PublicController | @@ -62,20 +62,36 @@ class InviteController < PublicController | ||
62 | redirect_to :action => 'invite_friends' | 62 | redirect_to :action => 'invite_friends' |
63 | end | 63 | end |
64 | 64 | ||
65 | + #Invite or add member without create a task | ||
66 | + #if logged user is admin of environment | ||
65 | def invite_registered_friend | 67 | def invite_registered_friend |
68 | + | ||
69 | + if !params['q'].present? || !request.post? | ||
70 | + | ||
71 | + redirect_to :action => 'invite_friends' | ||
72 | + session[:notice] = _('Please enter a valid profile.') | ||
73 | + | ||
74 | + return | ||
75 | + end | ||
76 | + | ||
66 | contacts_to_invite = params['q'].split(',') | 77 | contacts_to_invite = params['q'].split(',') |
67 | - if !contacts_to_invite.empty? && request.post? | 78 | + |
79 | + if user.is_admin? && profile.community? | ||
80 | + | ||
81 | + Delayed::Job.enqueue AddMembersJob.new contacts_to_invite, profile.id, locale | ||
82 | + | ||
83 | + session[:notice] = _('This friends was added!') | ||
84 | + else | ||
68 | Delayed::Job.enqueue InvitationJob.new(user.id, contacts_to_invite, '', profile.id, nil, locale) | 85 | Delayed::Job.enqueue InvitationJob.new(user.id, contacts_to_invite, '', profile.id, nil, locale) |
69 | session[:notice] = _('Your invitations are being sent.') | 86 | session[:notice] = _('Your invitations are being sent.') |
70 | - if profile.person? | ||
71 | - redirect_to :controller => 'profile', :action => 'friends' | ||
72 | - else | ||
73 | - redirect_to :controller => 'profile', :action => 'members' | ||
74 | - end | 87 | + end |
88 | + | ||
89 | + if profile.person? | ||
90 | + redirect_to :controller => 'profile', :action => 'friends' | ||
75 | else | 91 | else |
76 | - redirect_to :action => 'invite_friends' | ||
77 | - session[:notice] = _('Please enter a valid profile.') | 92 | + redirect_to :controller => 'profile', :action => 'members' |
78 | end | 93 | end |
94 | + | ||
79 | end | 95 | end |
80 | 96 | ||
81 | def search | 97 | def search |
app/helpers/application_helper.rb
@@ -589,14 +589,24 @@ module ApplicationHelper | @@ -589,14 +589,24 @@ module ApplicationHelper | ||
589 | trigger_class = 'enterprise-trigger' | 589 | trigger_class = 'enterprise-trigger' |
590 | end | 590 | end |
591 | end | 591 | end |
592 | - extra_info = extra_info.nil? ? '' : content_tag( 'span', extra_info, :class => 'extra_info' ) | 592 | + |
593 | + extra_info_tag = '' | ||
594 | + img_class = 'profile-image' | ||
595 | + | ||
596 | + if extra_info.is_a? Hash | ||
597 | + extra_info_tag = content_tag( 'span', extra_info[:value], :class => 'extra_info '+extra_info[:class]) | ||
598 | + img_class +=' '+extra_info[:class] | ||
599 | + else | ||
600 | + extra_info_tag = content_tag( 'span', extra_info, :class => 'extra_info' ) | ||
601 | + end | ||
602 | + #extra_info = extra_info.nil? ? '' : content_tag( 'span', extra_info, :class => 'extra_info' ) | ||
593 | links = links_for_balloon(profile) | 603 | links = links_for_balloon(profile) |
594 | content_tag('div', content_tag(tag, | 604 | content_tag('div', content_tag(tag, |
595 | (environment.enabled?(:show_balloon_with_profile_links_when_clicked) ? popover_menu(_('Profile links'),profile.short_name,links,{:class => trigger_class, :url => url}) : "") + | 605 | (environment.enabled?(:show_balloon_with_profile_links_when_clicked) ? popover_menu(_('Profile links'),profile.short_name,links,{:class => trigger_class, :url => url}) : "") + |
596 | link_to( | 606 | link_to( |
597 | - content_tag( 'span', profile_image( profile, size ), :class => 'profile-image' ) + | 607 | + content_tag( 'span', profile_image( profile, size ), :class => img_class ) + |
598 | content_tag( 'span', h(name), :class => ( profile.class == Person ? 'fn' : 'org' ) ) + | 608 | content_tag( 'span', h(name), :class => ( profile.class == Person ? 'fn' : 'org' ) ) + |
599 | - extra_info + profile_sex_icon( profile ) + profile_cat_icons( profile ), | 609 | + extra_info_tag + profile_sex_icon( profile ) + profile_cat_icons( profile ), |
600 | profile.url, | 610 | profile.url, |
601 | :class => 'profile_link url', | 611 | :class => 'profile_link url', |
602 | :help => _('Click on this icon to go to the <b>%s</b>\'s home page') % profile.name, | 612 | :help => _('Click on this icon to go to the <b>%s</b>\'s home page') % profile.name, |
app/models/profile.rb
@@ -703,6 +703,32 @@ private :generate_url, :url_options | @@ -703,6 +703,32 @@ private :generate_url, :url_options | ||
703 | end | 703 | end |
704 | end | 704 | end |
705 | 705 | ||
706 | + # Adds many people to profile by id's or email's | ||
707 | + def add_members(people_ids) | ||
708 | + | ||
709 | + unless people_ids.nil? && people_ids.empty? | ||
710 | + people = [] | ||
711 | + | ||
712 | + if people_ids.first =~ /\@/ | ||
713 | + people = User.where(email: people_ids) | ||
714 | + else | ||
715 | + people = Person.where(id: people_ids) | ||
716 | + end | ||
717 | + | ||
718 | + people.each do |profile| | ||
719 | + person = profile | ||
720 | + | ||
721 | + if profile.is_a? User | ||
722 | + person = profile.person | ||
723 | + end | ||
724 | + | ||
725 | + unless person.is_member_of?(self) | ||
726 | + add_member person | ||
727 | + end | ||
728 | + end | ||
729 | + end | ||
730 | + end | ||
731 | + | ||
706 | def remove_member(person) | 732 | def remove_member(person) |
707 | self.disaffiliate(person, Profile::Roles.all_roles(environment.id)) | 733 | self.disaffiliate(person, Profile::Roles.all_roles(environment.id)) |
708 | end | 734 | end |
app/views/profile/members.html.erb
@@ -4,6 +4,10 @@ | @@ -4,6 +4,10 @@ | ||
4 | 4 | ||
5 | <% cache_timeout(profile.members_cache_key(params), 4.hours) do %> | 5 | <% cache_timeout(profile.members_cache_key(params), 4.hours) do %> |
6 | <ul class='profile-list'> | 6 | <ul class='profile-list'> |
7 | + <!-- | ||
8 | + @todo Highlight visual for invited members | ||
9 | + of a community | ||
10 | + --> | ||
7 | <% @members.each do |member| %> | 11 | <% @members.each do |member| %> |
8 | <%= profile_image_link(member) %> | 12 | <%= profile_image_link(member) %> |
9 | <% end %> | 13 | <% end %> |
public/stylesheets/application.css
@@ -2205,6 +2205,21 @@ a.button.disabled, input.disabled { | @@ -2205,6 +2205,21 @@ a.button.disabled, input.disabled { | ||
2205 | .profile-list .extra_info { | 2205 | .profile-list .extra_info { |
2206 | font-size: 9px; | 2206 | font-size: 9px; |
2207 | } | 2207 | } |
2208 | + | ||
2209 | +/* New members of community added | ||
2210 | +* by admin of environment feature | ||
2211 | +* #issue 227 | ||
2212 | +*/ | ||
2213 | +.profile-list .extra_info.new-profile { | ||
2214 | + margin-top: 5px; | ||
2215 | + color: #0A0; | ||
2216 | + font-weight: bold; | ||
2217 | +} | ||
2218 | + | ||
2219 | +span.new-profile img{ | ||
2220 | + border-top: solid 2px #0A0; | ||
2221 | + margin-top: -2px; | ||
2222 | +} | ||
2208 | /* ==> blocks/recent-documents-block.css <<= */ | 2223 | /* ==> blocks/recent-documents-block.css <<= */ |
2209 | 2224 | ||
2210 | #content .recent-documents-block { | 2225 | #content .recent-documents-block { |
test/functional/invite_controller_test.rb
@@ -284,6 +284,11 @@ class InviteControllerTest < ActionController::TestCase | @@ -284,6 +284,11 @@ class InviteControllerTest < ActionController::TestCase | ||
284 | assert_empty json_response | 284 | assert_empty json_response |
285 | end | 285 | end |
286 | 286 | ||
287 | + #@todo Copy this test and create a another version | ||
288 | + #of this, for test add members in a community | ||
289 | + #logged as admin of environment! | ||
290 | + # #issue227 | ||
291 | + # | ||
287 | should 'invite registered users through profile id' do | 292 | should 'invite registered users through profile id' do |
288 | friend1 = create_user('testuser1').person | 293 | friend1 = create_user('testuser1').person |
289 | friend2 = create_user('testuser2').person | 294 | friend2 = create_user('testuser2').person |
@@ -297,6 +302,29 @@ class InviteControllerTest < ActionController::TestCase | @@ -297,6 +302,29 @@ class InviteControllerTest < ActionController::TestCase | ||
297 | end | 302 | end |
298 | end | 303 | end |
299 | 304 | ||
305 | + should 'add registered users imediatly instead invite if logged user is a environment admin' do | ||
306 | + | ||
307 | + #Add user like a environment admin | ||
308 | + Environment.default.add_admin profile | ||
309 | + | ||
310 | + friend1 = create_user('testuser1').person | ||
311 | + friend2 = create_user('testuser2').person | ||
312 | + | ||
313 | + assert_difference 'Delayed::Job.count', 1 do | ||
314 | + assert_equal 0,community.members.count | ||
315 | + | ||
316 | + post :invite_registered_friend, :profile => @community.identifier, :q => [friend1.id,friend2.id] | ||
317 | + | ||
318 | + assert_response :redirect | ||
319 | + assert_redirected_to :controller => 'profile', :action => 'members' | ||
320 | + end | ||
321 | + | ||
322 | + Delayed::Worker.new.run(Delayed::Job.last) | ||
323 | + | ||
324 | + assert_equal 2,community.members.count | ||
325 | + | ||
326 | + end | ||
327 | + | ||
300 | private | 328 | private |
301 | 329 | ||
302 | def json_response | 330 | def json_response |