Commit fcbc8630c87f6f41dfc717c559b2d34d2e9d649d
1 parent
a4bff7fa
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Adding admin configuration to choose which templates could be used for integration
Showing
5 changed files
with
23 additions
and
44 deletions
Show diff stats
plugins/serpro_integration/lib/ext/community.rb
| @@ -3,8 +3,8 @@ require_dependency 'community' | @@ -3,8 +3,8 @@ require_dependency 'community' | ||
| 3 | class Community | 3 | class Community |
| 4 | 4 | ||
| 5 | settings_items :allow_sonar_integration, :type => :boolean, :default => false | 5 | settings_items :allow_sonar_integration, :type => :boolean, :default => false |
| 6 | - settings_items :allow_gitlab_integration, :type => :boolean, :default => false | ||
| 7 | - settings_items :allow_jenkins_integration, :type => :boolean, :default => false | 6 | + settings_items :allow_gitlab_integration, :type => :boolean, :default => true |
| 7 | + settings_items :allow_jenkins_integration, :type => :boolean, :default => true | ||
| 8 | 8 | ||
| 9 | settings_items :serpro_integration_plugin_gitlab, :type => Hash, :default => {} | 9 | settings_items :serpro_integration_plugin_gitlab, :type => Hash, :default => {} |
| 10 | settings_items :serpro_integration_plugin_jenkins, :type => Hash, :default => {} | 10 | settings_items :serpro_integration_plugin_jenkins, :type => Hash, :default => {} |
| @@ -12,10 +12,9 @@ class Community | @@ -12,10 +12,9 @@ class Community | ||
| 12 | 12 | ||
| 13 | attr_accessible :allow_unauthenticated_comments, :allow_gitlab_integration, :allow_sonar_integration, :allow_jenkins_integration, :serpro_integration_plugin_gitlab, :serpro_integration_plugin_jenkins, :serpro_integration_plugin_sonar | 13 | attr_accessible :allow_unauthenticated_comments, :allow_gitlab_integration, :allow_sonar_integration, :allow_jenkins_integration, :serpro_integration_plugin_gitlab, :serpro_integration_plugin_jenkins, :serpro_integration_plugin_sonar |
| 14 | 14 | ||
| 15 | - before_update :create_integration_projects | 15 | + after_create :create_integration_projects, :if => lambda { |c| c.allow_serpro_integration?} |
| 16 | 16 | ||
| 17 | def create_integration_projects | 17 | def create_integration_projects |
| 18 | - return unless setting_changed?(:serpro_integration_plugin_gitlab) | ||
| 19 | 18 | ||
| 20 | if allow_gitlab_integration | 19 | if allow_gitlab_integration |
| 21 | gitlab_integration = SerproIntegrationPlugin::GitlabIntegration.new(gitlab_host, gitlab_private_token) | 20 | gitlab_integration = SerproIntegrationPlugin::GitlabIntegration.new(gitlab_host, gitlab_private_token) |
| @@ -68,4 +67,9 @@ class Community | @@ -68,4 +67,9 @@ class Community | ||
| 68 | serpro_integration_plugin_jenkins[:project_name] || self.identifier | 67 | serpro_integration_plugin_jenkins[:project_name] || self.identifier |
| 69 | end | 68 | end |
| 70 | 69 | ||
| 70 | + def allow_serpro_integration? | ||
| 71 | + allow = serpro_integration_plugin_settings.communities[:templates].include?(self.id.to_s) | ||
| 72 | + allow || serpro_integration_plugin_settings.communities[:templates].include?(self.template_id.to_s) | ||
| 73 | + end | ||
| 74 | + | ||
| 71 | end | 75 | end |
plugins/serpro_integration/views/profile-editor-extras.html.erb
| 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> | 1 | +<% if profile.allow_serpro_integration? %> |
| 2 | + <div id='serpro-integration'> | ||
| 3 | + <h2><%= _('Serpro Integration') %></h2> | ||
| 18 | 4 | ||
| 19 | -<div id='serpro-integration'> | ||
| 20 | - <h2><%= _('Serpro Integration') %></h2> | ||
| 21 | - | ||
| 22 | - <%= render :partial => 'gitlab' %> | ||
| 23 | - <%= render :partial => 'jenkins' %> | ||
| 24 | - | ||
| 25 | - <div id="sonar"> | ||
| 26 | - <h3> | ||
| 27 | - <%= labelled_check_box('', 'profile_data[allow_sonar_integration]', true, profile.allow_sonar_integration, {:class => "toggle_checkbox", 'data-selector' => 'ul.sonar'}) %> | ||
| 28 | - <%= _('Sonar Integration') %> | ||
| 29 | - </h3> | ||
| 30 | - <ul class='sonar'> | ||
| 31 | - <li> | ||
| 32 | - <%= labelled_text_field(_('Server Host'), 'profile_data[serpro_integration_plugin_sonar][host]', profile.serpro_integration_plugin_sonar[:host]) %> | ||
| 33 | - </li> | ||
| 34 | - <li> | ||
| 35 | - <%= labelled_text_field(_('Project: '), 'profile_data[serpro_integration_plugin_sonar][project]', profile.serpro_integration_plugin_sonar[:project]) %> | ||
| 36 | - </li> | ||
| 37 | - </ul> | 5 | + <%= render :partial => 'gitlab' %> |
| 6 | + <%= render :partial => 'jenkins' %> | ||
| 38 | </div> | 7 | </div> |
| 39 | - | ||
| 40 | -</div> | 8 | +<% end %> |
plugins/serpro_integration/views/profile_editor/_gitlab.html.erb
| 1 | <div id="gitlab"> | 1 | <div id="gitlab"> |
| 2 | 2 | ||
| 3 | <h3> | 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') %> | 4 | <%= _('Gitlab Integration') %> |
| 6 | </h3> | 5 | </h3> |
| 7 | <ul class="gitlab"> | 6 | <ul class="gitlab"> |
| 8 | <li> | 7 | <li> |
| 9 | <span class="label"><%= _('Server Host:') %><span> | 8 | <span class="label"><%= _('Server Host:') %><span> |
| 10 | <span class="value"><%= profile.gitlab_host %><span> | 9 | <span class="value"><%= profile.gitlab_host %><span> |
| 10 | +<!-- FIXME put the force button to works | ||
| 11 | <%= link_to _('Force'), {:controller => 'serpro_integration_plugin_myprofile', :action => 'create_gitlab'}, {:remote => true} %> | 11 | <%= link_to _('Force'), {:controller => 'serpro_integration_plugin_myprofile', :action => 'create_gitlab'}, {:remote => true} %> |
| 12 | +--> | ||
| 12 | </li> | 13 | </li> |
| 13 | <li> | 14 | <li> |
| 14 | <%= labelled_text_field(_('Group Name:'), 'profile_data[serpro_integration_plugin_gitlab][group]', profile.gitlab_group) %> | 15 | <%= labelled_text_field(_('Group Name:'), 'profile_data[serpro_integration_plugin_gitlab][group]', profile.gitlab_group) %> |
plugins/serpro_integration/views/profile_editor/_jenkins.html.erb
| 1 | <div id="jenkins"> | 1 | <div id="jenkins"> |
| 2 | <h3> | 2 | <h3> |
| 3 | - <%= labelled_check_box('', 'profile_data[allow_jenkins_integration]', true, profile.allow_jenkins_integration, {:class => "toggle_checkbox", 'data-selector' => 'ul.jenkins'}) %> | ||
| 4 | <%= _('Jenkins Integration') %> | 3 | <%= _('Jenkins Integration') %> |
| 5 | </h3> | 4 | </h3> |
| 6 | <ul class='jenkins'> | 5 | <ul class='jenkins'> |
plugins/serpro_integration/views/serpro_integration_plugin_admin/index.html.erb
| @@ -2,6 +2,13 @@ | @@ -2,6 +2,13 @@ | ||
| 2 | 2 | ||
| 3 | <%= form_for(:settings) do |f| %> | 3 | <%= form_for(:settings) do |f| %> |
| 4 | 4 | ||
| 5 | + <div class="community_settings"> | ||
| 6 | + <h2><%= _('Community Templates')%></h2> | ||
| 7 | + <%= f.fields_for :communities, OpenStruct.new(@settings.communities) do |g| %> | ||
| 8 | + <%= labelled_form_field _('Communities where integrations will be applied'), g.select("templates", @environment.communities.templates.map{|t| [t.name, t.id]},{}, :multiple => true) %> | ||
| 9 | + <% end %> | ||
| 10 | + </div> | ||
| 11 | + | ||
| 5 | <div class="gitlab_settings"> | 12 | <div class="gitlab_settings"> |
| 6 | <h2><%= _('Gitlab Settings')%></h2> | 13 | <h2><%= _('Gitlab Settings')%></h2> |
| 7 | <%= f.fields_for :gitlab, OpenStruct.new(@settings.gitlab) do |g| %> | 14 | <%= f.fields_for :gitlab, OpenStruct.new(@settings.gitlab) do |g| %> |