# GET
#
def index
- templates_names = Internal.permission_templates.selectAllPermissionTemplates.collect {|t| t.name}
- @permission_templates = []
- @permission_templates_options = []
- templates_names.each do |template_name|
- permission_template = Internal.permission_templates.selectPermissionTemplate(template_name)
- @permission_templates << permission_template
- @permission_templates_options << [permission_template.name, permission_template.key]
- end
- @root_qualifiers = get_root_qualifiers
+ all_templates = Internal.permission_templates.selectAllPermissionTemplates
- @default_templates = {}
- default_template_property = Property.by_key("sonar.permission.template.default")
- @root_qualifiers.each do |qualifier|
- qualifier_template = Property.by_key("sonar.permission.template.#{qualifier}.default")
- @default_templates[qualifier] = qualifier_template ? qualifier_template.text_value : default_template_property.text_value
- end
+ @permission_templates = get_templates_and_permissions(all_templates)
+ @root_qualifiers = get_root_qualifiers
+ @default_templates = get_default_templates_per_qualifier(@root_qualifiers)
end
+ #
+ # GET (modal form)
+ #
def edit_users
@permission = params[:permission]
@permission_template = Internal.permission_templates.selectPermissionTemplate(params[:name])
render :partial => 'permission_templates/edit_users'
end
+ #
+ # GET (modal form)
+ #
def edit_groups
@permission = params[:permission]
@permission_template = Internal.permission_templates.selectPermissionTemplate(params[:name])
redirect_to :action => 'index'
end
-
+ #
+ # GET (modal form)
+ #
def create_form
render :partial => 'permission_templates/permission_template_form',
:locals => {:form_action => 'create', :message_title => 'new_template', :message_submit => 'create_template'}
redirect_to :action => 'index'
end
+ #
+ # GET (modal form)
+ #
def edit_form
@permission_template = Internal.permission_templates.selectPermissionTemplate(params[:name])
render :partial => 'permission_templates/permission_template_form',
redirect_to :action => 'index'
end
+ #
+ # GET (modal form)
+ #
def delete_form
@permission_template = Internal.permission_templates.selectPermissionTemplate(params[:name])
render :partial => 'permission_templates/delete_form'
redirect_to :action => 'index'
end
+ #
+ # GET (modal form)
+ #
+ def default_templates_form
+ all_templates = Internal.permission_templates.selectAllPermissionTemplates
+
+ @permission_templates_options = all_templates.collect {|t| [t.name, t.key]}
+ @root_qualifiers = get_root_qualifiers
+ @default_templates = get_default_templates_per_qualifier(@root_qualifiers)
+
+ render :partial => 'permission_templates/default_templates_form'
+ end
+
#
# POST
#
- def set_default_template
+ def update_default_templates
verify_post_request
get_root_qualifiers.each do |qualifier|
Property.set("sonar.permission.template.#{qualifier}.default", params["default_template_#{qualifier}"])
redirect_to :action => 'index'
end
+
private
def get_root_qualifiers
Java::OrgSonarServerUi::JRubyFacade.getInstance().getResourceRootTypes().map {|type| type.getQualifier()}
end
+ def get_default_templates_per_qualifier(root_qualifiers)
+ default_templates = {}
+ default_template_property = Property.by_key("sonar.permission.template.default")
+ root_qualifiers.each do |qualifier|
+ qualifier_template = Property.by_key("sonar.permission.template.#{qualifier}.default")
+ default_templates[qualifier] = qualifier_template ? qualifier_template.text_value : default_template_property.text_value
+ end
+ default_templates
+ end
+
+ def get_templates_and_permissions(permission_templates)
+ templates_names = permission_templates.collect {|t| t.name}
+ permission_templates = []
+ templates_names.each do |template_name|
+ permission_templates << Internal.permission_templates.selectPermissionTemplate(template_name)
+ end
+ permission_templates
+ end
+
end
--- /dev/null
+<form id="default-templates-form" method="post" action="<%= ApplicationController.root_context -%>/permission_templates/update_default_templates">
+ <fieldset>
+ <div class="modal-head">
+ <h2><%= message('permission_template.set_default_templates') -%></h2>
+ </div>
+ <div class="modal-body">
+ <div id="permission-template-error" class="permission-template error errors" style="display:none;" />
+ <% @root_qualifiers.each do |qualifier| %>
+ <div class="modal-field">
+ <%= label_tag("default_template_#{qualifier}", "#{message('qualifier.' + qualifier)}(s):") %>
+ <%= select_tag("default_template_#{qualifier}", options_for_select(@permission_templates_options, @default_templates[qualifier])) %>
+ </div>
+ <% end %>
+ </div>
+ <div class="modal-foot">
+ <input type="submit" value="<%= h message('permission_template.update_permissions') -%>" id="submit-default-templates"/>
+ <a href="#" onclick="return closeModalWindow()" id="cancel-default-templates"><%= h message('cancel') -%></a>
+ </div>
+ </fieldset>
+</form>
+
+<script>
+ $j("#default-templates-form").modalForm({
+ success: function (data) {
+ window.location.reload();
+ },
+ error: function (xhr, textStatus, errorThrown) {
+ var htmlClass = 'permission-template';
+ $j('input[id^="submit-default-templates"]').removeAttr('disabled');
+ $j('.' + htmlClass + '.errors').show();
+ $j('.' + htmlClass + '.errors').html(xhr.responseText);
+ }
+ });
+</script>
+
<%= render :partial => 'roles/tabs', :locals => {:selected_tab=>'Permission templates'} %>
<br/>
-<h2>Default templates</h2>
-<div class="box">
- <p>
- This section allows you to configure the default permission templates that will be applied by SonarQube while analysing your projects.
- </p>
- <% form_tag(:controller => 'permission_templates', :action => 'set_default_template') do %>
-
- <% @root_qualifiers.each do |qualifier| %>
- <%= label_tag("default_template_#{qualifier}", "Default permission template for #{message('qualifier.' + qualifier)}:") %>
- <%= select_tag("default_template_#{qualifier}", options_for_select(@permission_templates_options, @default_templates[qualifier])) %>
- <% end %>
- <br/>
- <br/>
- <%= submit_tag "Save" %>
- <% end %>
-</div>
-<br/>
<div class="line-block">
<ul style="float: right" class="horizontal">
+ <li style="padding-top: 3px; padding-right: 10px;">
+ <%= link_to message('permission_template.set_default_templates'), {:action => :default_templates_form, :qualifiers => @root_qualifiers},
+ :id => 'configure-defaults-permission-template', :class => 'open-modal link-action' %>
+ </li>
<li class="marginleft10 add">
- <a id="create-link-permission-template" href="permission_templates/create_form" class="open-modal link-action"><%= message('create') -%></a>
+ <%= link_to message('create'), {:action => :create_form}, :id => 'create-link-permission-template', :class => 'open-modal link-action' %>
</li>
</ul>
<h2>Available templates</h2>
end
if qualifiers.length > 0
%>
- <%= image_tag 'tick.png', :id => "is_active_#{u permission_template.name}" %><span class="small gray">(Default for <%= qualifiers.collect {|q| message('qualifier.' + q)}.join(',') %>)</span>
+ <%= image_tag 'tick.png', :id => "is_active_#{u permission_template.name}" %><span class="small gray">(Default for <%= qualifiers.collect {|q| message('qualifier.' + q)}.join(', ') %>)</span>
<% end %>
</td>
<td align="right">