Commit 53a8b04d5b1f126459dfbccdf1e54e8bf05a7a6c
1 parent
74c15a6a
Exists in
master
and in
1 other branch
Check if user profile was filled for pontuation
Showing
2 changed files
with
16 additions
and
7 deletions
Show diff stats
lib/ext/person.rb
| ... | ... | @@ -5,12 +5,21 @@ class Person |
| 5 | 5 | # TODO why this relationship doesn't exists in core? |
| 6 | 6 | has_many :comments, :foreign_key => 'author_id' |
| 7 | 7 | |
| 8 | + after_save { |obj| obj.new_merit_action(:update, {}) } | |
| 9 | + | |
| 8 | 10 | def profile_completion_score_condition |
| 9 | - self.points(category: 'profile_completion') == 0 and self.is_profile_complete? | |
| 11 | + categories = [] | |
| 12 | + GamificationPlugin::PointsCategorization.for_type('profile_completion').each {|i| categories << i.id.to_s} | |
| 13 | + self.points(category: categories) == 0 and self.is_profile_complete? | |
| 10 | 14 | end |
| 15 | + | |
| 11 | 16 | def is_profile_complete? |
| 12 | - # FIXME: FIND OUT A WAY TO CHECK EVERY REGISTRY FIELD | |
| 13 | - false | |
| 17 | + !(self.name.blank? or | |
| 18 | + (self.data[:identidade_genero].blank? and self.data[:transgenero].blank?) or | |
| 19 | + self.data[:etnia].blank? or | |
| 20 | + self.data[:orientacao_sexual].blank? or | |
| 21 | + self.data[:state].blank? or | |
| 22 | + self.data[:city].blank?) | |
| 14 | 23 | end |
| 15 | 24 | |
| 16 | 25 | def points_by_type type | ... | ... |
lib/merit/point_rules.rb
| ... | ... | @@ -96,14 +96,14 @@ module Merit |
| 96 | 96 | profile_action: false |
| 97 | 97 | }, |
| 98 | 98 | profile_completion: { |
| 99 | - action: ['account#create', 'account#update'], | |
| 100 | - undo_action: 'account#destroy', | |
| 101 | - to: lambda {|user| user.person}, | |
| 99 | + action: ['profile#create', 'profile#update'], | |
| 100 | + undo_action: 'profile#destroy', | |
| 101 | + to: :itself, | |
| 102 | 102 | value: 1, |
| 103 | 103 | description: _('Profile Completion'), |
| 104 | 104 | default_weight: 100, |
| 105 | 105 | model_name: "User", |
| 106 | - condition: lambda {|user| user.person.profile_completion_score_condition }, | |
| 106 | + condition: lambda {|person| person.person? and person.profile_completion_score_condition }, | |
| 107 | 107 | profile_action: false |
| 108 | 108 | }, |
| 109 | 109 | follower: { | ... | ... |