Commit 149906fb21825af5d1df759fef7501ac3dbc5440

Authored by Gabriela Navarro
0 parents

Initial Commit

db/migrate/20150408121921_add_extra_fields_to_gov_user.rb 0 → 100644
  1 +++ a/db/migrate/20150408121921_add_extra_fields_to_gov_user.rb
... ... @@ -0,0 +1,15 @@
  1 +class AddExtraFieldsToGovUser < ActiveRecord::Migration
  2 + def self.up
  3 + change_table :users do |t|
  4 + t.string :secondary_email
  5 + t.string :role
  6 + end
  7 + end
  8 +
  9 + def self.down
  10 + change_table :users do |t|
  11 + t.remove :secondary_email
  12 + t.remove :role
  13 + end
  14 + end
  15 +end
... ...
features/user_profile_edition.feature 0 → 100644
  1 +++ a/features/user_profile_edition.feature
... ... @@ -0,0 +1,28 @@
  1 +Feature: Institution Field
  2 + As a user
  3 + I want to update my update my user data
  4 + So I can maintain my personal data updated
  5 +
  6 + Background:
  7 + Given "GovUserPlugin" plugin is enabled
  8 + And I am logged in as admin
  9 + And I go to /admin/plugins
  10 + And I check "GovUserPlugin"
  11 + And I press "Save changes"
  12 + And feature "skip_new_user_email_confirmation" is enabled on environment
  13 + And I go to /admin/features/manage_fields
  14 + And I check "person_fields_country_active"
  15 + And I check "person_fields_state_active"
  16 + And I check "person_fields_city_active"
  17 + And I press "Save changes"
  18 + And I am logged in as mpog_admin
  19 +
  20 + Scenario: Go to control panel when clicked on 'Complete your profile' link
  21 + When I follow "Complete your profile"
  22 + Then I should see "Profile settings for "
  23 + And I should see "Personal information"
  24 +
  25 + @selenium
  26 + Scenario: Verify text information to use governmental e-mail
  27 + Given I follow "Edit Profile"
  28 + Then I should see "If you work in a public agency use your government e-Mail"
... ...
lib/ext/person.rb 0 → 100644
  1 +++ a/lib/ext/person.rb
... ... @@ -0,0 +1,21 @@
  1 +# encoding: utf-8
  2 +
  3 +require_dependency 'person'
  4 +
  5 +class Person
  6 +
  7 + settings_items :percentage_incomplete, :type => :string, :default => ""
  8 +
  9 + attr_accessible :percentage_incomplete
  10 +
  11 + delegate :login, :to => :user, :prefix => true
  12 +
  13 + def secondary_email
  14 + self.user.secondary_email unless self.user.nil?
  15 + end
  16 +
  17 + def secondary_email= value
  18 + self.user.secondary_email = value unless self.user.nil?
  19 + end
  20 +
  21 +end
... ...
lib/ext/user.rb 0 → 100644
  1 +++ a/lib/ext/user.rb
