From 149906fb21825af5d1df759fef7501ac3dbc5440 Mon Sep 17 00:00:00 2001 From: Gabriela Navarro Date: Wed, 8 Apr 2015 15:06:02 +0000 Subject: [PATCH] Initial Commit --- db/migrate/20150408121921_add_extra_fields_to_gov_user.rb | 15 +++++++++++++++ features/user_profile_edition.feature | 28 ++++++++++++++++++++++++++++ lib/ext/person.rb | 21 +++++++++++++++++++++ lib/ext/user.rb | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/gov_user_plugin.rb | 125 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ public/app.js | 11 +++++++++++ public/initializer.js | 28 ++++++++++++++++++++++++++++ public/lib/noosfero-root.js | 13 +++++++++++++ public/style.css | 20 ++++++++++++++++++++ public/vendor/jquery.js | 3 +++ public/vendor/jquery.maskedinput.min.js | 7 +++++++ public/vendor/modulejs-1.5.0.min.js | 2 ++ public/views/complete-registration.js | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/helpers/plugin_test_helper.rb | 37 +++++++++++++++++++++++++++++++++++++ test/unit/person_test.rb | 43 +++++++++++++++++++++++++++++++++++++++++++ test/unit/user_test.rb | 138 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ views/incomplete_registration.html.erb | 11 +++++++++++ views/person_editor_extras.html.erb | 12 ++++++++++++ 18 files changed, 662 insertions(+), 0 deletions(-) create mode 100644 db/migrate/20150408121921_add_extra_fields_to_gov_user.rb create mode 100644 features/user_profile_edition.feature create mode 100644 lib/ext/person.rb create mode 100644 lib/ext/user.rb create mode 100644 lib/gov_user_plugin.rb create mode 100644 public/app.js create mode 100644 public/initializer.js create mode 100644 public/lib/noosfero-root.js create mode 100644 public/style.css create mode 100644 public/vendor/jquery.js create mode 100644 public/vendor/jquery.maskedinput.min.js create mode 100644 public/vendor/modulejs-1.5.0.min.js create mode 100644 public/views/complete-registration.js create mode 100644 test/helpers/plugin_test_helper.rb create mode 100644 test/unit/person_test.rb create mode 100644 test/unit/user_test.rb create mode 100644 views/incomplete_registration.html.erb create mode 100644 views/person_editor_extras.html.erb diff --git a/db/migrate/20150408121921_add_extra_fields_to_gov_user.rb b/db/migrate/20150408121921_add_extra_fields_to_gov_user.rb new file mode 100644 index 0000000..2979cf5 --- /dev/null +++ b/db/migrate/20150408121921_add_extra_fields_to_gov_user.rb @@ -0,0 +1,15 @@ +class AddExtraFieldsToGovUser < ActiveRecord::Migration + def self.up + change_table :users do |t| + t.string :secondary_email + t.string :role + end + end + + def self.down + change_table :users do |t| + t.remove :secondary_email + t.remove :role + end + end +end diff --git a/features/user_profile_edition.feature b/features/user_profile_edition.feature new file mode 100644 index 0000000..0c21c72 --- /dev/null +++ b/features/user_profile_edition.feature @@ -0,0 +1,28 @@ +Feature: Institution Field + As a user + I want to update my update my user data + So I can maintain my personal data updated + + Background: + Given "GovUserPlugin" plugin is enabled + And I am logged in as admin + And I go to /admin/plugins + And I check "GovUserPlugin" + And I press "Save changes" + And feature "skip_new_user_email_confirmation" is enabled on environment + And I go to /admin/features/manage_fields + And I check "person_fields_country_active" + And I check "person_fields_state_active" + And I check "person_fields_city_active" + And I press "Save changes" + And I am logged in as mpog_admin + + Scenario: Go to control panel when clicked on 'Complete your profile' link + When I follow "Complete your profile" + Then I should see "Profile settings for " + And I should see "Personal information" + + @selenium + Scenario: Verify text information to use governmental e-mail + Given I follow "Edit Profile" + Then I should see "If you work in a public agency use your government e-Mail" diff --git a/lib/ext/person.rb b/lib/ext/person.rb new file mode 100644 index 0000000..34ea237 --- /dev/null +++ b/lib/ext/person.rb @@ -0,0 +1,21 @@ +# encoding: utf-8 + +require_dependency 'person' + +class Person + + settings_items :percentage_incomplete, :type => :string, :default => "" + + attr_accessible :percentage_incomplete + + delegate :login, :to => :user, :prefix => true + + def secondary_email + self.user.secondary_email unless self.user.nil? + end + + def secondary_email= value + self.user.secondary_email = value unless self.user.nil? + end + +end diff --git a/lib/ext/user.rb b/lib/ext/user.rb new file mode 100644 index 0000000..3817c86 --- /dev/null +++ b/lib/ext/user.rb @@ -0,0 +1,88 @@ +require_dependency 'user' + +class User + + GOV_SUFFIX = /^.*@[gov.br|jus.br|leg.br|mp.br]+$/ + + validate :email_different_secondary?, :email_has_already_been_used?, + :secondary_email_format, :email_suffix_is_gov? + + scope :primary_or_secondary_email_already_used?, lambda { |email| + where("email=? OR secondary_email=?", email, email) + } + + def email_different_secondary? + self.errors.add( + :base, + _("Email must be different from secondary email.") + ) if self.email == self.secondary_email + end + + def email_has_already_been_used? + user_already_saved = User.find(:first, + :conditions => ["email = ?", self.email]) + + if user_already_saved.nil? + primary_email_hasnt_been_used = + User.primary_or_secondary_email_already_used?(self.email).empty? + + if !self.secondary_email.nil? and self.secondary_email.empty? + self.secondary_email = nil + end + + secondary_email_hasnt_been_used = + User.primary_or_secondary_email_already_used?(self.secondary_email). + empty? + + if !primary_email_hasnt_been_used or !secondary_email_hasnt_been_used + self.errors.add(:base, _("E-mail or secondary e-mail already taken.")) + end + end + end + + def secondary_email_format + if !self.secondary_email.nil? and self.secondary_email.length > 0 + test = /\A[^@]+@([^@\.]+\.)+[^@\.]+\z/ + + unless test.match(self.secondary_email) + self.errors.add(:base, _("Invalid secondary email format.")) + end + end + end + + def email_suffix_is_gov? + check_gov_suffix_in_secondary_email + check_gov_email_have_institution + end + + private + + def valid_format?(value, string_format) + !value.nil? && value.length > 0 && !string_format.match(value).nil? + end + + def check_gov_suffix_in_secondary_email + unless primary_email_has_gov_suffix? + self.errors.add( + :base, + _("The governamental email must be the primary one.") + ) if secondary_email_has_gov_suffix? + end + end + + def check_gov_email_have_institution + self.errors.add( + :base, + _("Institution is obligatory if user has a government email.") + ) if primary_email_has_gov_suffix? && self.institutions.blank? + end + + def primary_email_has_gov_suffix? + valid_format?(self.email, GOV_SUFFIX) + end + + def secondary_email_has_gov_suffix? + valid_format?(self.secondary_email, GOV_SUFFIX) + end + +end diff --git a/lib/gov_user_plugin.rb b/lib/gov_user_plugin.rb new file mode 100644 index 0000000..f3f7a2f --- /dev/null +++ b/lib/gov_user_plugin.rb @@ -0,0 +1,125 @@ +class GovUserPlugin < Noosfero::Plugin + include ActionView::Helpers::TagHelper + include ActionView::Helpers::FormTagHelper + include ActionView::Helpers::FormOptionsHelper + include ActionView::Helpers::JavaScriptHelper + include ActionView::Helpers::AssetTagHelper + include FormsHelper + include ActionView::Helpers + include ActionDispatch::Routing + include Rails.application.routes.url_helpers + + def self.plugin_name + # FIXME + "GovUserPlugin" + end + + def self.plugin_description + # FIXME + _("A plugin that does this and that.") + end + + # Hotspot to insert html without an especific hotspot on view. + def body_beginning + return if context.session[:user].nil? or context.session[:hide_incomplete_percentage] == true + + person = context.environment.people.where(:user_id=>context.session[:user]).first + + if context.profile && context.profile.person? and !person.nil? + @person = person + @percentege = calc_percentage_registration(person) + + if @percentege >= 0 and @percentege < 100 + expanded_template('incomplete_registration.html.erb') + end + end + end + + def profile_editor_transaction_extras + single_hash_transactions = { :user => 'user', + :instituton => 'instituton' + } + + single_hash_transactions.each do |model, transaction| + call_model_transaction(model, transaction) + end + end + + def profile_editor_extras + profile = context.profile + + if profile.person? + expanded_template('person_editor_extras.html.erb') + end + end + + + def calc_percentage_registration(person) + required_list = profile_required_list + empty_fields = profile_required_empty_list person + count = required_list[:person_fields].count + + required_list[:user_fields].count + percentege = 100 - ((empty_fields.count * 100) / count) + person.percentage_incomplete = percentege + person.save(validate: false) + percentege + end + + def js_files + %w( + vendor/modulejs-1.5.0.min.js + vendor/jquery.js + lib/noosfero-root.js + views/complete-registration.js + initializer.js + app.js + ) + end + + protected + + def profile_required_list + fields = {} + fields[:person_fields] = %w(cell_phone + contact_phone + comercial_phone + country + city + state + organization_website + image + identifier + name) + + fields[:user_fields] = %w(secondary_email email) + fields + end + + def profile_required_empty_list(person) + empty_fields = [] + required_list = profile_required_list + + required_list[:person_fields].each do |field| + empty_fields << field.sub('_',' ') if person.send(field).blank? + end + required_list[:user_fields].each do |field| + empty_fields << field.sub('_',' ') if person.user.send(field).blank? + end + empty_fields + end + + def user_transaction + user_editor_institution_actions + + User.transaction do + context.profile.user.update_attributes!(context.params[:user]) + end + end + + private + + def call_model_transaction(model,name) + send(name + '_transaction') if context.params.key?(model.to_sym) + end + +end diff --git a/public/app.js b/public/app.js new file mode 100644 index 0000000..7e98375 --- /dev/null +++ b/public/app.js @@ -0,0 +1,11 @@ +(function() { + 'use strict'; + + var $ = modulejs.require('jquery'); + var Initializer = modulejs.require('Initializer'); + + + $(document).ready(function() { + Initializer.init(); + }); +})(); diff --git a/public/initializer.js b/public/initializer.js new file mode 100644 index 0000000..44751b5 --- /dev/null +++ b/public/initializer.js @@ -0,0 +1,28 @@ +(function() { + 'use strict'; + + var dependencies = [ + 'CompleteRegistration', + ]; + + + modulejs.define('Initializer', dependencies, function() { + var __dependencies = arguments; + + + function call_dependency(dependency) { + if( dependency.isCurrentPage() ) { + dependency.init(); + } + } + + + return { + init: function() { + for(var i=0, len = __dependencies.length; i < len; i++) { + call_dependency(__dependencies[i]); + } + } + }; + }); +})(); diff --git a/public/lib/noosfero-root.js b/public/lib/noosfero-root.js new file mode 100644 index 0000000..cd3c8bf --- /dev/null +++ b/public/lib/noosfero-root.js @@ -0,0 +1,13 @@ +modulejs.define('NoosferoRoot', function() { + 'use strict'; + + + function url_with_subdirectory(url) { + return noosfero_root() + url; + } + + + return { + urlWithSubDirectory: url_with_subdirectory + } +}); diff --git a/public/style.css b/public/style.css new file mode 100644 index 0000000..00381f3 --- /dev/null +++ b/public/style.css @@ -0,0 +1,20 @@ +#complete_registration { + padding: 5px; + width: 100%; + background-color: #fff; +} + +#complete_registration a { + text-decoration: none; +} + +#complete_registration a:hover { + font-weight: bold; +} + +#complete_registration_percentage { + width: 100%; + height: 20px; + background: #fff; + border: solid 1px #000; +} diff --git a/public/vendor/jquery.js b/public/vendor/jquery.js new file mode 100644 index 0000000..a3f4ebf --- /dev/null +++ b/public/vendor/jquery.js @@ -0,0 +1,3 @@ +modulejs.define('jquery', function() { + return jQuery; +}); diff --git a/public/vendor/jquery.maskedinput.min.js b/public/vendor/jquery.maskedinput.min.js new file mode 100644 index 0000000..0d9ce6e --- /dev/null +++ b/public/vendor/jquery.maskedinput.min.js @@ -0,0 +1,7 @@ +/* + Masked Input plugin for jQuery + Copyright (c) 2007-2013 Josh Bush (digitalbush.com) + Licensed under the MIT license (http://digitalbush.com/projects/masked-input-plugin/#license) + Version: 1.3.1 +*/ +(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)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); \ No newline at end of file diff --git a/public/vendor/modulejs-1.5.0.min.js b/public/vendor/modulejs-1.5.0.min.js new file mode 100644 index 0000000..9905b63 --- /dev/null +++ b/public/vendor/modulejs-1.5.0.min.js @@ -0,0 +1,2 @@ +/* modulejs 1.5.0 - http://larsjung.de/modulejs/ */ +!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}}}); \ No newline at end of file diff --git a/public/views/complete-registration.js b/public/views/complete-registration.js new file mode 100644 index 0000000..6293cc0 --- /dev/null +++ b/public/views/complete-registration.js @@ -0,0 +1,60 @@ +modulejs.define('CompleteRegistration', ['jquery', 'NoosferoRoot'], function($, NoosferoRoot) { + 'use strict'; + + + var AJAX_URL = { + hide_registration_incomplete_percentage: + NoosferoRoot.urlWithSubDirectory("/plugin/software_communities/hide_registration_incomplete_percentage") + }; + + + function hide_incomplete_percentage(evt) { + evt.preventDefault(); + + jQuery.get(AJAX_URL.hide_registration_incomplete_percentage, {hide:true}, function(response){ + if( response === true ) { + jQuery("#complete_registration").fadeOut(); + } + }); + } + + + function show_complete_progressbar() { + var percentage = jQuery("#complete_registration_message span").html(); + var canvas_tag = document.getElementById("complete_registration_percentage"); + + if( canvas_tag !== null ) { + var context = canvas_tag.getContext("2d"); + + percentage = canvas_tag.width*(percentage/100.0); + + context.beginPath(); + context.rect(0, 0, percentage, canvas_tag.height); + context.fillStyle = '#00FF00'; + context.fill(); + } + } + + + function repositioning_bar_percentage() { + var complete_message = $("#complete_registration").remove(); + + $(".profile-info-options").before(complete_message); + } + + + return { + isCurrentPage: function() { + return $("#complete_registration").length === 1; + }, + + + init: function() { + repositioning_bar_percentage(); + + jQuery(".hide-incomplete-percentage").click(hide_incomplete_percentage); + + show_complete_progressbar(); + } + } +}); diff --git a/test/helpers/plugin_test_helper.rb b/test/helpers/plugin_test_helper.rb new file mode 100644 index 0000000..46ea88f --- /dev/null +++ b/test/helpers/plugin_test_helper.rb @@ -0,0 +1,37 @@ +module PluginTestHelper + def create_person name, email, password, password_confirmation, secondary_email, state, city + user = create_user( + name.to_slug, + email, + password, + password_confirmation, + secondary_email + ) + person = Person::new + + user.person = person + person.user = user + + person.name = name + person.identifier = name.to_slug + person.state = state + person.city = city + + user.save + person.save + + person + end + + def create_user login, email, password, password_confirmation, secondary_email + user = User.new + + user.login = login + user.email = email + user.password = password + user.password_confirmation = password_confirmation + user.secondary_email = secondary_email + + user + end +end diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb new file mode 100644 index 0000000..dd6c628 --- /dev/null +++ b/test/unit/person_test.rb @@ -0,0 +1,43 @@ +require File.dirname(__FILE__) + '/../../../../test/test_helper' +require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' + +class SoftwareCommunitiesPluginPersonTest < ActiveSupport::TestCase + include PluginTestHelper + def setup + @plugin = GovUserPlugin.new + + @user = fast_create(User) + @person = create_person( + "My Name", + "user@email.com", + "123456", + "123456", + "user@secondaryemail.com", + "Any State", + "Some City" + ) + end + + should 'calculate the percentege of person incomplete fields' do + @person.cell_phone = "76888919" + @person.contact_phone = "987654321" + + assert_equal(67, @plugin.calc_percentage_registration(@person)) + + @person.comercial_phone = "11223344" + @person.country = "I dont know" + @person.state = "I dont know" + @person.city = "I dont know" + @person.organization_website = "www.whatever.com" + @person.image = Image::new :uploaded_data=>fixture_file_upload('/files/rails.png', 'image/png') + @person.save + + assert_equal(100, @plugin.calc_percentage_registration(@person)) + end + + should 'return true when the email has not gov.br,jus.br,leg.br or mp.br' do + @user.secondary_email = "test_email@com.br" + @user.email = "test_email@net.br" + assert @user.save + end +end diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb new file mode 100644 index 0000000..82c1900 --- /dev/null +++ b/test/unit/user_test.rb @@ -0,0 +1,138 @@ +require File.dirname(__FILE__) + '/../../../../test/test_helper' +require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' + +class UserTest < ActiveSupport::TestCase + include PluginTestHelper + + should 'not save user whose both email and secondary email are the same' do + user = fast_create(User) + user.email = "test@email.com" + user.secondary_email = "test@email.com" + + assert !user.save + end + + should 'not save user whose email and secondary email have been taken' do + user1 = create_default_user + user2 = fast_create(User) + + user2.email = "primary@email.com" + user2.secondary_email = "secondary@email.com" + assert !user2.save + end + + should 'not save user whose email has already been used' do + user1 = create_default_user + user2 = fast_create(User) + + user2.email = "primary@email.com" + user2.secondary_email = "noosfero@email.com" + assert !user2.save + end + + should 'not save user whose email has been taken another in users secondary email' do + user1 = create_default_user + user2 = fast_create(User) + + user2.login = "another-login" + user2.email = "secondary@email.com" + user2.secondary_email = "noosfero@email.com" + assert !user2.save + end + + should 'not save user whose secondary email has been taken used in another users email' do + user1 = create_default_user + user2 = fast_create(User) + + user2.login = "another-login" + user2.email = "noosfero@email.com" + user2.secondary_email = "primary@email.com" + assert !user2.save + end + + should 'not save user whose secondary email has already been used in another users secondary email' do + user1 = create_default_user + user2 = fast_create(User) + + user2.login = "another-login" + user2.email = "noosfero@email.com" + user2.secondary_email = "secondary@email.com" + assert !user2.save + end + + should 'not save user whose secondary email is in the wrong format' do + user = fast_create(User) + user.email = "test@email.com" + user.secondary_email = "notarightformat.com" + + assert !user.save + + user.secondary_email = "not@arightformatcom" + + assert !user.save + end + + should 'save more than one user without secondary email' do + user = fast_create(User) + user.email = "test@email.com" + user.secondary_email = "" + user.save + + user2 = fast_create(User) + user2.email = "test2@email.com" + user2.secondary_email = "" + assert user2.save + end + + should 'return an error if secondary email is governmental and primary is not' do + invalid_msg = "The governamental email must be the primary one." + user = fast_create(User) + + user.email = "test@email.com" + user.secondary_email = "test@gov.br" + + assert !user.save + assert user.errors.full_messages.include?(invalid_msg) + end + + # should 'have institution if email is governmental' do + # user = fast_create(User) + # + # user.email = "testtest@gov.br" + # + # user.institutions = [] + # assert !user.save, "this should not save" + # + # gov_power = GovernmentalPower.create(:name=>"Some Gov Power") + # gov_sphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") + # juridical_nature = JuridicalNature.create(:name => "Autarquia") + # institution = create_public_institution( + # "Ministerio Publico da Uniao", + # "MPU", + # "BR", + # "DF", + # "Gama", + # juridical_nature, + # gov_power, + # gov_sphere, + # "44.555.666/7777-88" + # ) + # institution.save! + # + # user.institutions << institution + # assert user.save, "this should save" + # end + + private + + def create_default_user + user = fast_create(User) + user.login = "a-login" + user.email = "primary@email.com" + user.secondary_email = "secondary@email.com" + user.save + + return user + end + +end diff --git a/views/incomplete_registration.html.erb b/views/incomplete_registration.html.erb new file mode 100644 index 0000000..d1dceba --- /dev/null +++ b/views/incomplete_registration.html.erb @@ -0,0 +1,11 @@ +
+
+
<%= _("Complete Profile")+": #{@percentege}%" %>
+ +
+ <%= link_to _("Complete your profile"), "#{Noosfero.root}/myprofile/#{@person.identifier}/profile_editor/edit" %> | + <%= link_to _("Hide"), "#", :class=>"hide-incomplete-percentage" %> +
+
+
+ diff --git a/views/person_editor_extras.html.erb b/views/person_editor_extras.html.erb new file mode 100644 index 0000000..a0a58ca --- /dev/null +++ b/views/person_editor_extras.html.erb @@ -0,0 +1,12 @@ +
+ <%= label_tag "user[secondary_email]", _('Secondary e-mail')+":", :class=>"formlabel" %> + +
+ <%= text_field_tag "user[secondary_email]", context.profile.user.secondary_email %> +
+
+ +<%= hidden_field_tag("full_name_error", _("Should begin with a capital letter and no special characters")) %> +<%= hidden_field_tag("email_error", _("Email should have the following format: name@host.br")) %> +<%= hidden_field_tag("site_error", _("Site should have a valid format: http://name.hosts")) %> +
<%= _("If you work in a public agency use your government e-Mail") %>
-- libgit2 0.21.2