Commit 1ea734898ee0b66b093bde6469d691215ca2c447
Committed by
Daniela Feitosa
1 parent
5c1641f3
Exists in
master
and in
27 other branches
curriculum_lattes_plugin: Refactoring to use load_plugin_filters hotspot
Showing
18 changed files
with
198 additions
and
118 deletions
Show diff stats
app/controllers/admin/features_controller.rb
| @@ -17,10 +17,6 @@ class FeaturesController < AdminController | @@ -17,10 +17,6 @@ class FeaturesController < AdminController | ||
| 17 | 17 | ||
| 18 | def manage_fields | 18 | def manage_fields |
| 19 | @person_fields = Person.fields | 19 | @person_fields = Person.fields |
| 20 | - @plugins.dispatch(:extra_person_fields).collect do |field| | ||
| 21 | - @person_fields << field unless @person_fields.include?(field) | ||
| 22 | - end | ||
| 23 | - | ||
| 24 | @enterprise_fields = Enterprise.fields | 20 | @enterprise_fields = Enterprise.fields |
| 25 | @community_fields = Community.fields | 21 | @community_fields = Community.fields |
| 26 | end | 22 | end |
app/controllers/my_profile/profile_editor_controller.rb
| @@ -16,21 +16,15 @@ class ProfileEditorController < MyProfileController | @@ -16,21 +16,15 @@ class ProfileEditorController < MyProfileController | ||
| 16 | if request.post? | 16 | if request.post? |
| 17 | params[:profile_data][:fields_privacy] ||= {} if profile.person? && params[:profile_data].is_a?(Hash) | 17 | params[:profile_data][:fields_privacy] ||= {} if profile.person? && params[:profile_data].is_a?(Hash) |
| 18 | begin | 18 | begin |
| 19 | - @plugins.dispatch(:profile_editor_transaction_extras) | ||
| 20 | - | ||
| 21 | Profile.transaction do | 19 | Profile.transaction do |
| 22 | Image.transaction do | 20 | Image.transaction do |
| 23 | - if @profile_data.update_attributes(params[:profile_data]) | ||
| 24 | - redirect_to :action => 'index', :profile => profile.identifier | ||
| 25 | - else | ||
| 26 | - profile.identifier = params[:profile] if profile.identifier.blank? | ||
| 27 | - end | 21 | + @plugins.dispatch(:profile_editor_transaction_extras) |
| 22 | + @profile_data.update_attributes!(params[:profile_data]) | ||
| 23 | + redirect_to :action => 'index', :profile => profile.identifier | ||
| 28 | end | 24 | end |
| 29 | end | 25 | end |
| 30 | rescue Exception => ex | 26 | rescue Exception => ex |
| 31 | - if profile.identifier.blank? | ||
| 32 | - profile.identifier = params[:profile] | ||
| 33 | - end | 27 | + profile.identifier = params[:profile] if profile.identifier.blank? |
| 34 | end | 28 | end |
| 35 | end | 29 | end |
| 36 | end | 30 | end |
app/controllers/public/account_controller.rb
| @@ -93,13 +93,7 @@ class AccountController < ApplicationController | @@ -93,13 +93,7 @@ class AccountController < ApplicationController | ||
| 93 | @user.terms_of_use = environment.terms_of_use | 93 | @user.terms_of_use = environment.terms_of_use |
| 94 | @user.environment = environment | 94 | @user.environment = environment |
| 95 | @terms_of_use = environment.terms_of_use | 95 | @terms_of_use = environment.terms_of_use |
| 96 | - | ||
| 97 | - params_profile_data = params[:profile_data] | ||
| 98 | - @plugins.dispatch(:extra_person_data_params).each do |data| | ||
| 99 | - params_profile_data = params_profile_data.merge(data) unless params[:profile_data].blank? | ||
| 100 | - end | ||
| 101 | - | ||
| 102 | - @user.person_data = params_profile_data | 96 | + @user.person_data = params[:profile_data] |
| 103 | @user.return_to = session[:return_to] | 97 | @user.return_to = session[:return_to] |
| 104 | @person = Person.new(params[:profile_data]) | 98 | @person = Person.new(params[:profile_data]) |
| 105 | @person.environment = @user.environment | 99 | @person.environment = @user.environment |
app/models/user.rb
| @@ -29,8 +29,6 @@ class User < ActiveRecord::Base | @@ -29,8 +29,6 @@ class User < ActiveRecord::Base | ||
| 29 | alias_method_chain :human_attribute_name, :customization | 29 | alias_method_chain :human_attribute_name, :customization |
| 30 | end | 30 | end |
| 31 | 31 | ||
| 32 | - include Noosfero::Plugin::HotSpot | ||
| 33 | - | ||
| 34 | before_create do |user| | 32 | before_create do |user| |
| 35 | if user.environment.nil? | 33 | if user.environment.nil? |
| 36 | user.environment = Environment.default | 34 | user.environment = Environment.default |
| @@ -48,7 +46,6 @@ class User < ActiveRecord::Base | @@ -48,7 +46,6 @@ class User < ActiveRecord::Base | ||
| 48 | p.environment = user.environment | 46 | p.environment = user.environment |
| 49 | p.name ||= user.name || user.login | 47 | p.name ||= user.name || user.login |
| 50 | p.visible = false unless user.activated? | 48 | p.visible = false unless user.activated? |
| 51 | - | ||
| 52 | p.save! | 49 | p.save! |
| 53 | 50 | ||
| 54 | user.person = p | 51 | user.person = p |
db/schema.rb
| 1 | # encoding: UTF-8 | 1 | # encoding: UTF-8 |
| 2 | # This file is auto-generated from the current state of the database. Instead | 2 | # This file is auto-generated from the current state of the database. Instead |
| 3 | # of editing this file, please use the migrations feature of Active Record to | 3 | # of editing this file, please use the migrations feature of Active Record to |
| 4 | +# incrementally modify your database, and then regenerate this schema definition. | ||
| 4 | # | 5 | # |
| 5 | # Note that this schema.rb definition is the authoritative source for your | 6 | # Note that this schema.rb definition is the authoritative source for your |
| 6 | # database schema. If you need to create the application database on another | 7 | # database schema. If you need to create the application database on another |
features/step_definitions/noosfero_steps.rb
| @@ -762,3 +762,11 @@ When /^I confirm the "(.*)" dialog$/ do |confirmation| | @@ -762,3 +762,11 @@ When /^I confirm the "(.*)" dialog$/ do |confirmation| | ||
| 762 | assert_equal confirmation, a.text | 762 | assert_equal confirmation, a.text |
| 763 | a.accept | 763 | a.accept |
| 764 | end | 764 | end |
| 765 | + | ||
| 766 | +Given /^the field (.*) is public for all users$/ do |field| | ||
| 767 | + Person.all.each do |person| | ||
| 768 | + person.fields_privacy = Hash.new if person.fields_privacy.nil? | ||
| 769 | + person.fields_privacy[field] = "public" | ||
| 770 | + person.save! | ||
| 771 | + end | ||
| 772 | +end | ||
| 765 | \ No newline at end of file | 773 | \ No newline at end of file |
lib/noosfero/plugin.rb
| @@ -537,23 +537,12 @@ class Noosfero::Plugin | @@ -537,23 +537,12 @@ class Noosfero::Plugin | ||
| 537 | nil | 537 | nil |
| 538 | end | 538 | end |
| 539 | 539 | ||
| 540 | - # -> Return a list of extra person fields | ||
| 541 | - # returns = a list of strings with fields' name | ||
| 542 | - def extra_person_fields | ||
| 543 | - [] | ||
| 544 | - end | ||
| 545 | - | ||
| 546 | # -> Return a list of hashs with the needed information to create optional fields | 540 | # -> Return a list of hashs with the needed information to create optional fields |
| 547 | # returns = a list of hashs as {:name => "string", :label => "string", :object_name => :key, :method => :key} | 541 | # returns = a list of hashs as {:name => "string", :label => "string", :object_name => :key, :method => :key} |
| 548 | def extra_optional_fields | 542 | def extra_optional_fields |
| 549 | [] | 543 | [] |
| 550 | end | 544 | end |
| 551 | 545 | ||
| 552 | - # -> Return a hash with another object's params | ||
| 553 | - def extra_person_data_params | ||
| 554 | - {} | ||
| 555 | - end | ||
| 556 | - | ||
| 557 | # -> Adds additional blocks to profiles and environments. | 546 | # -> Adds additional blocks to profiles and environments. |
| 558 | # Your plugin must implements a class method called 'extra_blocks' | 547 | # Your plugin must implements a class method called 'extra_blocks' |
| 559 | # that returns a hash with the following syntax. | 548 | # that returns a hash with the following syntax. |
| @@ -0,0 +1,45 @@ | @@ -0,0 +1,45 @@ | ||
| 1 | +README - Lattes Curriculum (LattesCurriculum Plugin) | ||
| 2 | +================================ | ||
| 3 | + | ||
| 4 | +Lattes Curriculum is a plugin that allow users to show their academic informations in the wall, extracted from CNPQ's lattes plataform | ||
| 5 | + | ||
| 6 | +INSTALL | ||
| 7 | +======= | ||
| 8 | + | ||
| 9 | +Enable Plugin | ||
| 10 | +------------- | ||
| 11 | + | ||
| 12 | +Also, you need to enable LattesCurriculum Plugin on your Noosfero: | ||
| 13 | + | ||
| 14 | +cd <your_noosfero_dir> | ||
| 15 | +./script/noosfero-plugins enable lattes_curriculum | ||
| 16 | + | ||
| 17 | +Active Plugin | ||
| 18 | +------------- | ||
| 19 | + | ||
| 20 | +As a Noosfero administrator user, go to administrator panel: | ||
| 21 | + | ||
| 22 | +- Click on "Enable/disable plugins" option | ||
| 23 | +- Click on "LattesCurriculumPlugin" check-box | ||
| 24 | + | ||
| 25 | +Running LattesCurriculum tests | ||
| 26 | +-------------------- | ||
| 27 | + | ||
| 28 | +$ rake test:noosfero_plugins:lattes_curriculum | ||
| 29 | + | ||
| 30 | +LICENSE | ||
| 31 | +======= | ||
| 32 | + | ||
| 33 | +Copyright (c) The Author developers. | ||
| 34 | + | ||
| 35 | +See Noosfero license. | ||
| 36 | + | ||
| 37 | + | ||
| 38 | +AUTHORS | ||
| 39 | +======= | ||
| 40 | + | ||
| 41 | +Jose Pedro (1jpsneto at gmail.com) | ||
| 42 | +Thiago Kairala (thiagor.kairala at gmail.com) | ||
| 43 | +Ana Paula Vargas (anapaulavnoronha at gmail.com) | ||
| 44 | +Leandro Veloso (leandrovelosorodrigues at gmail.com) | ||
| 45 | +Arthur Del Esposte (arthurmde at gmail.com) | ||
| 0 | \ No newline at end of file | 46 | \ No newline at end of file |
plugins/lattes_curriculum/db/migrate/20140814210103_create_academic_infos.rb
| 1 | class CreateAcademicInfos < ActiveRecord::Migration | 1 | class CreateAcademicInfos < ActiveRecord::Migration |
| 2 | def self.up | 2 | def self.up |
| 3 | - create_table :academic_infos do |t| | ||
| 4 | - t.references :person | 3 | + create_table :academic_infos do |t| |
| 4 | + t.references :person | ||
| 5 | t.column :lattes_url, :string | 5 | t.column :lattes_url, :string |
| 6 | end | 6 | end |
| 7 | - end | 7 | + end |
| 8 | 8 | ||
| 9 | def self.down | 9 | def self.down |
| 10 | drop_table :academic_infos | 10 | drop_table :academic_infos |
plugins/lattes_curriculum/features/lattes_curriculum.feature
| @@ -7,55 +7,43 @@ Feature: import lattes information | @@ -7,55 +7,43 @@ Feature: import lattes information | ||
| 7 | Given "LattesCurriculumPlugin" plugin is enabled | 7 | Given "LattesCurriculumPlugin" plugin is enabled |
| 8 | And I am logged in as admin | 8 | And I am logged in as admin |
| 9 | And I go to /admin/plugins | 9 | And I go to /admin/plugins |
| 10 | - And I check "LattesCurriculumPlugin" | 10 | + And I check "Lattes Curriculum Plugin" |
| 11 | And I press "Save changes" | 11 | And I press "Save changes" |
| 12 | And I go to /admin/features/manage_fields | 12 | And I go to /admin/features/manage_fields |
| 13 | Given I follow "Person's fields" | 13 | Given I follow "Person's fields" |
| 14 | And I check "person_fields_lattes_url_active" | 14 | And I check "person_fields_lattes_url_active" |
| 15 | And I check "person_fields_lattes_url_signup" | 15 | And I check "person_fields_lattes_url_signup" |
| 16 | And I press "save_person_fields" | 16 | And I press "save_person_fields" |
| 17 | - And feature "skip_new_user_email_confirmation" is enabled on environment | ||
| 18 | - And I am not logged in | ||
| 19 | 17 | ||
| 20 | - @selenium | ||
| 21 | - Scenario: Import lattes informations after singup | ||
| 22 | - Given I am on signup page | ||
| 23 | - When I fill in "e-Mail" with "josesilva@example.com" | ||
| 24 | - And I fill in "Username" with "josesilva" | ||
| 25 | - And I fill in "Full name" with "João Silva" | ||
| 26 | - And I fill in "Password" with "secret" | ||
| 27 | - And I fill in "Password confirmation" with "secret" | 18 | + Scenario: Don't accept edit the profile with invalid lattes url |
| 19 | + Given I am on admin_user's control panel | ||
| 20 | + When I follow "Edit Profile" | ||
| 21 | + And I fill in "Lattes URL" with "http://youtube.com.br/" | ||
| 22 | + And I press "Save" | ||
| 23 | + Then I should see "Academic info lattes url is invalid" | ||
| 24 | + | ||
| 25 | + Scenario: Import lattes informations | ||
| 26 | + Given I am on admin_user's control panel | ||
| 27 | + And the field lattes_url is public for all users | ||
| 28 | + When I follow "Edit Profile" | ||
| 28 | And I fill in "Lattes URL" with "http://lattes.cnpq.br/2864976228727880" | 29 | And I fill in "Lattes URL" with "http://lattes.cnpq.br/2864976228727880" |
| 29 | - And wait for the captcha signup time | ||
| 30 | - And I press "Create my account" | ||
| 31 | - And I go to /profile/josesilva | ||
| 32 | - And I follow "Lattes" within "#ui-tabs-anchor" | 30 | + And I press "Save" |
| 31 | + And I go to /profile/admin_user#lattes_tab | ||
| 33 | Then I should see "Endereço para acessar este CV: http://lattes.cnpq.br/2864976228727880" | 32 | Then I should see "Endereço para acessar este CV: http://lattes.cnpq.br/2864976228727880" |
| 34 | 33 | ||
| 35 | - @selenium | ||
| 36 | Scenario: Don't show lattes informations for blank lattes urls | 34 | Scenario: Don't show lattes informations for blank lattes urls |
| 37 | - Given I am on signup page | ||
| 38 | - When I fill in "e-Mail" with "josesilva@example.com" | ||
| 39 | - And I fill in "Username" with "josesilva" | ||
| 40 | - And I fill in "Full name" with "João Silva" | ||
| 41 | - And I fill in "Password" with "secret" | ||
| 42 | - And I fill in "Password confirmation" with "secret" | ||
| 43 | - And wait for the captcha signup time | ||
| 44 | - And I press "Create my account" | ||
| 45 | - And I go to /profile/josesilva | ||
| 46 | - Then I should not see "Lattes" within "#ui-tabs-anchor" | 35 | + Given I am on admin_user's control panel |
| 36 | + And the field lattes_url is public for all users | ||
| 37 | + When I follow "Edit Profile" | ||
| 38 | + And I press "Save" | ||
| 39 | + And I go to /profile/admin_user | ||
| 40 | + Then I should not see "Lattes" | ||
| 47 | 41 | ||
| 48 | - @selenium | ||
| 49 | Scenario: Inform problem if the informed lattes doesn't exist | 42 | Scenario: Inform problem if the informed lattes doesn't exist |
| 50 | - Given I am on signup page | ||
| 51 | - When I fill in "e-Mail" with "josesilva@example.com" | ||
| 52 | - And I fill in "Username" with "josesilva" | ||
| 53 | - And I fill in "Full name" with "João Silva" | ||
| 54 | - And I fill in "Password" with "secret" | ||
| 55 | - And I fill in "Password confirmation" with "secret" | 43 | + Given I am on admin_user's control panel |
| 44 | + And the field lattes_url is public for all users | ||
| 45 | + When I follow "Edit Profile" | ||
| 56 | And I fill in "Lattes URL" with "http://lattes.cnpq.br/123456" | 46 | And I fill in "Lattes URL" with "http://lattes.cnpq.br/123456" |
| 57 | - And wait for the captcha signup time | ||
| 58 | - And I press "Create my account" | ||
| 59 | - And I go to /profile/josesilva | ||
| 60 | - And I follow "Lattes" within "#ui-tabs-anchor" | 47 | + And I press "Save" |
| 48 | + And I go to /profile/admin_user#lattes_tab | ||
| 61 | Then I should see "Lattes not found. Please, make sure the informed URL is correct." | 49 | Then I should see "Lattes not found. Please, make sure the informed URL is correct." |
| 62 | \ No newline at end of file | 50 | \ No newline at end of file |
plugins/lattes_curriculum/lib/academic_info.rb
| 1 | class AcademicInfo < ActiveRecord::Base | 1 | class AcademicInfo < ActiveRecord::Base |
| 2 | 2 | ||
| 3 | - belongs_to :person | 3 | + belongs_to :person |
| 4 | 4 | ||
| 5 | - attr_accessible :lattes_url | 5 | + attr_accessible :lattes_url |
| 6 | validate :lattes_url_validate? | 6 | validate :lattes_url_validate? |
| 7 | 7 | ||
| 8 | def lattes_url_validate? | 8 | def lattes_url_validate? |
| 9 | - valid_url_start = 'http://lattes.cnpq.br/' | ||
| 10 | - unless self.lattes_url.blank? || self.lattes_url =~ /http:\/\/lattes.cnpq.br\/\d+/ | ||
| 11 | - self.errors.add(:lattes_url, _("Sorry, the lattes url is not valid.")) | 9 | + unless AcademicInfo.matches?(self.lattes_url) |
| 10 | + self.errors.add(:lattes_url, _(" is invalid.")) | ||
| 12 | end | 11 | end |
| 13 | end | 12 | end |
| 13 | + | ||
| 14 | + def self.matches?(info) | ||
| 15 | + lattes = nil | ||
| 16 | + if info.class == String | ||
| 17 | + lattes = info | ||
| 18 | + elsif info.class == Hash | ||
| 19 | + lattes = info[:lattes_url] | ||
| 20 | + end | ||
| 21 | + return lattes.blank? || lattes =~ /^http:\/\/lattes.cnpq.br\/\d+$/ | ||
| 22 | + end | ||
| 14 | end | 23 | end |
plugins/lattes_curriculum/lib/ext/person.rb
| @@ -15,4 +15,6 @@ class Person | @@ -15,4 +15,6 @@ class Person | ||
| 15 | def lattes_url= value | 15 | def lattes_url= value |
| 16 | self.academic_info.lattes_url = value unless self.academic_info.nil? | 16 | self.academic_info.lattes_url = value unless self.academic_info.nil? |
| 17 | end | 17 | end |
| 18 | + | ||
| 19 | + FIELDS << "lattes_url" | ||
| 18 | end | 20 | end |
plugins/lattes_curriculum/lib/html_parser.rb
| @@ -6,8 +6,8 @@ Encoding.default_external = Encoding::UTF_8 | @@ -6,8 +6,8 @@ Encoding.default_external = Encoding::UTF_8 | ||
| 6 | Encoding.default_internal = Encoding::UTF_8 | 6 | Encoding.default_internal = Encoding::UTF_8 |
| 7 | 7 | ||
| 8 | class Html_parser | 8 | class Html_parser |
| 9 | - def get_html(lattes_link = "") | ||
| 10 | - begin | 9 | + def get_html(lattes_link = "") |
| 10 | + begin | ||
| 11 | page = Nokogiri::HTML(open(lattes_link), nil, "UTF-8") | 11 | page = Nokogiri::HTML(open(lattes_link), nil, "UTF-8") |
| 12 | page = page.css(".main-content").to_s() | 12 | page = page.css(".main-content").to_s() |
| 13 | page = remove_class_tooltip(page) | 13 | page = remove_class_tooltip(page) |
| @@ -17,8 +17,10 @@ class Html_parser | @@ -17,8 +17,10 @@ class Html_parser | ||
| 17 | page = remove_further_informations(page) | 17 | page = remove_further_informations(page) |
| 18 | rescue OpenURI::HTTPError => e | 18 | rescue OpenURI::HTTPError => e |
| 19 | page = _("Lattes not found. Please, make sure the informed URL is correct.") | 19 | page = _("Lattes not found. Please, make sure the informed URL is correct.") |
| 20 | - end | ||
| 21 | - end | 20 | + rescue Timeout::Error => e |
| 21 | + page = _("Lattes Platform is unreachable. Please, try it later.") | ||
| 22 | + end | ||
| 23 | + end | ||
| 22 | 24 | ||
| 23 | def remove_class_tooltip(page = "") | 25 | def remove_class_tooltip(page = "") |
| 24 | while page.include? 'class="tooltip"' do | 26 | while page.include? 'class="tooltip"' do |
plugins/lattes_curriculum/lib/lattes_curriculum_plugin.rb
| 1 | class LattesCurriculumPlugin < Noosfero::Plugin | 1 | class LattesCurriculumPlugin < Noosfero::Plugin |
| 2 | 2 | ||
| 3 | def self.plugin_name | 3 | def self.plugin_name |
| 4 | - "LattesCurriculumPlugin" | 4 | + "Lattes Curriculum Plugin" |
| 5 | end | 5 | end |
| 6 | 6 | ||
| 7 | def self.plugin_description | 7 | def self.plugin_description |
| @@ -17,10 +17,6 @@ class LattesCurriculumPlugin < Noosfero::Plugin | @@ -17,10 +17,6 @@ class LattesCurriculumPlugin < Noosfero::Plugin | ||
| 17 | end | 17 | end |
| 18 | 18 | ||
| 19 | def extra_optional_fields | 19 | def extra_optional_fields |
| 20 | - if context.profile && context.profile.person? && context.profile.academic_info.nil? | ||
| 21 | - context.profile.academic_info = AcademicInfo.new | ||
| 22 | - end | ||
| 23 | - | ||
| 24 | fields = [] | 20 | fields = [] |
| 25 | 21 | ||
| 26 | lattes_url = { | 22 | lattes_url = { |
| @@ -36,20 +32,8 @@ class LattesCurriculumPlugin < Noosfero::Plugin | @@ -36,20 +32,8 @@ class LattesCurriculumPlugin < Noosfero::Plugin | ||
| 36 | return fields | 32 | return fields |
| 37 | end | 33 | end |
| 38 | 34 | ||
| 39 | - def extra_person_fields | ||
| 40 | - fields = [] | ||
| 41 | - | ||
| 42 | - fields << "lattes_url" | ||
| 43 | - | ||
| 44 | - return fields | ||
| 45 | - end | ||
| 46 | - | ||
| 47 | - def extra_person_data_params | ||
| 48 | - {"academic_info_attributes" => context.params[:academic_infos]} | ||
| 49 | - end | ||
| 50 | - | ||
| 51 | def profile_tabs | 35 | def profile_tabs |
| 52 | - unless context.profile.academic_info.nil? || context.profile.academic_info.lattes_url.blank? | 36 | + if show_lattes_tab? |
| 53 | href = context.profile.academic_info.lattes_url | 37 | href = context.profile.academic_info.lattes_url |
| 54 | html_parser = Html_parser.new | 38 | html_parser = Html_parser.new |
| 55 | { | 39 | { |
| @@ -69,6 +53,78 @@ class LattesCurriculumPlugin < Noosfero::Plugin | @@ -69,6 +53,78 @@ class LattesCurriculumPlugin < Noosfero::Plugin | ||
| 69 | end | 53 | end |
| 70 | end | 54 | end |
| 71 | 55 | ||
| 56 | + def profile_editor_controller_filters | ||
| 57 | + validate_lattes_url_block = proc do | ||
| 58 | + if request.post? | ||
| 59 | + if !params[:academic_infos].blank? | ||
| 60 | + @profile_data = profile | ||
| 61 | + | ||
| 62 | + academic_infos = {"academic_info_attributes" => params[:academic_infos]} | ||
| 63 | + | ||
| 64 | + params_profile_data = params[:profile_data] | ||
| 65 | + params_profile_data = params_profile_data.merge(academic_infos) | ||
| 66 | + | ||
| 67 | + @profile_data.attributes = params_profile_data | ||
| 68 | + @profile_data.valid? | ||
| 69 | + | ||
| 70 | + @possible_domains = profile.possible_domains | ||
| 71 | + | ||
| 72 | + unless AcademicInfo.matches?(params[:academic_infos]) | ||
| 73 | + @profile_data.errors.add(:lattes_url, _(' Invalid lattes url')) | ||
| 74 | + render :action => :edit, :profile => profile.identifier | ||
| 75 | + end | ||
| 76 | + end | ||
| 77 | + end | ||
| 78 | + end | ||
| 79 | + | ||
| 80 | + create_academic_info_block = proc do | ||
| 81 | + if profile && profile.person? && profile.academic_info.nil? | ||
| 82 | + profile.academic_info = AcademicInfo.new | ||
| 83 | + end | ||
| 84 | + end | ||
| 85 | + | ||
| 86 | + [{:type => 'before_filter', | ||
| 87 | + :method_name => 'validate_lattes_url', | ||
| 88 | + :options => {:only => 'edit'}, | ||
| 89 | + :block => validate_lattes_url_block }, | ||
| 90 | + {:type => 'before_filter', | ||
| 91 | + :method_name => 'create_academic_info', | ||
| 92 | + :options => {:only => 'edit'}, | ||
| 93 | + :block => create_academic_info_block }] | ||
| 94 | + end | ||
| 95 | + | ||
| 96 | + def account_controller_filters | ||
| 97 | + validate_lattes_url_block = proc do | ||
| 98 | + if request.post? | ||
| 99 | + params[:profile_data] ||= {} | ||
| 100 | + params[:profile_data][:academic_info_attributes] = params[:academic_infos] | ||
| 101 | + | ||
| 102 | + if !params[:academic_infos].blank? && !AcademicInfo.matches?(params[:academic_infos]) | ||
| 103 | + @person = Person.new(params[:profile_data]) | ||
| 104 | + @person.environment = environment | ||
| 105 | + @user = User.new(params[:user]) | ||
| 106 | + @person.errors.add(:lattes_url, _(' Invalid lattes url')) | ||
| 107 | + render :action => :signup | ||
| 108 | + end | ||
| 109 | + end | ||
| 110 | + end | ||
| 111 | + | ||
| 112 | + create_academic_info_block = proc do | ||
| 113 | + if profile && profile.person? && profile.academic_info.nil? | ||
| 114 | + profile.academic_info = AcademicInfo.new | ||
| 115 | + end | ||
| 116 | + end | ||
| 117 | + | ||
| 118 | + [{:type => 'before_filter', | ||
| 119 | + :method_name => 'validate_lattes_url', | ||
| 120 | + :options => {:only => 'signup'}, | ||
| 121 | + :block => validate_lattes_url_block }, | ||
| 122 | + {:type => 'before_filter', | ||
| 123 | + :method_name => 'create_academic_info', | ||
| 124 | + :options => {:only => 'edit'}, | ||
| 125 | + :block => create_academic_info_block }] | ||
| 126 | + end | ||
| 127 | + | ||
| 72 | protected | 128 | protected |
| 73 | 129 | ||
| 74 | def academic_info_transaction | 130 | def academic_info_transaction |
| @@ -77,4 +133,7 @@ class LattesCurriculumPlugin < Noosfero::Plugin | @@ -77,4 +133,7 @@ class LattesCurriculumPlugin < Noosfero::Plugin | ||
| 77 | end | 133 | end |
| 78 | end | 134 | end |
| 79 | 135 | ||
| 136 | + def show_lattes_tab? | ||
| 137 | + return context.profile.person? && !context.profile.academic_info.nil? && !context.profile.academic_info.lattes_url.blank? && context.profile.public_fields.include?("lattes_url") | ||
| 138 | + end | ||
| 80 | end | 139 | end |
plugins/lattes_curriculum/public/singup_complement.js
| 1 | jQuery(function($){ | 1 | jQuery(function($){ |
| 2 | - $(document).ready(function(){ | ||
| 3 | - $('#lattes_id_field').blur(function(){ | ||
| 4 | - var value = this.value | ||
| 5 | - }) | 2 | + $(document).ready(function(){ |
| 3 | + $('#lattes_id_field').blur(function(){ | ||
| 4 | + var value = this.value | ||
| 5 | + }) | ||
| 6 | 6 | ||
| 7 | - $('#lattes_id_field').focus(function(){ | ||
| 8 | - $('#lattes-id-balloon').fadeIn('slow') | ||
| 9 | - }) | 7 | + $('#lattes_id_field').focus(function(){ |
| 8 | + $('#lattes-id-balloon').fadeIn('slow') | ||
| 9 | + }) | ||
| 10 | 10 | ||
| 11 | - $('#lattes_id_field').blur(function(){ | ||
| 12 | - $('#lattes-id-balloon').fadeOut('slow') | ||
| 13 | - }) | ||
| 14 | - }) | 11 | + $('#lattes_id_field').blur(function(){ |
| 12 | + $('#lattes-id-balloon').fadeOut('slow') | ||
| 13 | + }) | ||
| 14 | + }) | ||
| 15 | }) | 15 | }) |
| 16 | \ No newline at end of file | 16 | \ No newline at end of file |
plugins/lattes_curriculum/test/unit/academic_info_test.rb
| @@ -20,6 +20,4 @@ class AcademicInfoTest < ActiveSupport::TestCase | @@ -20,6 +20,4 @@ class AcademicInfoTest < ActiveSupport::TestCase | ||
| 20 | @academic_info.lattes_url = "http://lattes.cnpq.br/2193972715230641" | 20 | @academic_info.lattes_url = "http://lattes.cnpq.br/2193972715230641" |
| 21 | assert @academic_info.save | 21 | assert @academic_info.save |
| 22 | end | 22 | end |
| 23 | - | ||
| 24 | - | ||
| 25 | end | 23 | end |
plugins/lattes_curriculum/test/unit/html_parser_test.rb
| @@ -21,5 +21,4 @@ class HtmlParserTest < ActiveSupport::TestCase | @@ -21,5 +21,4 @@ class HtmlParserTest < ActiveSupport::TestCase | ||
| 21 | should 'inform that lattes was not found' do | 21 | should 'inform that lattes was not found' do |
| 22 | assert_equal "Lattes not found. Please, make sure the informed URL is correct.", @parser.get_html("http://lattes.cnpq.br/123") | 22 | assert_equal "Lattes not found. Please, make sure the informed URL is correct.", @parser.get_html("http://lattes.cnpq.br/123") |
| 23 | end | 23 | end |
| 24 | - | ||
| 25 | end | 24 | end |
plugins/lattes_curriculum/test/unit/lattes_curriculum_test.rb
| @@ -11,7 +11,7 @@ class LattesCurriculumPluginTest < ActiveSupport::TestCase | @@ -11,7 +11,7 @@ class LattesCurriculumPluginTest < ActiveSupport::TestCase | ||
| 11 | end | 11 | end |
| 12 | 12 | ||
| 13 | should 'have name' do | 13 | should 'have name' do |
| 14 | - assert_equal 'LattesCurriculumPlugin', LattesCurriculumPlugin.plugin_name | 14 | + assert_equal 'Lattes Curriculum Plugin', LattesCurriculumPlugin.plugin_name |
| 15 | end | 15 | end |
| 16 | 16 | ||
| 17 | should 'have description' do | 17 | should 'have description' do |
| @@ -21,5 +21,4 @@ class LattesCurriculumPluginTest < ActiveSupport::TestCase | @@ -21,5 +21,4 @@ class LattesCurriculumPluginTest < ActiveSupport::TestCase | ||
| 21 | should 'have stylesheet' do | 21 | should 'have stylesheet' do |
| 22 | assert @plugin.stylesheet? | 22 | assert @plugin.stylesheet? |
| 23 | end | 23 | end |
| 24 | - | ||
| 25 | end | 24 | end |