... ... @@ -0,0 +1,88 @@
  1 +require_dependency 'user'
  2 +
  3 +class User
  4 +
  5 + GOV_SUFFIX = /^.*@[gov.br|jus.br|leg.br|mp.br]+$/
  6 +
  7 + validate :email_different_secondary?, :email_has_already_been_used?,
  8 + :secondary_email_format, :email_suffix_is_gov?
  9 +
  10 + scope :primary_or_secondary_email_already_used?, lambda { |email|
  11 + where("email=? OR secondary_email=?", email, email)
  12 + }
  13 +
  14 + def email_different_secondary?
  15 + self.errors.add(
  16 + :base,
  17 + _("Email must be different from secondary email.")
  18 + ) if self.email == self.secondary_email
  19 + end
  20 +
  21 + def email_has_already_been_used?
  22 + user_already_saved = User.find(:first,
  23 + :conditions => ["email = ?", self.email])
  24 +
  25 + if user_already_saved.nil?
  26 + primary_email_hasnt_been_used =
  27 + User.primary_or_secondary_email_already_used?(self.email).empty?
  28 +
  29 + if !self.secondary_email.nil? and self.secondary_email.empty?
  30 + self.secondary_email = nil
  31 + end
  32 +
  33 + secondary_email_hasnt_been_used =
  34 + User.primary_or_secondary_email_already_used?(self.secondary_email).
  35 + empty?
  36 +
  37 + if !primary_email_hasnt_been_used or !secondary_email_hasnt_been_used
  38 + self.errors.add(:base, _("E-mail or secondary e-mail already taken."))
  39 + end
  40 + end
  41 + end
  42 +
  43 + def secondary_email_format
  44 + if !self.secondary_email.nil? and self.secondary_email.length > 0
  45 + test = /\A[^@]+@([^@\.]+\.)+[^@\.]+\z/
  46 +
  47 + unless test.match(self.secondary_email)
  48 + self.errors.add(:base, _("Invalid secondary email format."))
  49 + end
  50 + end
  51 + end
  52 +
  53 + def email_suffix_is_gov?
  54 + check_gov_suffix_in_secondary_email
  55 + check_gov_email_have_institution
  56 + end
  57 +
  58 + private
  59 +
  60 + def valid_format?(value, string_format)
  61 + !value.nil? && value.length > 0 && !string_format.match(value).nil?
  62 + end
  63 +
  64 + def check_gov_suffix_in_secondary_email
  65 + unless primary_email_has_gov_suffix?
  66 + self.errors.add(
  67 + :base,
  68 + _("The governamental email must be the primary one.")
  69 + ) if secondary_email_has_gov_suffix?
  70 + end
  71 + end
  72 +
  73 + def check_gov_email_have_institution
  74 + self.errors.add(
  75 + :base,
  76 + _("Institution is obligatory if user has a government email.")
  77 + ) if primary_email_has_gov_suffix? && self.institutions.blank?
  78 + end
  79 +
  80 + def primary_email_has_gov_suffix?
  81 + valid_format?(self.email, GOV_SUFFIX)
  82 + end
  83 +
  84 + def secondary_email_has_gov_suffix?
  85 + valid_format?(self.secondary_email, GOV_SUFFIX)
  86 + end
  87 +
  88 +end
... ...
lib/gov_user_plugin.rb 0 → 100644
  1 +++ a/lib/gov_user_plugin.rb
