From 7ba0db117c922fa575ef846115e9d1e28d457ad8 Mon Sep 17 00:00:00 2001 From: Michel Felipe Date: Mon, 2 Mar 2015 16:56:49 -0300 Subject: [PATCH] Modify invite friend to community feature for add member imediatly, if logged user is a admin of environment --- app/controllers/public/invite_controller.rb | 20 ++++++++++++++++++-- app/controllers/public/profile_controller.rb | 7 +++++++ app/helpers/application_helper.rb | 16 +++++++++++++--- app/models/invitation.rb | 19 ++++++++++++++++++- app/views/profile/members.html.erb | 6 +++++- public/stylesheets/application.css | 15 +++++++++++++++ 6 files changed, 76 insertions(+), 7 deletions(-) diff --git a/app/controllers/public/invite_controller.rb b/app/controllers/public/invite_controller.rb index d0ddacc..f7e4fb6 100644 --- a/app/controllers/public/invite_controller.rb +++ b/app/controllers/public/invite_controller.rb @@ -62,11 +62,27 @@ class InviteController < PublicController redirect_to :action => 'invite_friends' end + #Invite or add member without create a task + #if logged user is admin of environment def invite_registered_friend contacts_to_invite = params['q'].split(',') if !contacts_to_invite.empty? && request.post? - Delayed::Job.enqueue InvitationJob.new(user.id, contacts_to_invite, '', profile.id, nil, locale) - session[:notice] = _('Your invitations are being sent.') + + if user.is_admin? + person = Person.find(user.id) + session[:invited_members] = [] + + Invitation.invite(person, contacts_to_invite, '', profile) do |added_member| + session[:invited_members] << added_member.id + end + + session[:notice] = _('This friends was added!') + else + Delayed::Job.enqueue InvitationJob.new(user.id, contacts_to_invite, '', profile.id, nil, locale) + session[:notice] = _('Your invitations are being sent.') + end + + if profile.person? redirect_to :controller => 'profile', :action => 'friends' else diff --git a/app/controllers/public/profile_controller.rb b/app/controllers/public/profile_controller.rb index da07102..b7e08b2 100644 --- a/app/controllers/public/profile_controller.rb +++ b/app/controllers/public/profile_controller.rb @@ -64,8 +64,15 @@ class ProfileController < PublicController end def members + @profiles_focus = [] + if is_cache_expired?(profile.members_cache_key(params)) @members = profile.members_by_name.includes(relations_to_include).paginate(:per_page => members_per_page, :page => params[:npage], :total_entries => profile.members.count) + if session[:invited_members] + @profiles_focus = session[:invited_members] + + session.delete :invited_members + end end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 05bf735..e9f7892 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -589,14 +589,24 @@ module ApplicationHelper trigger_class = 'enterprise-trigger' end end - extra_info = extra_info.nil? ? '' : content_tag( 'span', extra_info, :class => 'extra_info' ) + + extra_info_tag = '' + img_class = 'profile-image' + + if extra_info.is_a? Hash + extra_info_tag = content_tag( 'span', extra_info[:value], :class => 'extra_info '+extra_info[:class]) + img_class +=' '+extra_info[:class] + else + extra_info_tag = content_tag( 'span', extra_info, :class => 'extra_info' ) + end + #extra_info = extra_info.nil? ? '' : content_tag( 'span', extra_info, :class => 'extra_info' ) links = links_for_balloon(profile) content_tag('div', content_tag(tag, (environment.enabled?(:show_balloon_with_profile_links_when_clicked) ? link_to( content_tag( 'span', _('Profile links')), '#', :onclick => "toggleSubmenu(this, '#{profile.short_name}', #{CGI::escapeHTML(links.to_json)}); return false", :class => "menu-submenu-trigger #{trigger_class}", :url => url) : "") + link_to( - content_tag( 'span', profile_image( profile, size ), :class => 'profile-image' ) + + content_tag( 'span', profile_image( profile, size ), :class => img_class ) + content_tag( 'span', h(name), :class => ( profile.class == Person ? 'fn' : 'org' ) ) + - extra_info + profile_sex_icon( profile ) + profile_cat_icons( profile ), + extra_info_tag + profile_sex_icon( profile ) + profile_cat_icons( profile ), profile.url, :class => 'profile_link url', :help => _('Click on this icon to go to the %s\'s home page') % profile.name, diff --git a/app/models/invitation.rb b/app/models/invitation.rb index 3b8b21e..0a7d0f8 100644 --- a/app/models/invitation.rb +++ b/app/models/invitation.rb @@ -47,6 +47,7 @@ class Invitation < Task end def self.invite(person, contacts_to_invite, message, profile) + contacts_to_invite.each do |contact_to_invite| next if contact_to_invite == _("Firstname Lastname ") @@ -79,7 +80,23 @@ class Invitation < Task if profile.person? InviteFriend.create(task_args) if user.nil? || !user.person.is_a_friend?(person) elsif profile.community? - InviteMember.create(task_args.merge(:community_id => profile.id)) if user.nil? || !user.person.is_member_of?(profile) + + if person.is_admin? + unless user.person.is_member_of?(profile) + + profile.add_member(user.person) + + #Call after add member callback + yield user + + end + else + + InviteMember.create(task_args.merge(:community_id => profile.id)) if user.nil? || !user.person.is_member_of?(profile) + + #Call after create invite member task callback + yield user,task_args + end else raise NotImplementedError, 'Don\'t know how to invite people to a %s' % profile.class.to_s end diff --git a/app/views/profile/members.html.erb b/app/views/profile/members.html.erb index fc9f1ae..921c64a 100644 --- a/app/views/profile/members.html.erb +++ b/app/views/profile/members.html.erb @@ -4,8 +4,12 @@ <% cache_timeout(profile.members_cache_key(params), 4.hours) do %> diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index c01682f..e8f7bf9 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -2205,6 +2205,21 @@ a.button.disabled, input.disabled { .profile-list .extra_info { font-size: 9px; } + +/* New members of community added +* by admin of environment feature +* #issue 227 +*/ +.profile-list .extra_info.new-profile { + margin-top: 5px; + color: #0A0; + font-weight: bold; +} + +span.new-profile img{ + border-top: solid 2px #0A0; + margin-top: -2px; +} /* ==> blocks/recent-documents-block.css <<= */ #content .recent-documents-block { -- libgit2 0.21.2