From 05b6b3868ceed5b14c11afce1068f28fee8488c6 Mon Sep 17 00:00:00 2001 From: Leandro Nunes dos Santos Date: Mon, 2 Jun 2014 19:21:31 -0300 Subject: [PATCH] merging with branch AI3033-serpro_integration of rails 2.3 --- app/controllers/public/account_controller.rb | 26 ++++++++++++++++++++------ app/controllers/public/profile_controller.rb | 21 ++++++--------------- app/models/user.rb | 6 +++++- features/login.feature | 15 +++++++++++++++ features/signup.feature | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ plugins/serpro_integration/controllers/serpro_integration_plugin_myprofile_controller.rb | 13 +++++++++++++ plugins/serpro_integration/features/sonar.feature | 15 +++++++++++++++ plugins/serpro_integration/install.rb | 2 ++ plugins/serpro_integration/lib/ext/community.rb | 220 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/serpro_integration/lib/ext/profile.rb | 9 +++++++++ plugins/serpro_integration/lib/serpro_integration_plugin.rb | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/serpro_integration/lib/serpro_integration_plugin/smile_block.rb | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/serpro_integration/lib/serpro_integration_plugin/sonar_widget_block.rb | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/serpro_integration/public/smile_face.js | 129 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/serpro_integration/public/style.css | 3 +++ plugins/serpro_integration/smile.html | 142 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/serpro_integration/test/unit/sonar_plugin_test.rb | 41 +++++++++++++++++++++++++++++++++++++++++ plugins/serpro_integration/views/profile-editor-extras.html.erb | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ plugins/serpro_integration/views/profile_design/sonar_plugin/_sonar_widget_block.rhtml | 4 ++++ plugins/serpro_integration/views/profile_editor/_gitlab.html.erb | 22 ++++++++++++++++++++++ plugins/serpro_integration/views/sonar_widget_block.rhtml | 10 ++++++++++ test/fixtures/files/500.html | 1 - test/fixtures/files/500.html | 151 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/functional/profile_controller_test.rb | 31 ++++++++++++++----------------- test/functional/profile_editor_controller_test.rb | 17 +++++++++++++++++ 25 files changed, 1180 insertions(+), 40 deletions(-) create mode 100644 plugins/serpro_integration/controllers/serpro_integration_plugin_myprofile_controller.rb create mode 100644 plugins/serpro_integration/features/sonar.feature create mode 100644 plugins/serpro_integration/install.rb create mode 100644 plugins/serpro_integration/lib/ext/community.rb create mode 100644 plugins/serpro_integration/lib/ext/profile.rb create mode 100644 plugins/serpro_integration/lib/serpro_integration_plugin.rb create mode 100644 plugins/serpro_integration/lib/serpro_integration_plugin/smile_block.rb create mode 100644 plugins/serpro_integration/lib/serpro_integration_plugin/sonar_widget_block.rb create mode 100644 plugins/serpro_integration/public/smile_face.js create mode 100644 plugins/serpro_integration/public/style.css create mode 100644 plugins/serpro_integration/smile.html create mode 100644 plugins/serpro_integration/test/unit/sonar_plugin_test.rb create mode 100644 plugins/serpro_integration/views/profile-editor-extras.html.erb create mode 100644 plugins/serpro_integration/views/profile_design/sonar_plugin/_sonar_widget_block.rhtml create mode 100644 plugins/serpro_integration/views/profile_editor/_gitlab.html.erb create mode 100644 plugins/serpro_integration/views/sonar_widget_block.rhtml delete mode 120000 test/fixtures/files/500.html create mode 100644 test/fixtures/files/500.html diff --git a/app/controllers/public/account_controller.rb b/app/controllers/public/account_controller.rb index 653ed51..a571400 100644 --- a/app/controllers/public/account_controller.rb +++ b/app/controllers/public/account_controller.rb @@ -17,6 +17,8 @@ class AccountController < ApplicationController @user = User.find_by_activation_code(params[:activation_code]) if params[:activation_code] if @user and @user.activate @message = _("Your account has been activated, now you can log in!") + check_redirection + session[:join] = params[:join] unless params[:join].blank? render :action => 'login', :userlogin => @user.login else session[:notice] = _("It looks like you're trying to activate an account. Perhaps have already activated this account?") @@ -35,6 +37,7 @@ class AccountController < ApplicationController self.current_user ||= User.authenticate(params[:user][:login], params[:user][:password], environment) if params[:user] if logged_in? + check_join_in_community(self.current_user) if params[:remember_me] == "1" self.current_user.remember_me cookies[:auth_token] = { :value => self.current_user.remember_token , :expires => self.current_user.remember_token_expires_at } @@ -91,6 +94,7 @@ class AccountController < ApplicationController if session[:may_be_a_bot] return false unless verify_recaptcha :model=>@user, :message=>_('Captcha (the human test)') end + @user.community_to_join = session[:join] @user.signup! owner_role = Role.find_by_name('owner') @user.person.affiliate(@user.person, [owner_role]) if owner_role @@ -101,6 +105,7 @@ class AccountController < ApplicationController end if @user.activated? self.current_user = @user + check_join_in_community(@user) go_to_signup_initial_page else @register_pending = true @@ -388,12 +393,6 @@ class AccountController < ApplicationController end def go_to_initial_page - if params[:redirection] - session[:return_to] = @user.return_to - @user.return_to = nil - @user.save - end - if params[:return_to] redirect_to params[:return_to] elsif environment.enabled?('allow_change_of_redirection_after_login') @@ -444,4 +443,19 @@ class AccountController < ApplicationController redirect_back_or_default(default) end end + + def check_redirection + unless params[:redirection].blank? + session[:return_to] = @user.return_to + @user.update_attributes(:return_to => nil) + end + end + + def check_join_in_community(user) + profile_to_join = session[:join] + unless profile_to_join.blank? + environment.profiles.find_by_identifier(profile_to_join).add_member(user.person) + session.delete(:join) + end + end end diff --git a/app/controllers/public/profile_controller.rb b/app/controllers/public/profile_controller.rb index 6b312b9..e855c28 100644 --- a/app/controllers/public/profile_controller.rb +++ b/app/controllers/public/profile_controller.rb @@ -3,7 +3,7 @@ class ProfileController < PublicController needs_profile before_filter :check_access_to_profile, :except => [:join, :join_not_logged, :index, :add] before_filter :store_location, :only => [:join, :join_not_logged, :report_abuse, :send_mail] - before_filter :login_required, :only => [:add, :join, :join_not_logged, :leave, :unblock, :leave_scrap, :remove_scrap, :remove_activity, :view_more_activities, :view_more_network_activities, :report_abuse, :register_report, :leave_comment_on_activity, :send_mail] + before_filter :login_required, :only => [:add, :join, :leave, :unblock, :leave_scrap, :remove_scrap, :remove_activity, :view_more_activities, :view_more_network_activities, :report_abuse, :register_report, :leave_comment_on_activity, :send_mail] helper TagsHelper @@ -97,21 +97,12 @@ class ProfileController < PublicController end def join_not_logged - if request.post? - profile.add_member(user) - session[:notice] = _('%s administrator still needs to accept you as member.') % profile.name if profile.closed? - redirect_to_previous_location + session[:join] = profile.identifier + + if user + redirect_to :controller => 'profile', :action => 'join' else - if user.memberships.include?(profile) - session[:notice] = _('You are already a member of %s.') % profile.name - redirect_to profile.url - return - end - if request.xhr? - render :layout => false - else - redirect_to profile.url - end + redirect_to :controller => '/account', :action => 'login' end end diff --git a/app/models/user.rb b/app/models/user.rb index a97a15a..69be0c0 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -63,6 +63,9 @@ class User < ActiveRecord::Base self.person.preferred_domain && self.person.preferred_domain.name || self.environment.default_hostname(true) end + # virtual attribute used to stash which community to join on signup or login + attr_accessor :community_to_join + class Mailer < ActionMailer::Base def activation_email_notify(user) user_email = "#{user.login}@#{user.email_domain}" @@ -85,7 +88,8 @@ class User < ActiveRecord::Base :activation_code => user.activation_code, :environment => user.environment.name, :url => user.environment.top_url, - :redirection => (true if user.return_to) + :redirection => (true if user.return_to), + :join => (user.community_to_join if user.community_to_join) end def signup_welcome_email(user) diff --git a/features/login.feature b/features/login.feature index 580c411..fe66e72 100644 --- a/features/login.feature +++ b/features/login.feature @@ -207,3 +207,18 @@ Feature: login | Password | 123456 | When I press "Log in" Then I should be on joaosilva's control panel + + Scenario: join community on login + Given the following users + | login | name | + | mariasilva | Maria Silva | + And the following communities + | name | identifier | owner | + | Free Software | freesoftware | mariasilva | + And I am on /freesoftware + When I follow "Join" + And I fill in the following: + | Username / Email | joaosilva | + | Password | 123456 | + And I press "Log in" + Then "Joao Silva" should be a member of "Free Software" diff --git a/features/signup.feature b/features/signup.feature index 662ee0b..da6fa8f 100644 --- a/features/signup.feature +++ b/features/signup.feature @@ -250,3 +250,51 @@ Feature: signup And I fill in "Password" with "secret" And I press "Log in" Then I should be on the homepage + + @selenium + Scenario: join community on signup + Given the following users + | login | name | + | mariasilva | Maria Silva | + And the following communities + | name | identifier | owner | + | Free Software | freesoftware | mariasilva | + And feature "skip_new_user_email_confirmation" is disabled on environment + And I am on /freesoftware + When I follow "Join" + And I follow "New user" + And I fill in the following within ".no-boxes": + | e-Mail | josesilva@example.com | + | Username | josesilva | + | Password | secret | + | Password confirmation | secret | + | Full name | José da Silva | + And wait for the captcha signup time + And I press "Create my account" + And I go to josesilva's confirmation URL + And I fill in "Username" with "josesilva" + And I fill in "Password" with "secret" + And I press "Log in" + Then "José da Silva" should be a member of "Free Software" + + @selenium + Scenario: join community on direct signup + Given the following users + | login | name | + | mariasilva | Maria Silva | + And the following communities + | name | identifier | owner | + | Free Software | freesoftware | mariasilva | + And feature "skip_new_user_email_confirmation" is enabled on environment + And I am on /freesoftware + When I follow "Join" + And I follow "New user" + And I fill in the following within ".no-boxes": + | e-Mail | josesilva@example.com | + | Username | josesilva | + | Password | secret | + | Password confirmation | secret | + | Full name | José da Silva | + And wait for the captcha signup time + And I press "Create my account" + Then "José da Silva" should be a member of "Free Software" diff --git a/plugins/serpro_integration/controllers/serpro_integration_plugin_myprofile_controller.rb b/plugins/serpro_integration/controllers/serpro_integration_plugin_myprofile_controller.rb new file mode 100644 index 0000000..0566d08 --- /dev/null +++ b/plugins/serpro_integration/controllers/serpro_integration_plugin_myprofile_controller.rb @@ -0,0 +1,13 @@ +class SerproIntegrationPluginMyprofileController < MyProfileController + append_view_path File.join(File.dirname(__FILE__) + '/../views') + + def create_gitlab + profile.create_gitlab_project + render :update do |page| + page.replace_html 'gitlab', :partial => 'gitlab' +# page.replace_html 'gitlab', 'teste' + end +# raise 'teste my profile' + end + +end diff --git a/plugins/serpro_integration/features/sonar.feature b/plugins/serpro_integration/features/sonar.feature new file mode 100644 index 0000000..9a8ce8d --- /dev/null +++ b/plugins/serpro_integration/features/sonar.feature @@ -0,0 +1,15 @@ +Feature: require authentication to comment + + Background: + Given plugin RequireAuthToCommentPlugin is enabled on environment + And the following users + | login | + | bozo | + + Scenario: enabling unauthenticated comment per profile + Given I am logged in as "bozo" + When I edit my profile + And I check "Accept comments from unauthenticated users" + And I press "Save" + Then I edit my profile + And the "Accept comments from unauthenticated users" checkbox should be checked diff --git a/plugins/serpro_integration/install.rb b/plugins/serpro_integration/install.rb new file mode 100644 index 0000000..6944eaf --- /dev/null +++ b/plugins/serpro_integration/install.rb @@ -0,0 +1,2 @@ +system "gem install --user-install gitlab" +system "gem install --user-install jenkins_api_client" diff --git a/plugins/serpro_integration/lib/ext/community.rb b/plugins/serpro_integration/lib/ext/community.rb new file mode 100644 index 0000000..208aed4 --- /dev/null +++ b/plugins/serpro_integration/lib/ext/community.rb @@ -0,0 +1,220 @@ +require_dependency 'community' +require 'gitlab' +#require 'jenkins_api_client' + +class Community + + settings_items :allow_sonar_integration, :type => :boolean, :default => true + settings_items :allow_gitlab_integration, :type => :boolean, :default => true + settings_items :allow_jenkins_integration, :type => :boolean, :default => true + + #FIXME make test for default option + settings_items :serpro_integration_plugin, :type => Hash, :default => {} + + ########################################## + # Gitlab stuff # + ########################################## + + after_create :create_gitlab_project + + def gitlab= params + self.serpro_integration_plugin[:gitlab] = params + end + + def gitlab + self.serpro_integration_plugin[:gitlab] ||= {} + self.serpro_integration_plugin[:gitlab] + end + + def create_gitlab_project + Gitlab.endpoint = self.gitlab_host + Gitlab.private_token = self.gitlab_private_token + + user = nil + + #Find user by email + begin + user = Gitlab.users(:search => email) + rescue Gitlab::Error::NotFound, Gitlab::Error::Parsing + user = nil + end + + #User not found, create user + if user == nil || user.count == 0 + user = self.admins.first + gitlab_user = Gitlab.create_user(user.email, '123456', {:username => user.identifier, :name => user.name, :provider => 'ldap'}) + end + + if gitlab_user.nil? + self.gitlab[:errors] = _('Gitlab user could not be created') + return nil + end + + #Create project for user + begin + #FIXME Why this? + if gitlab_user.is_a?(Array) + gitlab_user = user[0] + end + + project_options = {} + project_options[:user_id] = gitlab_user.id + project_options[:issues_enabled ] = true + project_options[:wall_enabled] = true + project_options[:wiki_enabled] = true + project_options[:public] = true + project = Gitlab.create_project(self.identifier, project_options) + + #Create Web Hook for Jenkins' integration +# Gitlab.add_project_hook(project.id, "#{self.jenkins[:url]}/gitlab/build_now") +# createJenkinsJob(project.name, project.path_with_namespace, project.web_url, project.http_url_to_repo) + + rescue Gitlab::Error::NotFound, Gitlab::Error::Parsing + #Project already exists + end + + self.gitlab[:errors] = nil + end + + # set an API endpoint + def gitlab_host + self.serpro_integration_plugin[:gitlab_host] + end + + # set a user private token + def gitlab_private_token + self.serpro_integration_plugin[:gitlab_private_token] + end + + ########################################## + # Sonar stuff # + ########################################## + +# after_create :create_sonar_project + + def sonar= params + self.serpro_integration_plugin[:sonar] = params + end + + def sonar + self.serpro_integration_plugin[:sonar] ||= {} + self.serpro_integration_plugin[:sonar] + end + + ########################################## + # Jenkins stuff # + ########################################## + +# after_create :create_jenkis_project + + def jenkins= params + self.serpro_integration_plugin[:jenkins] = params + end + + def jenkins + self.serpro_integration_plugin[:jenkins] ||= {} + url = "#{self.serpro_integration_plugin[:jenkins][:host]}:" + url += "#{self.serpro_integration_plugin[:jenkins][:port]}/" + url += "#{self.serpro_integration_plugin[:jenkins][:context_name]}" + self.serpro_integration_plugin[:jenkins][:url] = url + self.serpro_integration_plugin[:jenkins] + end + + + #FIXME make jenkins integration works + def create_jenkis_project +#(projectName, repositoryPath, webUrl, gitUrl) + + @client = JenkinsApi::Client.new(:server_url => "#{$jenkins_url}/", + :password => $jenkins_private_token, + :username => $jenkins_user) + + xmlJenkins = " + + + Projeto criado para o repositório #{repositoryPath} do Gitlab - #{webUrl} + + -1 + 2 + -1 + -1 + + false + + + 2 + + + #{gitUrl} + + + + + */master + + + false + + + + true + false + false + false + (Inherit From Job) + + false + clean package install deploy + true + false + true + false + false + false + false + -1 + false + false + + + + + + false + true + true + + + + + (Inherit From Job) + + + + + + + false + + + + + + + FAILURE + 2 + RED + + + " + + begin + @client.job.create(projectName, xmlJenkins) + rescue JenkinsApi::Exceptions::ApiException + + end + + end + + +end diff --git a/plugins/serpro_integration/lib/ext/profile.rb b/plugins/serpro_integration/lib/ext/profile.rb new file mode 100644 index 0000000..d6f029c --- /dev/null +++ b/plugins/serpro_integration/lib/ext/profile.rb @@ -0,0 +1,9 @@ +require_dependency 'profile' + +class Profile + settings_items :allow_sonar_integration, :type => :boolean, :default => true + settings_items :allow_gitlab_integration, :type => :boolean, :default => true + + #FIXME make test for default option + settings_items :serpro_integration_plugin, :type => Hash, :default => {} +end diff --git a/plugins/serpro_integration/lib/serpro_integration_plugin.rb b/plugins/serpro_integration/lib/serpro_integration_plugin.rb new file mode 100644 index 0000000..a49ba27 --- /dev/null +++ b/plugins/serpro_integration/lib/serpro_integration_plugin.rb @@ -0,0 +1,64 @@ +class SerproIntegrationPlugin < Noosfero::Plugin + +#include ActionController::UrlWriter +# include ActionView::Helpers::TagHelper +# include ActionView::Helpers::FormTagHelper +# include FormsHelper + + +# include ActionView::Helpers +# include FormsHelper + + def self.plugin_name + "Serpro Integration Plugin" + end + + def self.plugin_description + _("Make integration with serpro servers.") + end + +# def filter_comment(c) +# c.reject! unless logged_in? || allowed_by_profile +# end + + #FIXME make this test + # User could not have this block + def self.extra_blocks + { SonarPlugin::SonarWidgetBlock => {:type => [Community] }, + SonarPlugin::SmileBlock => {:type => [Community] } + } + end + + #FIXME make this test + def profile_editor_extras + lambda do + render :file => 'profile-editor-extras' + end + end + + def profile_id + context.profile + end + + def stylesheet? + true + end + +# FIXME make this test + def js_files + ['smile_face.js'] + end + +# def body_beginning +# "" if allowed_by_profile +# end +# +# protected +# +# delegate :logged_in?, :to => :context +# +# def allowed_by_profile +# context.profile && context.profile.allow_unauthenticated_comments +# end + +end diff --git a/plugins/serpro_integration/lib/serpro_integration_plugin/smile_block.rb b/plugins/serpro_integration/lib/serpro_integration_plugin/smile_block.rb new file mode 100644 index 0000000..c1cff00 --- /dev/null +++ b/plugins/serpro_integration/lib/serpro_integration_plugin/smile_block.rb @@ -0,0 +1,100 @@ +require 'open-uri' +require 'json' + +class SonarPlugin::SmileBlock < Block + + + METRIC_SUCCESS_DENSITY = 'test_success_density' + METRIC_LOC = 'ncloc' + METRIC_UNCOVERED_LINE = 'uncovered_lines' + METRIC_COVERAGE = 'coverage' + + #FIXME make this test + settings_items :sonar_info, :type => Hash, :default => {} + + def self.description + _('Sonar Smile') + end + + def help + _('This block adds a smile face that make tecnical debits visible with funny way.') + end + + #FIXME make this test + def sonar_host + self.owner.sonar_plugin['host'] + end + + #FIXME make this test + def sonar_project + self.owner.sonar_plugin['project'] #|| '' + end + +#FIXME make this test + def smile_factor + collect_sonar_information + factor = (self.sonar_info[METRIC_COVERAGE] * self.sonar_info[METRIC_SUCCESS_DENSITY]).to_f/1000 + factor + end + + #FIXME make this test + def content(args={}) + smile_face_id = 'smileFace-' + self.id.to_s + + content_tag(:div, + content_tag(:canvas, '', :id => smile_face_id, :width => '95%', :height => '95%' ) + + "", + :class => 'smile' + ) + end + + #FIXME make this test + def self.metrics + [ + METRIC_SUCCESS_DENSITY, + METRIC_LOC, + METRIC_UNCOVERED_LINE, + METRIC_COVERAGE + ] + end + + private + + #FIXME make this test + def collect_sonar_information + return false unless cache_expired? + begin + data = open("#{self.sonar_host}/api/resources?resource=#{self.sonar_project}&metrics=ncloc,coverage,weighted_violations,uncovered_lines,test_success_density&format=json").read + self.sonar_info = parse_sonar_resource(JSON.parse(data).first) + rescue + self.sonar_info = {} + end + self.sonar_info[:updated_at] = Time.now + self.save + end + + #FIXME make this test + def parse_sonar_resource(data) + parsed_data = {} + return {} if data['msr'].nil? + data['msr'].map do |metric| + self.class.metrics.map do |defined_metric| + parsed_data[defined_metric] = metric['val'] if metric['key'] == defined_metric + end + end + parsed_data + end + + #FIXME make this test + def cache_expired? + return true if self.sonar_info[:updated_at].nil? + (Time.now - self.sonar_info[:updated_at]) > cache_timestamp + end + + #FIXME make this test + # Cach time to load new data in seconds + def cache_timestamp + 60 * 60 + end + +end diff --git a/plugins/serpro_integration/lib/serpro_integration_plugin/sonar_widget_block.rb b/plugins/serpro_integration/lib/serpro_integration_plugin/sonar_widget_block.rb new file mode 100644 index 0000000..3ba1e2b --- /dev/null +++ b/plugins/serpro_integration/lib/serpro_integration_plugin/sonar_widget_block.rb @@ -0,0 +1,81 @@ +class SerproIntegrationrPlugin::SonarWidgetBlock < Block + + #FIXME make this test + AVAILABLE_WIDGETS = { + 'project_motion_chart' => 'Project Motion Chart', + 'timeline' => 'Timeline', + 'complexity' => 'Complexity' + } + + #FIXME make this test. Make test for default widget + settings_items :widget, :type => String, :default => 'timeline' + + def self.description + _('Sonar Widgets') + end + + def help + _('This block adds sonar widgets on profile.') + end + + #FIXME make this test + def sonar_host + self.owner.serpro_integration_plugin['host'] + end + + #FIXME make this test + def sonar_project + self.owner.serpro_integration_plugin['project'] + end + + #FIXME make this test + def widget_url + self.sonar_host + 'widget?id=' + self.widget + '&resource=' + self.sonar_project + '&metric1=complexity&metric2=ncloc' + end + + #FIXME make this test + def is_widget_well_formed_url? + !self.widget_url.match(/http[s]?:\/\/[\w|.|\/]+\/widget\?id=[\w]+&resource=[\w|\W]+/).nil? + end + + #FIXME make this test + def widget_width + case widget + when 'project_motion_chart' + '360px' + when 'timeline' + '100%' + when 'complexity' + '100%' + else + '300px' + end + end + + #FIXME make this test + def widget_height + case widget + when 'project_motion_chart' + '450px' + when 'timeline' + '205px' + when 'complexity' + '170px' + else + '300px' + end + end + + def content(args={}) +# render this url +#http://sonar.serpro/widget?id=timeline&resource=br.gov.fazenda.coaf.siscoaf:siscoaf-parent&metric1=complexity&metric2=ncloc + + block = self + + lambda do + render :file => 'sonar_widget_block', :locals => { :block => block } + end + + end + +end diff --git a/plugins/serpro_integration/public/smile_face.js b/plugins/serpro_integration/public/smile_face.js new file mode 100644 index 0000000..e74e71c --- /dev/null +++ b/plugins/serpro_integration/public/smile_face.js @@ -0,0 +1,129 @@ +function drawBaseFace(element_id) { + var canvas = document.getElementById(element_id); + var ctx = canvas.getContext("2d"); + + var x = canvas.width / 2; + var y = canvas.height / 2; + var radius = canvas.width/2 - 1; + var startAngle = 0; + var endAngle = 2 * Math.PI; + + ctx.beginPath(); + ctx.arc(x, y, radius, startAngle, endAngle); + ctx.stroke(); + ctx.fillStyle = "yellow"; + ctx.fill(); +} + +function drawSmile(element_id, factor){ + var canvas = document.getElementById(element_id); + var ctx = canvas.getContext("2d"); + var x = canvas.width / 2; + var y = canvas.height / 2 + var radius = canvas.width/2 - canvas.width/4; + + var startAngle = 0; + var endAngle = 0; + var delta = 0; + + ctx.beginPath(); + ctx.lineWidth = canvas.width/100 * 2; + + if (factor >= 0 && factor < 5){ + //Draw sadness mouth + delta = 0.5 - factor* 0.1 + startAngle = (1.5 - delta) * Math.PI; + endAngle = (1.5 + delta) * Math.PI; + radius = radius - radius*delta; + y = y + (radius + radius*(1 - delta)); + ctx.arc(x, y, radius, startAngle, endAngle); + } else if (factor == 5) { + //Draw normal mouth + ctx.moveTo(x-canvas.width/8,y+canvas.width/8); + ctx.lineTo(x-canvas.width/8+(canvas.width/4),y+canvas.width/8); + } else if (factor > 5 && factor <= 10) { + //Draw happiness mouth + delta = 1 - factor * 0.1 + startAngle = delta * Math.PI; + endAngle = (1 - delta) * Math.PI; + radius = radius - radius*delta; + y = y - (radius - radius*(1-delta)); + ctx.arc(x, y, radius, startAngle, endAngle); + }else{ + //Draw scare mouth + radius = radius*0.4 + y = y + radius; + ctx.ellipse(x,y,radius*0.4, radius,0,0,2 * Math.PI, false); + ctx.fill(); + } + + + // line color + ctx.strokeStyle = 'black'; + ctx.stroke(); +} + +function drawEyes(element_id){ + var canvas = document.getElementById(element_id); + var ctx = canvas.getContext("2d"); + var centerX = canvas.width/5; + var centerY = 0; + var radius = canvas.width * 0.05; + + // save state + ctx.save(); + + // translate context so height is 1/3'rd from top of enclosing circle + ctx.translate(canvas.width / 2, canvas.height / 3); + + // scale context horizontally by 50% + ctx.scale(.5, 1); + + // draw circle which will be stretched into an oval + ctx.beginPath(); + ctx.arc(centerX, centerY, radius, 0, 2 * Math.PI, false); + + // restore to original state + ctx.restore(); + + // apply styling + ctx.fillStyle = 'black'; + ctx.fill(); + ctx.lineWidth = 2; + ctx.strokeStyle = 'black'; + ctx.stroke(); + + + //left eye + centerX = centerX * -1; + + // save state + ctx.save(); + + // translate context so height is 1/3'rd from top of enclosing circle + ctx.translate(canvas.width / 2, canvas.height / 3); + + // scale context horizontally by 50% + ctx.scale(.5, 1); + + // draw circle which will be stretched into an oval + ctx.beginPath(); + ctx.arc(centerX, centerY, radius, 0, 2 * Math.PI, false); + + // restore to original state + ctx.restore(); + + // apply styling + ctx.fillStyle = 'black'; + ctx.fill(); + ctx.lineWidth = 2; + ctx.strokeStyle = 'black'; + ctx.stroke(); +} + + +function drawFace(element_id, factor){ + drawBaseFace(element_id); + drawEyes(element_id); + drawSmile(element_id, factor); +} diff --git a/plugins/serpro_integration/public/style.css b/plugins/serpro_integration/public/style.css new file mode 100644 index 0000000..f89b362 --- /dev/null +++ b/plugins/serpro_integration/public/style.css @@ -0,0 +1,3 @@ +.serpro-integration-plugin_smile-block .smile { + text-align: center; +} diff --git a/plugins/serpro_integration/smile.html b/plugins/serpro_integration/smile.html new file mode 100644 index 0000000..672b48f --- /dev/null +++ b/plugins/serpro_integration/smile.html @@ -0,0 +1,142 @@ + + + + + + + + diff --git a/plugins/serpro_integration/test/unit/sonar_plugin_test.rb b/plugins/serpro_integration/test/unit/sonar_plugin_test.rb new file mode 100644 index 0000000..92b4e1d --- /dev/null +++ b/plugins/serpro_integration/test/unit/sonar_plugin_test.rb @@ -0,0 +1,41 @@ +require File.dirname(__FILE__) + '/../../../../test/test_helper' + +class RequireAuthToCommentPluginTest < ActiveSupport::TestCase + + def setup + @plugin = RequireAuthToCommentPlugin.new + @comment = Comment.new + end + + attr_reader :plugin, :comment + + should 'reject comments for unauthenticated users' do + plugin.context = logged_in(false) + plugin.filter_comment(comment) + assert comment.rejected? + end + + should 'allow comments from authenticated users' do + plugin.context = logged_in(true) + plugin.filter_comment(comment) + assert !comment.rejected? + end + + should 'allow comments from unauthenticated users if allowed by profile' do + plugin.context = logged_in(false) + plugin.context.profile.allow_unauthenticated_comments = true + + plugin.filter_comment(comment) + assert !comment.rejected? + end + + protected + + def logged_in(boolean) + controller = mock() + controller.stubs(:logged_in?).returns(boolean) + controller.stubs(:profile).returns(Profile.new) + controller + end + +end diff --git a/plugins/serpro_integration/views/profile-editor-extras.html.erb b/plugins/serpro_integration/views/profile-editor-extras.html.erb new file mode 100644 index 0000000..24f9a7f --- /dev/null +++ b/plugins/serpro_integration/views/profile-editor-extras.html.erb @@ -0,0 +1,49 @@ + +
+
+ <%= render :partial => 'gitlab' %> +
+ +
+ <%= labelled_check_box(_('Uses sonar integration'), 'profile_data[allow_sonar_integration]', true, profile.allow_sonar_integration) %> +
+ + + + +
+ <%= labelled_check_box(_('Uses Jenkins integration'), 'profile_data[allow_jenkins_integration]', true, profile.allow_jenkins_integration) %> +
+ + + +
diff --git a/plugins/serpro_integration/views/profile_design/sonar_plugin/_sonar_widget_block.rhtml b/plugins/serpro_integration/views/profile_design/sonar_plugin/_sonar_widget_block.rhtml new file mode 100644 index 0000000..fe9138d --- /dev/null +++ b/plugins/serpro_integration/views/profile_design/sonar_plugin/_sonar_widget_block.rhtml @@ -0,0 +1,4 @@ + +<%= labelled_form_field(_('Widget'), select(:block, :widget, SerproIntegrationPlugin::SonarWidgetBlock::AVAILABLE_WIDGETS.map {|id, name| [name, id]} )) %> + + diff --git a/plugins/serpro_integration/views/profile_editor/_gitlab.html.erb b/plugins/serpro_integration/views/profile_editor/_gitlab.html.erb new file mode 100644 index 0000000..86799ba --- /dev/null +++ b/plugins/serpro_integration/views/profile_editor/_gitlab.html.erb @@ -0,0 +1,22 @@ +
+ <%= labelled_check_box(_('Uses Gitlab integration'), 'profile_data[allow_gitlab_integration]', true, profile.allow_gitlab_integration) %> +
+ + + diff --git a/plugins/serpro_integration/views/sonar_widget_block.rhtml b/plugins/serpro_integration/views/sonar_widget_block.rhtml new file mode 100644 index 0000000..ef97408 --- /dev/null +++ b/plugins/serpro_integration/views/sonar_widget_block.rhtml @@ -0,0 +1,10 @@ +
+ <% if block.is_widget_well_formed_url? %> + + <% else %> +
+ + <%= _('Something wrong happened. Please see your sonar configuration.') %> +
+ <% end %> +
diff --git a/test/fixtures/files/500.html b/test/fixtures/files/500.html deleted file mode 120000 index 7847d77..0000000 --- a/test/fixtures/files/500.html +++ /dev/null @@ -1 +0,0 @@ -../../../public/500.html \ No newline at end of file diff --git a/test/fixtures/files/500.html b/test/fixtures/files/500.html new file mode 100644 index 0000000..9a040c2 --- /dev/null +++ b/test/fixtures/files/500.html @@ -0,0 +1,151 @@ + + + + + + Technical problems + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb index 74f7baa..a0f2052 100644 --- a/test/functional/profile_controller_test.rb +++ b/test/functional/profile_controller_test.rb @@ -474,17 +474,23 @@ class ProfileControllerTest < ActionController::TestCase assert_equal "/profile/#{community.identifier}", @request.session[:previous_location] end - should 'redirect to location before login after join community' do + should 'redirect to login after user not logged asks to join a community' do community = Community.create!(:name => 'my test community') - @request.expects(:referer).returns("/profile/#{community.identifier}/to_go") - login_as(profile.identifier) + get :join_not_logged, :profile => community.identifier - post :join_not_logged, :profile => community.identifier + assert_equal community.identifier, @request.session[:join] + assert_redirected_to :controller => :account, :action => :login + end - assert_redirected_to "/profile/#{community.identifier}/to_go" + should 'redirect to join after user logged asks to join_not_logged a community' do + community = Community.create!(:name => 'my test community') + + login_as(profile.identifier) + get :join_not_logged, :profile => community.identifier - assert_nil @request.session[:previous_location] + assert_equal community.identifier, @request.session[:join] + assert_redirected_to :controller => :profile, :action => :join end should 'show number of published events in index' do @@ -1186,7 +1192,7 @@ class ProfileControllerTest < ActionController::TestCase 20.times {comment = fast_create(Comment, :source_id => article, :title => 'a comment', :body => 'lalala', :created_at => Time.now)} article.reload get :index, :profile => profile.identifier - assert_tag 'ul', :attributes => {:class => 'profile-wall-activities-comments'}, :children => {:count => 0 } + assert_tag 'ul', :attributes => {:class => 'profile-wall-activities-comments'}, :children => {:count => 0 } end should "view more comments paginated" do @@ -1212,7 +1218,7 @@ class ProfileControllerTest < ActionController::TestCase 20.times {fast_create(Scrap, :sender_id => profile.id, :receiver_id => profile.id, :scrap_id => scrap.id)} profile.reload get :index, :profile => profile.identifier - assert_tag 'ul', :attributes => {:class => 'profile-wall-activities-comments scrap-replies'}, :children => {:count => 0 } + assert_tag 'ul', :attributes => {:class => 'profile-wall-activities-comments scrap-replies'}, :children => {:count => 0 } end should "view more replies paginated" do @@ -1269,15 +1275,6 @@ class ProfileControllerTest < ActionController::TestCase assert_tag :tag => 'div', :content => /#{instance_eval(&plugin2.profile_tabs[:content])}/, :attributes => {:id => /#{plugin2.profile_tabs[:id]}/} end - should 'redirect to profile page when try to request join_not_logged via GET method' do - community = Community.create!(:name => 'my test community') - login_as(profile.identifier) - get :join_not_logged, :profile => community.identifier - assert_nothing_raised do - assert_redirected_to community.url - end - end - should 'check different profile from the domain profile' do default = Environment.default default.domains.create!(:name => 'environment.com') diff --git a/test/functional/profile_editor_controller_test.rb b/test/functional/profile_editor_controller_test.rb index 29604a5..a6b0f28 100644 --- a/test/functional/profile_editor_controller_test.rb +++ b/test/functional/profile_editor_controller_test.rb @@ -894,6 +894,23 @@ class ProfileEditorControllerTest < ActionController::TestCase assert_tag :tag => 'input', :attributes => {:id => 'field_added_by_plugin', :value => 'value_of_field_added_by_plugin'} end + should 'add extra content with block provided by plugins on edit' do + class TestProfileEditPlugin < Noosfero::Plugin + def profile_editor_extras + lambda do + render :text => "" + end + end + end + Noosfero::Plugin.stubs(:all).returns([TestProfileEditPlugin.to_s]) + + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestProfileEditPlugin.new]) + + get :edit, :profile => profile.identifier + + assert_tag :tag => 'input', :attributes => {:id => 'field_added_by_plugin', :value => 'value_of_field_added_by_plugin'} + end + should 'show image upload field from profile editor' do env = Environment.default env.custom_person_fields = { } -- libgit2 0.21.2