... ... @@ -0,0 +1,125 @@
  1 +class GovUserPlugin < Noosfero::Plugin
  2 + include ActionView::Helpers::TagHelper
  3 + include ActionView::Helpers::FormTagHelper
  4 + include ActionView::Helpers::FormOptionsHelper
  5 + include ActionView::Helpers::JavaScriptHelper
  6 + include ActionView::Helpers::AssetTagHelper
  7 + include FormsHelper
  8 + include ActionView::Helpers
  9 + include ActionDispatch::Routing
  10 + include Rails.application.routes.url_helpers
  11 +
  12 + def self.plugin_name
  13 + # FIXME
  14 + "GovUserPlugin"
  15 + end
  16 +
  17 + def self.plugin_description
  18 + # FIXME
  19 + _("A plugin that does this and that.")
  20 + end
  21 +
  22 + # Hotspot to insert html without an especific hotspot on view.
  23 + def body_beginning
  24 + return if context.session[:user].nil? or context.session[:hide_incomplete_percentage] == true
  25 +
  26 + person = context.environment.people.where(:user_id=>context.session[:user]).first
  27 +
  28 + if context.profile && context.profile.person? and !person.nil?
  29 + @person = person
  30 + @percentege = calc_percentage_registration(person)
  31 +
  32 + if @percentege >= 0 and @percentege < 100
  33 + expanded_template('incomplete_registration.html.erb')
  34 + end
  35 + end
  36 + end
  37 +
  38 + def profile_editor_transaction_extras
  39 + single_hash_transactions = { :user => 'user',
  40 + :instituton => 'instituton'
  41 + }
  42 +
  43 + single_hash_transactions.each do |model, transaction|
  44 + call_model_transaction(model, transaction)
  45 + end
  46 + end
  47 +
  48 + def profile_editor_extras
  49 + profile = context.profile
  50 +
  51 + if profile.person?
  52 + expanded_template('person_editor_extras.html.erb')
  53 + end
  54 + end
  55 +
  56 +
  57 + def calc_percentage_registration(person)
  58 + required_list = profile_required_list
  59 + empty_fields = profile_required_empty_list person
  60 + count = required_list[:person_fields].count +
  61 + required_list[:user_fields].count
  62 + percentege = 100 - ((empty_fields.count * 100) / count)
  63 + person.percentage_incomplete = percentege
  64 + person.save(validate: false)
  65 + percentege
  66 + end
  67 +
  68 + def js_files
  69 + %w(
  70 + vendor/modulejs-1.5.0.min.js
  71 + vendor/jquery.js
  72 + lib/noosfero-root.js
  73 + views/complete-registration.js
  74 + initializer.js
  75 + app.js
  76 + )
  77 + end
  78 +
  79 + protected
  80 +
  81 + def profile_required_list
  82 + fields = {}
  83 + fields[:person_fields] = %w(cell_phone
  84 + contact_phone
  85 + comercial_phone
  86 + country
  87 + city
  88 + state
  89 + organization_website
  90 + image
  91 + identifier
  92 + name)
  93 +
  94 + fields[:user_fields] = %w(secondary_email email)
  95 + fields
  96 + end
  97 +
  98 + def profile_required_empty_list(person)
  99 + empty_fields = []
  100 + required_list = profile_required_list
  101 +
  102 + required_list[:person_fields].each do |field|
  103 + empty_fields << field.sub('_',' ') if person.send(field).blank?
  104 + end
  105 + required_list[:user_fields].each do |field|
  106 + empty_fields << field.sub('_',' ') if person.user.send(field).blank?
  107 + end
  108 + empty_fields
  109 + end
  110 +
  111 + def user_transaction
  112 + user_editor_institution_actions
  113 +
  114 + User.transaction do
  115 + context.profile.user.update_attributes!(context.params[:user])
  116 + end
  117 + end
  118 +
  119 + private
  120 +
  121 + def call_model_transaction(model,name)
  122 + send(name + '_transaction') if context.params.key?(model.to_sym)
  123 + end
  124 +
  125 +end
... ...
public/app.js 0 → 100644
  1 +++ a/public/app.js
... ... @@ -0,0 +1,11 @@
  1 +(function() {
  2 + 'use strict';
  3 +
  4 + var $ = modulejs.require('jquery');
  5 + var Initializer = modulejs.require('Initializer');
  6 +
  7 +
  8 + $(document).ready(function() {
  9 + Initializer.init();
  10 + });
  11 +})();
... ...
public/initializer.js 0 → 100644
  1 +++ a/public/initializer.js
... ... @@ -0,0 +1,28 @@
  1 +(function() {
  2 + 'use strict';
  3 +
  4 + var dependencies = [
  5 + 'CompleteRegistration',
  6 + ];
  7 +
  8 +
  9 + modulejs.define('Initializer', dependencies, function() {
  10 + var __dependencies = arguments;
  11 +
  12 +
  13 + function call_dependency(dependency) {
  14 + if( dependency.isCurrentPage() ) {
  15 + dependency.init();
  16 + }
  17 + }
  18 +
  19 +
  20 + return {
  21 + init: function() {
  22 + for(var i=0, len = __dependencies.length; i < len; i++) {
  23 + call_dependency(__dependencies[i]);
  24 + }
  25 + }
  26 + };
  27 + });
  28 +})();
... ...
public/lib/noosfero-root.js 0 → 100644
  1 +++ a/public/lib/noosfero-root.js
... ... @@ -0,0 +1,13 @@
  1 +modulejs.define('NoosferoRoot', function() {
  2 + 'use strict';
  3 +
  4 +
  5 + function url_with_subdirectory(url) {
  6 + return noosfero_root() + url;
  7 + }
  8 +
  9 +
  10 + return {
  11 + urlWithSubDirectory: url_with_subdirectory
  12 + }
  13 +});
... ...
public/style.css 0 → 100644
  1 +++ a/public/style.css
