From 53a8b04d5b1f126459dfbccdf1e54e8bf05a7a6c Mon Sep 17 00:00:00 2001 From: Hugo Melo Date: Wed, 14 Oct 2015 09:57:37 -0300 Subject: [PATCH] Check if user profile was filled for pontuation --- lib/ext/person.rb | 15 ++++++++++++--- lib/merit/point_rules.rb | 8 ++++---- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/ext/person.rb b/lib/ext/person.rb index c2144d4..5e5f91c 100644 --- a/lib/ext/person.rb +++ b/lib/ext/person.rb @@ -5,12 +5,21 @@ class Person # TODO why this relationship doesn't exists in core? has_many :comments, :foreign_key => 'author_id' + after_save { |obj| obj.new_merit_action(:update, {}) } + def profile_completion_score_condition - self.points(category: 'profile_completion') == 0 and self.is_profile_complete? + categories = [] + GamificationPlugin::PointsCategorization.for_type('profile_completion').each {|i| categories << i.id.to_s} + self.points(category: categories) == 0 and self.is_profile_complete? end + def is_profile_complete? - # FIXME: FIND OUT A WAY TO CHECK EVERY REGISTRY FIELD - false + !(self.name.blank? or + (self.data[:identidade_genero].blank? and self.data[:transgenero].blank?) or + self.data[:etnia].blank? or + self.data[:orientacao_sexual].blank? or + self.data[:state].blank? or + self.data[:city].blank?) end def points_by_type type diff --git a/lib/merit/point_rules.rb b/lib/merit/point_rules.rb index bf9fc69..657df3f 100644 --- a/lib/merit/point_rules.rb +++ b/lib/merit/point_rules.rb @@ -96,14 +96,14 @@ module Merit profile_action: false }, profile_completion: { - action: ['account#create', 'account#update'], - undo_action: 'account#destroy', - to: lambda {|user| user.person}, + action: ['profile#create', 'profile#update'], + undo_action: 'profile#destroy', + to: :itself, value: 1, description: _('Profile Completion'), default_weight: 100, model_name: "User", - condition: lambda {|user| user.person.profile_completion_score_condition }, + condition: lambda {|person| person.person? and person.profile_completion_score_condition }, profile_action: false }, follower: { -- libgit2 0.21.2