diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 9c3171f..11f222a 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -554,14 +554,25 @@ 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 + links = links_for_balloon(profile) content_tag('div', content_tag(tag, - (environment.enabled?(:show_balloon_with_profile_links_when_clicked) ? popover_menu(_('Profile links'),profile.short_name,links,{:class => trigger_class, :url => url}) : "") + + (environment.enabled?(:show_balloon_with_profile_links_when_clicked) ? + popover_menu(_('Profile links'),profile.short_name,links,{:class => 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 ), + extra_info_tag + profile_sex_icon( profile ), profile.url, :class => 'profile_link url', :help => _('Click on this icon to go to the %s\'s home page') % profile.name, @@ -709,7 +720,7 @@ module ApplicationHelper class NoosferoFormBuilder < ActionView::Helpers::FormBuilder extend ActionView::Helpers::TagHelper - def self.output_field(text, field_html, field_id = nil, options = {}) + def self.output_field(text, field_html, field_id = nil) # try to guess an id if none given if field_id.nil? field_html =~ /id=['"]([^'"]*)['"]/ diff --git a/app/models/profile.rb b/app/models/profile.rb index 4b4175a..70ad351 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -738,13 +738,13 @@ private :generate_url, :url_options end # Adds a person as member of this Profile. - def add_member(person) + def add_member(person, attributes={}) if self.has_members? if self.closed? && members.count > 0 AddMember.create!(:person => person, :organization => self) unless self.already_request_membership?(person) else - self.affiliate(person, Profile::Roles.admin(environment.id)) if members.count == 0 - self.affiliate(person, Profile::Roles.member(environment.id)) + self.affiliate(person, Profile::Roles.admin(environment.id), attributes) if members.count == 0 + self.affiliate(person, Profile::Roles.member(environment.id), attributes) end person.tasks.pending.of("InviteMember").select { |t| t.data[:community_id] == self.id }.each { |invite| invite.cancel } remove_from_suggestion_list person diff --git a/app/views/profile/_profile_members_list.html.erb b/app/views/profile/_profile_members_list.html.erb index 64701a2..dce1451 100644 --- a/app/views/profile/_profile_members_list.html.erb +++ b/app/views/profile/_profile_members_list.html.erb @@ -9,7 +9,8 @@ diff --git a/app/views/profile/members.html.erb b/app/views/profile/members.html.erb index b8dfd08..450f817 100644 --- a/app/views/profile/members.html.erb +++ b/app/views/profile/members.html.erb @@ -19,7 +19,6 @@ :id => "members-tab", :content => div_members } %> - <% div_admins = content_tag :div, :class => "profile-admins" do render :partial => 'profile_members_list', :locals => { diff --git a/db/migrate/20160202142247_add_timestamps_to_role_assignments.rb b/db/migrate/20160202142247_add_timestamps_to_role_assignments.rb new file mode 100644 index 0000000..a59624c --- /dev/null +++ b/db/migrate/20160202142247_add_timestamps_to_role_assignments.rb @@ -0,0 +1,5 @@ +class AddTimestampsToRoleAssignments < ActiveRecord::Migration + def change + add_timestamps :role_assignments + end +end diff --git a/db/schema.rb b/db/schema.rb index ce20bd8..9e69298 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150921140802) do +ActiveRecord::Schema.define(version: 20160202142247) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -639,12 +639,14 @@ ActiveRecord::Schema.define(version: 20150921140802) do end create_table "role_assignments", force: :cascade do |t| - t.integer "accessor_id", null: false - t.string "accessor_type" - t.integer "resource_id" - t.string "resource_type" - t.integer "role_id", null: false - t.boolean "is_global" + t.integer "accessor_id", null: false + t.string "accessor_type" + t.integer "resource_id" + t.string "resource_type" + t.integer "role_id", null: false + t.boolean "is_global" + t.datetime "created_at" + t.datetime "updated_at" end create_table "roles", force: :cascade do |t| diff --git a/public/stylesheets/profile-list.scss b/public/stylesheets/profile-list.scss index 0bcb493..cbd9bc1 100644 --- a/public/stylesheets/profile-list.scss +++ b/public/stylesheets/profile-list.scss @@ -207,3 +207,23 @@ height: auto; font-size: 12px; } +.action-profile-members .profile_link{ + position: relative; +} +.action-profile-members .profile_link span.new-profile:last-child{ + position: absolute; + top: 3px; + right: 2px; + text-transform: uppercase; + color: #FFF; + font-size: 9px; + background: #66CC33; + padding: 2px; + display: block; + width: 35px; + font-weight: 700; +} +.action-profile-members .profile_link .fn{ + font-style: normal; + color: #000; +} diff --git a/test/unit/access_control_test.rb b/test/unit/access_control_test.rb new file mode 100644 index 0000000..9da39e0 --- /dev/null +++ b/test/unit/access_control_test.rb @@ -0,0 +1,34 @@ + +require_relative "../test_helper" + +class AccessControlTest < ActiveSupport::TestCase + + include ActsAsAccessor + + should 'raise exception if parameter is not a profile' do + assert_raises(TypeError) { member_relation_of(nil) } + end + + should 'Verify relation among member and community' do + person = fast_create(Person) + community = fast_create(Community) + assert_difference 'person.member_relation_of(community).count', 2 do + community.add_member(person) + end + end + + should 'Member does not belong to community' do + person = fast_create(Person) + community = fast_create(Community) + assert_nil person.member_since_date(community) + end + + should 'Verify if enter date of member in community is available' do + person = fast_create(Person) + community = fast_create(Community) + community.add_member(person) + + assert_instance_of Date, person.member_since_date(community) + end + +end diff --git a/test/unit/application_helper_test.rb b/test/unit/application_helper_test.rb index 00f8282..efea953 100644 --- a/test/unit/application_helper_test.rb +++ b/test/unit/application_helper_test.rb @@ -1043,6 +1043,31 @@ class ApplicationHelperTest < ActionView::TestCase assert_equal c.top_url, top_url end + should "Extra info with hash" do + @plugins = mock + @plugins.stubs(:dispatch_first).returns(false) + env = Environment.default + stubs(:environment).returns(env) + stubs(:profile).returns(profile) + profile = fast_create(Person, :environment_id => env.id) + info = {:value =>_('New'), :class => 'new-profile'} + html = profile_image_link(profile, size=:portrait, tag='li', extra_info = info) + assert_tag_in_string html, :tag => 'span', :attributes => { :class => 'profile-image new-profile' } + assert_tag_in_string html, :tag => 'span', :attributes => { :class => 'extra_info new-profile' }, :content => 'New' + end + + should "Extra info without hash" do + @plugins = mock + @plugins.stubs(:dispatch_first).returns(false) + env = Environment.default + stubs(:environment).returns(env) + stubs(:profile).returns(profile) + profile = fast_create(Person, :environment_id => env.id) + info = 'new' + html = profile_image_link(profile, size=:portrait, tag='li', extra_info = info) + assert_tag_in_string html, :tag => 'span', :attributes => { :class => 'extra_info' }, :content => 'new' + end + protected include NoosferoTestHelper diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb index a424d31..75873fd 100644 --- a/test/unit/person_test.rb +++ b/test/unit/person_test.rb @@ -1925,5 +1925,13 @@ class PersonTest < ActiveSupport::TestCase assert_equal 2, Person.with_role(Profile::Roles.moderator(c1.environment.id).id).count end + should 'check if a person is added like a member of a community today' do + person = create_user('person').person + community = fast_create(Community) + community.add_member person + + assert !person.member_relation_of(community).empty?, "Person '#{person.identifier}' is not a member of Community '#{community.identifier}'" + assert person.member_since_date(community) == Date.today,"Person '#{person.identifier}' is not added like a member of Community '#{community.identifier}' today" + end end diff --git a/vendor/plugins/access_control/lib/acts_as_accessible.rb b/vendor/plugins/access_control/lib/acts_as_accessible.rb index 359329b..ee48a8d 100644 --- a/vendor/plugins/access_control/lib/acts_as_accessible.rb +++ b/vendor/plugins/access_control/lib/acts_as_accessible.rb @@ -19,9 +19,9 @@ module ActsAsAccessible nil end - def affiliate(accessor, roles) + def affiliate(accessor, roles, attributes = {}) roles = Array(roles) - roles.map {|role| accessor.add_role(role, self)}.any? + roles.map {|role| accessor.add_role(role, self, attributes)}.any? end def disaffiliate(accessor, roles) diff --git a/vendor/plugins/access_control/lib/acts_as_accessor.rb b/vendor/plugins/access_control/lib/acts_as_accessor.rb index b0b87d0..35f27a6 100644 --- a/vendor/plugins/access_control/lib/acts_as_accessor.rb +++ b/vendor/plugins/access_control/lib/acts_as_accessor.rb @@ -21,9 +21,9 @@ module ActsAsAccessor (actual_roles - roles).each {|r| remove_role(r, resource)} end - def add_role(role, resource) - attributes = role_attributes(role, resource) - if RoleAssignment.where(attributes).empty? + def add_role(role, resource, attributes = {}) + attributes = role_attributes(role, resource).merge attributes + if RoleAssignment.find(:all, :conditions => attributes).empty? ra = RoleAssignment.new(attributes) role_assignments << ra resource.role_assignments << ra @@ -44,6 +44,19 @@ module ActsAsAccessor RoleAssignment.where(role_attributes nil, res) end + def member_relation_of(profile) + raise TypeError, "Expected instance of 'Profile' class, but '#{profile.class.name}' was founded" unless profile.is_a? Profile + + role_assignments.where(resource_id: profile.id) + end + + def member_since_date(profile) + result = member_relation_of(profile).to_a + unless result.empty? + result.last.created_at ? result.last.created_at.to_date : Date.yesterday + end + end + protected def role_attributes(role, resource) attributes = {:accessor_id => self.id, :accessor_type => self.class.base_class.name} diff --git a/vendor/plugins/access_control/lib/role_assignment.rb b/vendor/plugins/access_control/lib/role_assignment.rb index 2720811..7e53cac 100644 --- a/vendor/plugins/access_control/lib/role_assignment.rb +++ b/vendor/plugins/access_control/lib/role_assignment.rb @@ -1,6 +1,6 @@ class RoleAssignment < ActiveRecord::Base - attr_accessible :accessor_id, :accessor_type, :role_id, :resource_id, :resource_type + attr_accessible :accessor_id, :accessor_type, :role_id, :resource_id, :resource_type, :created_at belongs_to :role belongs_to :accessor, :polymorphic => true -- libgit2 0.21.2