... ... @@ -0,0 +1,20 @@
  1 +#complete_registration {
  2 + padding: 5px;
  3 + width: 100%;
  4 + background-color: #fff;
  5 +}
  6 +
  7 +#complete_registration a {
  8 + text-decoration: none;
  9 +}
  10 +
  11 +#complete_registration a:hover {
  12 + font-weight: bold;
  13 +}
  14 +
  15 +#complete_registration_percentage {
  16 + width: 100%;
  17 + height: 20px;
  18 + background: #fff;
  19 + border: solid 1px #000;
  20 +}
... ...
public/vendor/jquery.js 0 → 100644
  1 +++ a/public/vendor/jquery.js
... ... @@ -0,0 +1,3 @@
  1 +modulejs.define('jquery', function() {
  2 + return jQuery;
  3 +});
... ...
public/vendor/jquery.maskedinput.min.js 0 → 100644
  1 +++ a/public/vendor/jquery.maskedinput.min.js
... ... @@ -0,0 +1,7 @@
  1 +/*
  2 + Masked Input plugin for jQuery
  3 + Copyright (c) 2007-2013 Josh Bush (digitalbush.com)
  4 + Licensed under the MIT license (http://digitalbush.com/projects/masked-input-plugin/#license)
  5 + Version: 1.3.1
  6 +*/
  7 +(function(e){function t(){var e=document.createElement("input"),t="onpaste";return e.setAttribute(t,""),"function"==typeof e[t]?"paste":"input"}var n,a=t()+".mask",r=navigator.userAgent,i=/iphone/i.test(r),o=/android/i.test(r);e.mask={definitions:{9:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},dataName:"rawMaskFn",placeholder:"_"},e.fn.extend({caret:function(e,t){var n;if(0!==this.length&&!this.is(":hidden"))return"number"==typeof e?(t="number"==typeof t?t:e,this.each(function(){this.setSelectionRange?this.setSelectionRange(e,t):this.createTextRange&&(n=this.createTextRange(),n.collapse(!0),n.moveEnd("character",t),n.moveStart("character",e),n.select())})):(this[0].setSelectionRange?(e=this[0].selectionStart,t=this[0].selectionEnd):document.selection&&document.selection.createRange&&(n=document.selection.createRange(),e=0-n.duplicate().moveStart("character",-1e5),t=e+n.text.length),{begin:e,end:t})},unmask:function(){return this.trigger("unmask")},mask:function(t,r){var c,l,s,u,f,h;return!t&&this.length>0?(c=e(this[0]),c.data(e.mask.dataName)()):(r=e.extend({placeholder:e.mask.placeholder,completed:null},r),l=e.mask.definitions,s=[],u=h=t.length,f=null,e.each(t.split(""),function(e,t){"?"==t?(h--,u=e):l[t]?(s.push(RegExp(l[t])),null===f&&(f=s.length-1)):s.push(null)}),this.trigger("unmask").each(function(){function c(e){for(;h>++e&&!s[e];);return e}function d(e){for(;--e>=0&&!s[e];);return e}function m(e,t){var n,a;if(!(0>e)){for(n=e,a=c(t);h>n;n++)if(s[n]){if(!(h>a&&s[n].test(R[a])))break;R[n]=R[a],R[a]=r.placeholder,a=c(a)}b(),x.caret(Math.max(f,e))}}function p(e){var t,n,a,i;for(t=e,n=r.placeholder;h>t;t++)if(s[t]){if(a=c(t),i=R[t],R[t]=n,!(h>a&&s[a].test(i)))break;n=i}}function g(e){var t,n,a,r=e.which;8===r||46===r||i&&127===r?(t=x.caret(),n=t.begin,a=t.end,0===a-n&&(n=46!==r?d(n):a=c(n-1),a=46===r?c(a):a),k(n,a),m(n,a-1),e.preventDefault()):27==r&&(x.val(S),x.caret(0,y()),e.preventDefault())}function v(t){var n,a,i,l=t.which,u=x.caret();t.ctrlKey||t.altKey||t.metaKey||32>l||l&&(0!==u.end-u.begin&&(k(u.begin,u.end),m(u.begin,u.end-1)),n=c(u.begin-1),h>n&&(a=String.fromCharCode(l),s[n].test(a)&&(p(n),R[n]=a,b(),i=c(n),o?setTimeout(e.proxy(e.fn.caret,x,i),0):x.caret(i),r.completed&&i>=h&&r.completed.call(x))),t.preventDefault())}function k(e,t){var n;for(n=e;t>n&&h>n;n++)s[n]&&(R[n]=r.placeholder)}function b(){x.val(R.join(""))}function y(e){var t,n,a=x.val(),i=-1;for(t=0,pos=0;h>t;t++)if(s[t]){for(R[t]=r.placeholder;pos++<a.length;)if(n=a.charAt(pos-1),s[t].test(n)){R[t]=n,i=t;break}if(pos>a.length)break}else R[t]===a.charAt(pos)&&t!==u&&(pos++,i=t);return e?b():u>i+1?(x.val(""),k(0,h)):(b(),x.val(x.val().substring(0,i+1))),u?t:f}var x=e(this),R=e.map(t.split(""),function(e){return"?"!=e?l[e]?r.placeholder:e:void 0}),S=x.val();x.data(e.mask.dataName,function(){return e.map(R,function(e,t){return s[t]&&e!=r.placeholder?e:null}).join("")}),x.attr("readonly")||x.one("unmask",function(){x.unbind(".mask").removeData(e.mask.dataName)}).bind("focus.mask",function(){clearTimeout(n);var e;S=x.val(),e=y(),n=setTimeout(function(){b(),e==t.length?x.caret(0,e):x.caret(e)},10)}).bind("blur.mask",function(){y(),x.val()!=S&&x.change()}).bind("keydown.mask",g).bind("keypress.mask",v).bind(a,function(){setTimeout(function(){var e=y(!0);x.caret(e),r.completed&&e==x.val().length&&r.completed.call(x)},0)}),y()}))}})})(jQuery);
