From fcbc8630c87f6f41dfc717c559b2d34d2e9d649d Mon Sep 17 00:00:00 2001 From: Leandro Nunes dos Santos Date: Mon, 18 Aug 2014 10:06:50 -0300 Subject: [PATCH] Adding admin configuration to choose which templates could be used for integration --- plugins/serpro_integration/lib/ext/community.rb | 12 ++++++++---- plugins/serpro_integration/views/profile-editor-extras.html.erb | 44 ++++++-------------------------------------- plugins/serpro_integration/views/profile_editor/_gitlab.html.erb | 3 ++- plugins/serpro_integration/views/profile_editor/_jenkins.html.erb | 1 - plugins/serpro_integration/views/serpro_integration_plugin_admin/index.html.erb | 7 +++++++ 5 files changed, 23 insertions(+), 44 deletions(-) diff --git a/plugins/serpro_integration/lib/ext/community.rb b/plugins/serpro_integration/lib/ext/community.rb index 6932df5..f5ad767 100644 --- a/plugins/serpro_integration/lib/ext/community.rb +++ b/plugins/serpro_integration/lib/ext/community.rb @@ -3,8 +3,8 @@ require_dependency 'community' class Community settings_items :allow_sonar_integration, :type => :boolean, :default => false - settings_items :allow_gitlab_integration, :type => :boolean, :default => false - settings_items :allow_jenkins_integration, :type => :boolean, :default => false + settings_items :allow_gitlab_integration, :type => :boolean, :default => true + settings_items :allow_jenkins_integration, :type => :boolean, :default => true settings_items :serpro_integration_plugin_gitlab, :type => Hash, :default => {} settings_items :serpro_integration_plugin_jenkins, :type => Hash, :default => {} @@ -12,10 +12,9 @@ class Community 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 - before_update :create_integration_projects + after_create :create_integration_projects, :if => lambda { |c| c.allow_serpro_integration?} def create_integration_projects - return unless setting_changed?(:serpro_integration_plugin_gitlab) if allow_gitlab_integration gitlab_integration = SerproIntegrationPlugin::GitlabIntegration.new(gitlab_host, gitlab_private_token) @@ -68,4 +67,9 @@ class Community serpro_integration_plugin_jenkins[:project_name] || self.identifier end + def allow_serpro_integration? + allow = serpro_integration_plugin_settings.communities[:templates].include?(self.id.to_s) + allow || serpro_integration_plugin_settings.communities[:templates].include?(self.template_id.to_s) + end + end diff --git a/plugins/serpro_integration/views/profile-editor-extras.html.erb b/plugins/serpro_integration/views/profile-editor-extras.html.erb index ec1a18b..12c1ae1 100644 --- a/plugins/serpro_integration/views/profile-editor-extras.html.erb +++ b/plugins/serpro_integration/views/profile-editor-extras.html.erb @@ -1,40 +1,8 @@ - +<% if profile.allow_serpro_integration? %> +
+

<%= _('Serpro Integration') %>

-
-

<%= _('Serpro Integration') %>

- - <%= render :partial => 'gitlab' %> - <%= render :partial => 'jenkins' %> - -
-

- <%= labelled_check_box('', 'profile_data[allow_sonar_integration]', true, profile.allow_sonar_integration, {:class => "toggle_checkbox", 'data-selector' => 'ul.sonar'}) %> - <%= _('Sonar Integration') %> -

-
    -
  • - <%= labelled_text_field(_('Server Host'), 'profile_data[serpro_integration_plugin_sonar][host]', profile.serpro_integration_plugin_sonar[:host]) %> -
  • -
  • - <%= labelled_text_field(_('Project: '), 'profile_data[serpro_integration_plugin_sonar][project]', profile.serpro_integration_plugin_sonar[:project]) %> -
  • -
+ <%= render :partial => 'gitlab' %> + <%= render :partial => 'jenkins' %>
- -
+<% end %> diff --git a/plugins/serpro_integration/views/profile_editor/_gitlab.html.erb b/plugins/serpro_integration/views/profile_editor/_gitlab.html.erb index 31d3e68..d75f976 100644 --- a/plugins/serpro_integration/views/profile_editor/_gitlab.html.erb +++ b/plugins/serpro_integration/views/profile_editor/_gitlab.html.erb @@ -1,14 +1,15 @@

- <%= labelled_check_box('', 'profile_data[allow_gitlab_integration]', true, profile.allow_gitlab_integration, {:class => "toggle_checkbox", 'data-selector' => "ul.gitlab"}) %> <%= _('Gitlab Integration') %>

  • <%= _('Server Host:') %> <%= profile.gitlab_host %> +
  • <%= labelled_text_field(_('Group Name:'), 'profile_data[serpro_integration_plugin_gitlab][group]', profile.gitlab_group) %> diff --git a/plugins/serpro_integration/views/profile_editor/_jenkins.html.erb b/plugins/serpro_integration/views/profile_editor/_jenkins.html.erb index c918863..016a35d 100644 --- a/plugins/serpro_integration/views/profile_editor/_jenkins.html.erb +++ b/plugins/serpro_integration/views/profile_editor/_jenkins.html.erb @@ -1,6 +1,5 @@

    - <%= labelled_check_box('', 'profile_data[allow_jenkins_integration]', true, profile.allow_jenkins_integration, {:class => "toggle_checkbox", 'data-selector' => 'ul.jenkins'}) %> <%= _('Jenkins Integration') %>

      diff --git a/plugins/serpro_integration/views/serpro_integration_plugin_admin/index.html.erb b/plugins/serpro_integration/views/serpro_integration_plugin_admin/index.html.erb index fe08779..bb63153 100644 --- a/plugins/serpro_integration/views/serpro_integration_plugin_admin/index.html.erb +++ b/plugins/serpro_integration/views/serpro_integration_plugin_admin/index.html.erb @@ -2,6 +2,13 @@ <%= form_for(:settings) do |f| %> +
      +

      <%= _('Community Templates')%>

      + <%= f.fields_for :communities, OpenStruct.new(@settings.communities) do |g| %> + <%= labelled_form_field _('Communities where integrations will be applied'), g.select("templates", @environment.communities.templates.map{|t| [t.name, t.id]},{}, :multiple => true) %> + <% end %> +
      +

      <%= _('Gitlab Settings')%>

      <%= f.fields_for :gitlab, OpenStruct.new(@settings.gitlab) do |g| %> -- libgit2 0.21.2