Commit 2a60008b6f38a9f9397014e90b37ec6ae6955f66
1 parent
7aa57416
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Added serpro integration plugin global configuration and fix gitlab project creation
Showing
7 changed files
with
104 additions
and
73 deletions
Show diff stats
| @@ -0,0 +1 @@ | @@ -0,0 +1 @@ | ||
| 1 | +gem 'gitlab', '~> 3.1.0' |
plugins/serpro_integration/controllers/serpro_integration_plugin_admin_controller.rb
0 → 100644
| @@ -0,0 +1,15 @@ | @@ -0,0 +1,15 @@ | ||
| 1 | +class SerproIntegrationPluginAdminController < AdminController | ||
| 2 | + | ||
| 3 | + def index | ||
| 4 | + settings = params[:settings] | ||
| 5 | + settings ||= {} | ||
| 6 | + | ||
| 7 | + @settings = Noosfero::Plugin::Settings.new(environment, SerproIntegrationPlugin, settings) | ||
| 8 | + if request.post? | ||
| 9 | + @settings.save! | ||
| 10 | + session[:notice] = 'Settings succefully saved.' | ||
| 11 | + redirect_to :action => 'index' | ||
| 12 | + end | ||
| 13 | + end | ||
| 14 | + | ||
| 15 | +end |
plugins/serpro_integration/lib/ext/community.rb
| 1 | require_dependency 'community' | 1 | require_dependency 'community' |
| 2 | -#require 'gitlab' | 2 | +require 'gitlab' |
| 3 | #require 'jenkins_api_client' | 3 | #require 'jenkins_api_client' |
| 4 | 4 | ||
| 5 | class Community | 5 | class Community |
| @@ -9,53 +9,54 @@ class Community | @@ -9,53 +9,54 @@ class Community | ||
| 9 | settings_items :allow_jenkins_integration, :type => :boolean, :default => true | 9 | settings_items :allow_jenkins_integration, :type => :boolean, :default => true |
| 10 | 10 | ||
| 11 | #FIXME make test for default option | 11 | #FIXME make test for default option |
| 12 | - settings_items :serpro_integration_plugin, :type => Hash | 12 | + settings_items :serpro_integration_plugin, :type => Hash, :default => {} |
| 13 | + | ||
| 14 | + attr_accessible :allow_unauthenticated_comments, :allow_gitlab_integration, :gitlab, :allow_sonar_integration, :sonar, :allow_jenkins_integration, :jenkins | ||
| 13 | 15 | ||
| 14 | ########################################## | 16 | ########################################## |
| 15 | # Gitlab stuff # | 17 | # Gitlab stuff # |
| 16 | ########################################## | 18 | ########################################## |
| 17 | 19 | ||
| 18 | - after_create :create_gitlab_project | 20 | + #after_create :create_gitlab_project |
| 19 | 21 | ||
| 20 | def gitlab= params | 22 | def gitlab= params |
| 21 | self.serpro_integration_plugin[:gitlab] = params | 23 | self.serpro_integration_plugin[:gitlab] = params |
| 22 | end | 24 | end |
| 23 | 25 | ||
| 24 | def gitlab | 26 | def gitlab |
| 25 | - self.serpro_integration_plugin ||= {} | ||
| 26 | self.serpro_integration_plugin[:gitlab] ||= {} | 27 | self.serpro_integration_plugin[:gitlab] ||= {} |
| 27 | - self.serpro_integration_plugin[:gitlab] | ||
| 28 | end | 28 | end |
| 29 | 29 | ||
| 30 | - def create_gitlab_project | ||
| 31 | - Gitlab.endpoint = self.gitlab_host | ||
| 32 | - Gitlab.private_token = self.gitlab_private_token | 30 | + def serpro_integration_plugin_settings |
| 31 | + @settings ||= Noosfero::Plugin::Settings.new(environment, SerproIntegrationPlugin) | ||
| 32 | + end | ||
| 33 | 33 | ||
| 34 | - user = nil | 34 | + def create_gitlab_project |
| 35 | + Gitlab.endpoint = gitlab_host | ||
| 36 | + Gitlab.private_token = serpro_integration_plugin_settings.gitlab[:private_token] | ||
| 35 | 37 | ||
| 36 | #Find user by email | 38 | #Find user by email |
| 37 | begin | 39 | begin |
| 38 | - user = Gitlab.users(:search => email) | 40 | + gitlab_user = Gitlab.users(:search => gitlab[:email]) |
| 39 | rescue Gitlab::Error::NotFound, Gitlab::Error::Parsing | 41 | rescue Gitlab::Error::NotFound, Gitlab::Error::Parsing |
| 40 | - user = nil | 42 | + gitlab_user = nil |
| 41 | end | 43 | end |
| 42 | 44 | ||
| 43 | #User not found, create user | 45 | #User not found, create user |
| 44 | - if user == nil || user.count == 0 | ||
| 45 | - user = self.admins.first | 46 | + if gitlab_user == nil || gitlab_user.count == 0 |
| 46 | gitlab_user = Gitlab.create_user(user.email, '123456', {:username => user.identifier, :name => user.name, :provider => 'ldap'}) | 47 | gitlab_user = Gitlab.create_user(user.email, '123456', {:username => user.identifier, :name => user.name, :provider => 'ldap'}) |
| 47 | end | 48 | end |
| 48 | 49 | ||
| 49 | if gitlab_user.nil? | 50 | if gitlab_user.nil? |
| 50 | self.gitlab[:errors] = _('Gitlab user could not be created') | 51 | self.gitlab[:errors] = _('Gitlab user could not be created') |
| 51 | return nil | 52 | return nil |
| 52 | - end | ||
| 53 | - | 53 | + end |
| 54 | + | ||
| 54 | #Create project for user | 55 | #Create project for user |
| 55 | begin | 56 | begin |
| 56 | #FIXME Why this? | 57 | #FIXME Why this? |
| 57 | if gitlab_user.is_a?(Array) | 58 | if gitlab_user.is_a?(Array) |
| 58 | - gitlab_user = user[0] | 59 | + gitlab_user = gitlab_user[0] |
| 59 | end | 60 | end |
| 60 | 61 | ||
| 61 | project_options = {} | 62 | project_options = {} |
| @@ -64,7 +65,7 @@ class Community | @@ -64,7 +65,7 @@ class Community | ||
| 64 | project_options[:wall_enabled] = true | 65 | project_options[:wall_enabled] = true |
| 65 | project_options[:wiki_enabled] = true | 66 | project_options[:wiki_enabled] = true |
| 66 | project_options[:public] = true | 67 | project_options[:public] = true |
| 67 | - project = Gitlab.create_project(self.identifier, project_options) | 68 | + project = Gitlab.create_project(gitlab_project_name, project_options) |
| 68 | 69 | ||
| 69 | #Create Web Hook for Jenkins' integration | 70 | #Create Web Hook for Jenkins' integration |
| 70 | # Gitlab.add_project_hook(project.id, "#{self.jenkins[:url]}/gitlab/build_now") | 71 | # Gitlab.add_project_hook(project.id, "#{self.jenkins[:url]}/gitlab/build_now") |
| @@ -77,14 +78,18 @@ class Community | @@ -77,14 +78,18 @@ class Community | ||
| 77 | self.gitlab[:errors] = nil | 78 | self.gitlab[:errors] = nil |
| 78 | end | 79 | end |
| 79 | 80 | ||
| 81 | + def gitlab_project_name | ||
| 82 | + gitlab[:project_name] || self.identifier | ||
| 83 | + end | ||
| 84 | + | ||
| 80 | # set an API endpoint | 85 | # set an API endpoint |
| 81 | def gitlab_host | 86 | def gitlab_host |
| 82 | - self.serpro_integration_plugin[:gitlab_host] | 87 | + serpro_integration_plugin_settings.gitlab[:host] |
| 83 | end | 88 | end |
| 84 | 89 | ||
| 85 | # set a user private token | 90 | # set a user private token |
| 86 | def gitlab_private_token | 91 | def gitlab_private_token |
| 87 | - self.serpro_integration_plugin[:gitlab_private_token] | 92 | + serpro_integration_plugin_settings.gitlab[:private_token] |
| 88 | end | 93 | end |
| 89 | 94 | ||
| 90 | ########################################## | 95 | ########################################## |
plugins/serpro_integration/lib/serpro_integration_plugin.rb
| 1 | class SerproIntegrationPlugin < Noosfero::Plugin | 1 | class SerproIntegrationPlugin < Noosfero::Plugin |
| 2 | 2 | ||
| 3 | -#include ActionController::UrlWriter | ||
| 4 | -# include ActionView::Helpers::TagHelper | ||
| 5 | -# include ActionView::Helpers::FormTagHelper | ||
| 6 | -# include FormsHelper | ||
| 7 | - | ||
| 8 | - | ||
| 9 | -# include ActionView::Helpers | ||
| 10 | -# include FormsHelper | ||
| 11 | - | ||
| 12 | def self.plugin_name | 3 | def self.plugin_name |
| 13 | "Serpro Integration Plugin" | 4 | "Serpro Integration Plugin" |
| 14 | end | 5 | end |
| @@ -17,10 +8,6 @@ class SerproIntegrationPlugin < Noosfero::Plugin | @@ -17,10 +8,6 @@ class SerproIntegrationPlugin < Noosfero::Plugin | ||
| 17 | _("Make integration with serpro servers.") | 8 | _("Make integration with serpro servers.") |
| 18 | end | 9 | end |
| 19 | 10 | ||
| 20 | -# def filter_comment(c) | ||
| 21 | -# c.reject! unless logged_in? || allowed_by_profile | ||
| 22 | -# end | ||
| 23 | - | ||
| 24 | #FIXME make this test | 11 | #FIXME make this test |
| 25 | # User could not have this block | 12 | # User could not have this block |
| 26 | def self.extra_blocks | 13 | def self.extra_blocks |
| @@ -49,16 +36,4 @@ class SerproIntegrationPlugin < Noosfero::Plugin | @@ -49,16 +36,4 @@ class SerproIntegrationPlugin < Noosfero::Plugin | ||
| 49 | ['smile_face.js'] | 36 | ['smile_face.js'] |
| 50 | end | 37 | end |
| 51 | 38 | ||
| 52 | -# def body_beginning | ||
| 53 | -# "<meta name='profile.allow_unauthenticated_comments'/>" if allowed_by_profile | ||
| 54 | -# end | ||
| 55 | -# | ||
| 56 | -# protected | ||
| 57 | -# | ||
| 58 | -# delegate :logged_in?, :to => :context | ||
| 59 | -# | ||
| 60 | -# def allowed_by_profile | ||
| 61 | -# context.profile && context.profile.allow_unauthenticated_comments | ||
| 62 | -# end | ||
| 63 | - | ||
| 64 | end | 39 | end |
plugins/serpro_integration/views/profile-editor-extras.html.erb
| 1 | - | 1 | +<script> |
| 2 | +jQuery( document ).ready(function( $ ) { | ||
| 3 | + function toggle_checkbox_selectors(el) { | ||
| 4 | + if( el.is(':checked')) { | ||
| 5 | + $(el.data('selector')).show('fast'); | ||
| 6 | + } else { | ||
| 7 | + $(el.data('selector')).hide('fast'); | ||
| 8 | + } | ||
| 9 | + } | ||
| 10 | + $(".toggle_checkbox").click(function() { | ||
| 11 | + toggle_checkbox_selectors($(this)); | ||
| 12 | + }); | ||
| 13 | + $(".toggle_checkbox").each(function() { | ||
| 14 | + toggle_checkbox_selectors($(this)); | ||
| 15 | + }); | ||
| 16 | +}); | ||
| 17 | +</script> | ||
| 18 | + | ||
| 2 | <div id='serpro-integration'> | 19 | <div id='serpro-integration'> |
| 3 | - <div id='gitlab' class='gitlab'> | ||
| 4 | - <%= render :partial => 'gitlab' %> | ||
| 5 | - </div> | 20 | + <h2><%= _('Serpro Integration') %></h2> |
| 6 | 21 | ||
| 22 | + <%= render :partial => 'gitlab' %> | ||
| 7 | 23 | ||
| 8 | - <div> | ||
| 9 | - <%= labelled_check_box(_('Uses sonar integration'), 'profile_data[allow_sonar_integration]', true, profile.allow_sonar_integration) %> | ||
| 10 | - </div> | ||
| 11 | - | 24 | + <div id="sonar"> |
| 25 | + <h3> | ||
| 26 | + <%= labelled_check_box('', 'profile_data[allow_sonar_integration]', true, profile.allow_sonar_integration, {:class => "toggle_checkbox", 'data-selector' => 'ul.sonar'}) %> | ||
| 27 | + <%= _('Sonar Integration') %> | ||
| 28 | + </h3> | ||
| 12 | <ul class='sonar'> | 29 | <ul class='sonar'> |
| 13 | - <h2><%= _('Sonar Integration') %></h2> | ||
| 14 | <li> | 30 | <li> |
| 15 | <%= labelled_text_field(_('Server Host'), 'profile_data[sonar]host]', profile.sonar[:host]) %> | 31 | <%= labelled_text_field(_('Server Host'), 'profile_data[sonar]host]', profile.sonar[:host]) %> |
| 16 | </li> | 32 | </li> |
| @@ -18,14 +34,14 @@ | @@ -18,14 +34,14 @@ | ||
| 18 | <%= labelled_text_field(_('Project: '), 'profile_data[sonar][project]', profile.sonar[:project]) %> | 34 | <%= labelled_text_field(_('Project: '), 'profile_data[sonar][project]', profile.sonar[:project]) %> |
| 19 | </li> | 35 | </li> |
| 20 | </ul> | 36 | </ul> |
| 21 | - | ||
| 22 | - | ||
| 23 | - <div> | ||
| 24 | - <%= labelled_check_box(_('Uses Jenkins integration'), 'profile_data[allow_jenkins_integration]', true, profile.allow_jenkins_integration) %> | ||
| 25 | </div> | 37 | </div> |
| 26 | - | 38 | + |
| 39 | + <div id="jenkins"> | ||
| 40 | + <h3> | ||
| 41 | + <%= labelled_check_box('', 'profile_data[allow_jenkins_integration]', true, profile.allow_jenkins_integration, {:class => "toggle_checkbox", 'data-selector' => 'ul.jenkins'}) %> | ||
| 42 | + <%= _('Jenkins Integration') %> | ||
| 43 | + </h3> | ||
| 27 | <ul class='jenkins'> | 44 | <ul class='jenkins'> |
| 28 | - <h2><%= _('Jenkins Integration') %></h2> | ||
| 29 | <li> | 45 | <li> |
| 30 | <%= labelled_text_field(_('Server Host'), 'profile_data[jenkins][host]', profile.jenkins[:host]) %> | 46 | <%= labelled_text_field(_('Server Host'), 'profile_data[jenkins][host]', profile.jenkins[:host]) %> |
| 31 | </li> | 47 | </li> |
| @@ -44,7 +60,6 @@ | @@ -44,7 +60,6 @@ | ||
| 44 | <li> | 60 | <li> |
| 45 | <%= labelled_text_field(_('Server Url'), 'profile_data[jenkins][url]', profile.jenkins[:url], {:disabled => true}) %> | 61 | <%= labelled_text_field(_('Server Url'), 'profile_data[jenkins][url]', profile.jenkins[:url], {:disabled => true}) %> |
| 46 | </li> | 62 | </li> |
| 47 | - | ||
| 48 | </ul> | 63 | </ul> |
| 49 | - | 64 | + </div> |
| 50 | </div> | 65 | </div> |
plugins/serpro_integration/views/profile_editor/_gitlab.html.erb
| 1 | -<div class='option'> | ||
| 2 | - <%= labelled_check_box(_('Uses Gitlab integration'), 'profile_data[allow_gitlab_integration]', true, profile.allow_gitlab_integration) %> | ||
| 3 | -</div> | ||
| 4 | - | ||
| 5 | -<ul> | ||
| 6 | - <h2> | ||
| 7 | - <%= _('Gitlab Integration') %> | ||
| 8 | - <%= link_to_remote _('Force'), :url => {:controller => 'serpro_integration_plugin_myprofile', :action => 'create_gitlab'} %> | 1 | +<div id="gitlab"> |
| 9 | 2 | ||
| 10 | - </h2> | 3 | +<h3> |
| 4 | + <%= labelled_check_box('', 'profile_data[allow_gitlab_integration]', true, profile.allow_gitlab_integration, {:class => "toggle_checkbox", 'data-selector' => "ul.gitlab"}) %> | ||
| 5 | + <%= _('Gitlab Integration') %> | ||
| 6 | +</h3> | ||
| 7 | +<ul class="gitlab"> | ||
| 8 | + <li> | ||
| 9 | + <span class="label"><%= _('Server Host:') %><span> | ||
| 10 | + <span class="value"><%= profile.gitlab_host %><span> | ||
| 11 | + <%= link_to _('Force'), {:controller => 'serpro_integration_plugin_myprofile', :action => 'create_gitlab'}, {:remote => true} %> | ||
| 12 | + </li> | ||
| 11 | <li> | 13 | <li> |
| 12 | - <%= labelled_text_field(_('Server Host'), 'profile_data[gitlab][host]', profile.gitlab[:host]) %> | 14 | + <%= labelled_text_field(_('Project Name:'), 'profile_data[gitlab][project_name]', profile.gitlab_project_name ) %> |
| 13 | </li> | 15 | </li> |
| 14 | <li> | 16 | <li> |
| 15 | - <%= labelled_text_field(_('User private token: '), 'profile_data[gitlab][private_token]', profile.gitlab[:private_token]) %> | 17 | + <%= labelled_text_field(_('Owner Email:'), 'profile_data[gitlab][email]', profile.gitlab[:email] || current_user.person.email ) %> |
| 16 | </li> | 18 | </li> |
| 17 | <li> | 19 | <li> |
| 18 | <%= _('Erros: %s') % (profile.gitlab[:errors] || _('None')) %> | 20 | <%= _('Erros: %s') % (profile.gitlab[:errors] || _('None')) %> |
| 19 | </li> | 21 | </li> |
| 20 | 22 | ||
| 21 | </ul> | 23 | </ul> |
| 22 | - | 24 | +</div> |
plugins/serpro_integration/views/serpro_integration_plugin_admin/index.html.erb
0 → 100644
| @@ -0,0 +1,18 @@ | @@ -0,0 +1,18 @@ | ||
| 1 | +<h1><%= _('Serpro Integration Settings')%></h1> | ||
| 2 | + | ||
| 3 | +<%= form_for(:settings) do |f| %> | ||
| 4 | + | ||
| 5 | + <div class="gitlab_settings"> | ||
| 6 | + <h2><%= _('Gitlab Settings')%></h2> | ||
| 7 | + <%= f.fields_for :gitlab, OpenStruct.new(@settings.gitlab) do |g| %> | ||
| 8 | + <%= labelled_form_field _('Server Host'), g.text_field("host") %> | ||
| 9 | + <%= labelled_form_field _('Private Token'), g.text_field(:private_token) %> | ||
| 10 | + <% end %> | ||
| 11 | + </div> | ||
| 12 | + | ||
| 13 | + <% button_bar do %> | ||
| 14 | + <%= submit_button(:save, _('Save'), :cancel => {:controller => 'plugins', :action => 'index'}) %> | ||
| 15 | + <% end %> | ||
| 16 | + | ||
| 17 | +<% end %> | ||
| 18 | + |