0 8 \ No newline at end of file
... ...
public/vendor/modulejs-1.5.0.min.js 0 → 100644
  1 +++ a/public/vendor/modulejs-1.5.0.min.js
... ... @@ -0,0 +1,2 @@
  1 +/* modulejs 1.5.0 - http://larsjung.de/modulejs/ */
  2 +!function(n){this.modulejs=n()}(function(){"use strict";function n(n){return function(r){return l.toString.call(r)==="[object "+n+"]"}}function r(n){return n===new Object(n)}function t(n,r){return l.hasOwnProperty.call(n,r)}function e(n,r,e){if(p&&n.forEach===p)n.forEach(r,e);else if(n.length===+n.length)for(var i=0,o=n.length;o>i;i+=1)r.call(e,n[i],i,n);else for(var u in n)t(n,u)&&r.call(e,n[u],u,n)}function i(n,r){for(var t=0,e=n.length;e>t;t+=1)if(n[t]===r)return!0;return!1}function o(n){var r={},i=[];return e(n,function(n){t(r,n)||(i.push(n),r[n]=1)}),i}function u(n,r,t){if(n){var e=new Error("[modulejs-"+r+"] "+t);throw e.code=r,e}}function c(n,r,a){if(u(!h(n),31,'id must be a string "'+n+'"'),!r&&t(b,n))return b[n];var f=y[n];u(!f,32,'id not defined "'+n+'"'),a=(a||[]).slice(0),a.push(n);var s=[];if(e(f.deps,function(n){u(i(a,n),33,"circular dependencies: "+a+" & "+n),r?(s=s.concat(c(n,r,a)),s.push(n)):s.push(c(n,r,a))}),r)return o(s);var d=f.fn.apply(void 0,s);return b[n]=d,d}function a(n,t,e){void 0===e&&(e=t,t=[]),u(!h(n),11,'id must be a string "'+n+'"'),u(y[n],12,'id already defined "'+n+'"'),u(!g(t),13,'dependencies for "'+n+'" must be an array "'+t+'"'),u(!r(e)&&!v(e),14,'arg for "'+n+'" must be object or function "'+e+'"'),y[n]={id:n,deps:t,fn:v(e)?e:function(){return e}}}function f(n){return c(n)}function s(){var n={};return e(y,function(r,e){n[e]={deps:r.deps.slice(0),reqs:c(e,!0),init:t(b,e)}}),e(y,function(r,t){var o=[];e(y,function(r,e){i(n[e].reqs,t)&&o.push(e)}),n[t].reqd=o}),n}function d(n){var r="\n";return e(s(),function(t,e){var i=n?t.reqd:t.reqs;r+=(t.init?"* ":" ")+e+" -> [ "+i.join(", ")+" ]\n"}),r}var l=Object.prototype,p=Array.prototype.forEach,h=n("String"),v=n("Function"),g=Array.isArray||n("Array"),y={},b={};return{define:a,require:f,state:s,log:d,_private:{isString:h,isFunction:v,isArray:g,isObject:r,has:t,each:e,contains:i,uniq:o,err:u,definitions:y,instances:b,resolve:c}}});
0 3 \ No newline at end of file
... ...
public/views/complete-registration.js 0 → 100644
  1 +++ a/public/views/complete-registration.js
... ... @@ -0,0 +1,60 @@
  1 +modulejs.define('CompleteRegistration', ['jquery', 'NoosferoRoot'], function($, NoosferoRoot) {
  2 + 'use strict';
  3 +
  4 +
  5 + var AJAX_URL = {
  6 + hide_registration_incomplete_percentage:
  7 + NoosferoRoot.urlWithSubDirectory("/plugin/software_communities/hide_registration_incomplete_percentage")
  8 + };
  9 +
  10 +
  11 + function hide_incomplete_percentage(evt) {
  12 + evt.preventDefault();
  13 +
  14 + jQuery.get(AJAX_URL.hide_registration_incomplete_percentage, {hide:true}, function(response){
  15 + if( response === true ) {
  16 + jQuery("#complete_registration").fadeOut();
  17 + }
  18 + });
  19 + }
  20 +
  21 +
  22 + function show_complete_progressbar() {
  23 + var percentage = jQuery("#complete_registration_message span").html();
  24 + var canvas_tag = document.getElementById("complete_registration_percentage");
  25 +
  26 + if( canvas_tag !== null ) {
  27 + var context = canvas_tag.getContext("2d");
  28 +
  29 + percentage = canvas_tag.width*(percentage/100.0);
  30 +
  31 + context.beginPath();
  32 + context.rect(0, 0, percentage, canvas_tag.height);
  33 + context.fillStyle = '#00FF00';
  34 + context.fill();
  35 + }
  36 + }
  37 +
  38 +
  39 + function repositioning_bar_percentage() {
  40 + var complete_message = $("#complete_registration").remove();
  41 +
  42 + $(".profile-info-options").before(complete_message);
  43 + }
  44 +
  45 +
  46 + return {
  47 + isCurrentPage: function() {
  48 + return $("#complete_registration").length === 1;
  49 + },
  50 +
  51 +
  52 + init: function() {
  53 + repositioning_bar_percentage();
  54 +
  55 + jQuery(".hide-incomplete-percentage").click(hide_incomplete_percentage);
  56 +
  57 + show_complete_progressbar();
  58 + }
  59 + }
  60 +});
... ...
test/helpers/plugin_test_helper.rb 0 → 100644
  1 +++ a/test/helpers/plugin_test_helper.rb
... ... @@ -0,0 +1,37 @@
  1 +module PluginTestHelper
  2 + def create_person name, email, password, password_confirmation, secondary_email, state, city
  3 + user = create_user(
  4 + name.to_slug,
  5 + email,
  6 + password,
  7 + password_confirmation,
  8 + secondary_email
  9 + )
  10 + person = Person::new
  11 +
  12 + user.person = person
  13 + person.user = user
  14 +
  15 + person.name = name
  16 + person.identifier = name.to_slug
  17 + person.state = state
  18 + person.city = city
  19 +
  20 + user.save
  21 + person.save
  22 +
  23 + person
  24 + end
  25 +
  26 + def create_user login, email, password, password_confirmation, secondary_email
  27 + user = User.new
  28 +
  29 + user.login = login
  30 + user.email = email
  31 + user.password = password
  32 + user.password_confirmation = password_confirmation
  33 + user.secondary_email = secondary_email
  34 +
  35 + user
  36 + end
  37 +end
... ...
test/unit/person_test.rb 0 → 100644
  1 +++ a/test/unit/person_test.rb
... ... @@ -0,0 +1,43 @@
  1 +require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +require File.dirname(__FILE__) + '/../helpers/plugin_test_helper'
  3 +
  4 +class SoftwareCommunitiesPluginPersonTest < ActiveSupport::TestCase
  5 + include PluginTestHelper
  6 + def setup
  7 + @plugin = GovUserPlugin.new
  8 +
  9 + @user = fast_create(User)
  10 + @person = create_person(
  11 + "My Name",
  12 + "user@email.com",
  13 + "123456",
  14 + "123456",
  15 + "user@secondaryemail.com",
  16 + "Any State",
  17 + "Some City"
  18 + )
  19 + end
  20 +
  21 + should 'calculate the percentege of person incomplete fields' do
  22 + @person.cell_phone = "76888919"
  23 + @person.contact_phone = "987654321"
  24 +
  25 + assert_equal(67, @plugin.calc_percentage_registration(@person))
  26 +
  27 + @person.comercial_phone = "11223344"
  28 + @person.country = "I dont know"
  29 + @person.state = "I dont know"
  30 + @person.city = "I dont know"
  31 + @person.organization_website = "www.whatever.com"
  32 + @person.image = Image::new :uploaded_data=>fixture_file_upload('/files/rails.png', 'image/png')
  33 + @person.save
  34 +
  35 + assert_equal(100, @plugin.calc_percentage_registration(@person))
  36 + end
  37 +
  38 + should 'return true when the email has not gov.br,jus.br,leg.br or mp.br' do
  39 + @user.secondary_email = "test_email@com.br"
  40 + @user.email = "test_email@net.br"
  41 + assert @user.save
  42 + end
  43 +end
... ...
test/unit/user_test.rb 0 → 100644
  1 +++ a/test/unit/user_test.rb
... ... @@ -0,0 +1,138 @@
  1 +require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +require File.dirname(__FILE__) + '/../helpers/plugin_test_helper'
  3 +
  4 +class UserTest < ActiveSupport::TestCase
  5 + include PluginTestHelper
  6 +
  7 + should 'not save user whose both email and secondary email are the same' do
  8 + user = fast_create(User)
  9 + user.email = "test@email.com"
  10 + user.secondary_email = "test@email.com"
  11 +
  12 + assert !user.save
  13 + end
  14 +
  15 + should 'not save user whose email and secondary email have been taken' do
  16 + user1 = create_default_user
  17 + user2 = fast_create(User)
  18 +
  19 + user2.email = "primary@email.com"
  20 + user2.secondary_email = "secondary@email.com"
  21 + assert !user2.save
  22 + end
  23 +
  24 + should 'not save user whose email has already been used' do
  25 + user1 = create_default_user
  26 + user2 = fast_create(User)
  27 +
  28 + user2.email = "primary@email.com"
  29 + user2.secondary_email = "noosfero@email.com"
  30 + assert !user2.save
  31 + end
  32 +
  33 + should 'not save user whose email has been taken another in users secondary email' do
  34 + user1 = create_default_user
  35 + user2 = fast_create(User)
  36 +
  37 + user2.login = "another-login"
  38 + user2.email = "secondary@email.com"
  39 + user2.secondary_email = "noosfero@email.com"
  40 + assert !user2.save
  41 + end
  42 +
  43 + should 'not save user whose secondary email has been taken used in another users email' do
  44 + user1 = create_default_user
  45 + user2 = fast_create(User)
  46 +
  47 + user2.login = "another-login"
  48 + user2.email = "noosfero@email.com"
  49 + user2.secondary_email = "primary@email.com"
  50 + assert !user2.save
  51 + end
  52 +
  53 + should 'not save user whose secondary email has already been used in another users secondary email' do
  54 + user1 = create_default_user
  55 + user2 = fast_create(User)
  56 +
  57 + user2.login = "another-login"
  58 + user2.email = "noosfero@email.com"
  59 + user2.secondary_email = "secondary@email.com"
  60 + assert !user2.save
  61 + end
  62 +
  63 + should 'not save user whose secondary email is in the wrong format' do
  64 + user = fast_create(User)
  65 + user.email = "test@email.com"
  66 + user.secondary_email = "notarightformat.com"
  67 +
  68 + assert !user.save
  69 +
  70 + user.secondary_email = "not@arightformatcom"
  71 +
  72 + assert !user.save
  73 + end
  74 +
  75 + should 'save more than one user without secondary email' do
  76 + user = fast_create(User)
  77 + user.email = "test@email.com"
  78 + user.secondary_email = ""
  79 + user.save
  80 +
  81 + user2 = fast_create(User)
  82 + user2.email = "test2@email.com"
  83 + user2.secondary_email = ""
  84 + assert user2.save
  85 + end
  86 +
  87 + should 'return an error if secondary email is governmental and primary is not' do
  88 + invalid_msg = "The governamental email must be the primary one."
  89 + user = fast_create(User)
  90 +
  91 + user.email = "test@email.com"
  92 + user.secondary_email = "test@gov.br"
  93 +
  94 + assert !user.save
  95 + assert user.errors.full_messages.include?(invalid_msg)
  96 + end
  97 +
  98 + # should 'have institution if email is governmental' do
  99 + # user = fast_create(User)
  100 + #
  101 + # user.email = "testtest@gov.br"
  102 + #
  103 + # user.institutions = []
  104 + # assert !user.save, "this should not save"
  105 + #
  106 + # gov_power = GovernmentalPower.create(:name=>"Some Gov Power")
  107 + # gov_sphere = GovernmentalSphere.create(:name=>"Some Gov Sphere")
  108 + # juridical_nature = JuridicalNature.create(:name => "Autarquia")
  109 + # institution = create_public_institution(
  110 + # "Ministerio Publico da Uniao",
  111 + # "MPU",
  112 + # "BR",
  113 + # "DF",
  114 + # "Gama",
  115 + # juridical_nature,
  116 + # gov_power,
  117 + # gov_sphere,
  118 + # "44.555.666/7777-88"
  119 + # )
  120 + # institution.save!
  121 + #
  122 + # user.institutions << institution
  123 + # assert user.save, "this should save"
  124 + # end
  125 +
  126 + private
  127 +
  128 + def create_default_user
  129 + user = fast_create(User)
  130 + user.login = "a-login"
  131 + user.email = "primary@email.com"
  132 + user.secondary_email = "secondary@email.com"
  133 + user.save
  134 +
  135 + return user
  136 + end
  137 +
  138 +end
... ...
views/incomplete_registration.html.erb 0 → 100644
  1 +++ a/views/incomplete_registration.html.erb
... ... @@ -0,0 +1,11 @@
  1 +<div id='complete_registration'>
  2 + <div id="complete_registration_message">
  3 + <div><%= _("Complete Profile")+": <span>#{@percentege}</span>%" %></div>
  4 + <canvas id="complete_registration_percentage" width="100%" height="20"></canvas>
  5 + <div>
  6 + <%= link_to _("Complete your profile"), "#{Noosfero.root}/myprofile/#{@person.identifier}/profile_editor/edit" %> |
  7 + <%= link_to _("Hide"), "#", :class=>"hide-incomplete-percentage" %>
  8 + </div>
  9 + </div>
  10 +</div>
  11 +</div>
... ...
views/person_editor_extras.html.erb 0 → 100644
  1 +++ a/views/person_editor_extras.html.erb
... ... @@ -0,0 +1,12 @@
  1 +<div class="formfieldline">
  2 + <%= label_tag "user[secondary_email]", _('Secondary e-mail')+":", :class=>"formlabel" %>
  3 +
  4 + <div class="formfield type-text">
  5 + <%= text_field_tag "user[secondary_email]", context.profile.user.secondary_email %>
  6 + </div>
  7 +</div>
  8 +
  9 +<%= hidden_field_tag("full_name_error", _("Should begin with a capital letter and no special characters")) %>
  10 +<%= hidden_field_tag("email_error", _("Email should have the following format: name@host.br")) %>
  11 +<%= hidden_field_tag("site_error", _("Site should have a valid format: http://name.hosts")) %>
  12 +<div id="email_public_message"><%= _("If you work in a public agency use your government e-Mail") %> </div>
... ...