+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-import org.sonar.api.web.AbstractRubyTemplate;
-import org.sonar.api.web.NavigationSection;
-import org.sonar.api.web.RubyRailsPage;
-
-@NavigationSection({NavigationSection.HOME})
-public class RubyApiGlobalPage extends AbstractRubyTemplate implements RubyRailsPage {
-
- public String getId() {
- return getClass().getName();
- }
-
- public String getTitle() {
- return "Ruby API Global Page";
- }
-
- @Override
- public String getTemplatePath() {
- return "/ruby-api-global-page.erb";
- }
-
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-import org.sonar.api.web.AbstractRubyTemplate;
-import org.sonar.api.web.NavigationSection;
-import org.sonar.api.web.RubyRailsPage;
-import org.sonar.api.web.UserRole;
-
-@NavigationSection({NavigationSection.RESOURCE})
-@UserRole(UserRole.USER)
-public class RubyApiProjectPage extends AbstractRubyTemplate implements RubyRailsPage {
-
- public String getId() {
- return getClass().getName();
- }
-
- public String getTitle() {
- return "Ruby API Project Page";
- }
-
- @Override
- public String getTemplatePath() {
- return "/ruby-api-project-page.erb";
- }
-
-}
public List getExtensions() {
return Arrays.asList(
FakePageDecorations.class,
- RubyApiGlobalPage.class,
- RubyApiProjectPage.class,
ResourceConfigurationPage.class
);
}
+++ /dev/null
-<h1>Ruby API Global Page</h1>
-
-<% success=true %>
-
-<% if logged_in? %>
- <h2>User Properties</h2>
- <ul id="user_properties">
- <%
- current_user.set_property({:prop_key => 'foo', :text_value => 'bar'})
- test=current_user.property_value('foo')=='bar'
- success&=test
- %>
- <li>create: <%= 'OK' if test -%></li>
-
- <%
- current_user.delete_property('foo')
- test=current_user.property('foo').nil?
- success&=test
- %>
- <li>delete: <%= 'OK' if test -%></li>
-
- <%
- current_user.set_property({:prop_key => 'foo', :text_value => 'bar'})
- current_user.set_property({:prop_key => 'foo', :text_value => 'newbar'})
- test=current_user.property_value('foo')=='newbar'
- success&=test
- %>
- <li>update: <%= 'OK' if test -%></li>
- </ul>
-<% end %>
-
-<br/>
-<p>Result: <span id="ruby-api-result"><%= success ? 'OK' : 'FAIL' %></span></p>
+++ /dev/null
-<h1>Ruby API Project</h1>
-
-<p>Project name is: <span id="ruby-api-project"><%= @project.name -%></span></p>
@Test
public void test_ruby_extensions() {
Selenese selenese = Selenese.builder().setHtmlTestsInClasspath("ui-ruby-extensions",
- "/uiExtension/UiExtensionsTest/ruby-api-tester.html",
"/uiExtension/UiExtensionsTest/ruby-rails-app.html",
"/uiExtension/UiExtensionsTest/ruby-rails-app-advanced.html"
).build();
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head profile="http://selenium-ide.openqa.org/profiles/test-case">
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
- <title>ruby-api</title>
-</head>
-<body>
-<table cellpadding="1" cellspacing="1" border="1">
- <thead>
- <tr>
- <td rowspan="1" colspan="3">ruby-api</td>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td>open</td>
- <td>/</td>
- <td></td>
- </tr>
- <tr>
- <td>waitForElementPresent</td>
- <td>link=Ruby API Global Page</td>
- <td></td>
- </tr>
- <tr>
- <td>clickAndWait</td>
- <td>link=Ruby API Global Page</td>
- <td></td>
- </tr>
- <tr>
- <td>waitForText</td>
- <td>ruby-api-result</td>
- <td>OK</td>
- </tr>
- </tbody>
-</table>
-</body>
-</html>
private
- def validation_messages_to_json(messages)
- hash={}
- hash[:errors]=messages.getErrors().to_a.map { |message| message }
- hash[:warnings]=messages.getWarnings().to_a.map { |message| message }
- hash[:infos]=messages.getInfos().to_a.map { |message| message }
- hash
- end
-
- def validation_result_to_json(result)
- hash={}
- hash[:warnings]=result.warnings().to_a.map { |message| message }
- hash[:infos]=result.infos().to_a.map { |message| message }
- hash
- end
-
def filter_rules
conditions=['active_rules.profile_id=?']
condition_values=[@profile.id]
@hide_sidebar = true
end
- #
- # SETTINGS
- #
- # TODO - remove from ApplicationController
- def by_category_name(categories)
- Api::Utils.insensitive_sort(categories) { |category| category_name(category) }
- end
-
- # TODO - remove from ApplicationController
- def by_subcategory_name(category, subcategories)
- Api::Utils.insensitive_sort(subcategories) { |subcategory|
- if (subcategory == category)
- # Hack to have default category in first position
- "aaaaa"
- else
- subcategory_name(category, subcategory)
- end
- }
- end
-
- # TODO - remove from ApplicationController
- def category_name(category)
- # Try with lowercase key then with original key for backward compatibility
- message("property.category.#{category.key}", :default => message("property.category.#{category.originalKey}", :default => category.originalKey))
- end
-
- # TODO - remove from ApplicationController
- def subcategory_name(category, subcategory)
- if (category.key == subcategory.key)
- # If subcategory == category then it is the default one
- category_name(category)
- else
- # Try with lowercase key then with original key for backward compatibility
- message("property.category.#{category.key}.#{subcategory.key}",
- :default => message("property.category.#{category.originalKey}.#{subcategory.originalKey}", :default => subcategory.originalKey))
- end
- end
-
- # TODO - remove from ApplicationController
- def processProperties(definitions_per_category)
- @categories = by_category_name(definitions_per_category.keys)
-
- if params[:category].nil?
- # Select the 'general' category by default. If 'general' category is not found, then return the first one.
- default_category = @categories.empty? ? nil : (@categories.find {|c| c && c.key.downcase == 'general'} || @categories[0])
- @category = default_category
- else
- @category = @categories.find {|c| c && c.key.casecmp(params[:category])==0}
- not_found('category') if @category.nil?
- end
-
- unless @category.isSpecial then
- @subcategories_per_categories = {}
- definitions_per_category.each {|category, definitions_per_subcategories| @subcategories_per_categories.store(category, by_subcategory_name(category, definitions_per_subcategories.keys)) }
-
- if params[:subcategory].nil?
- default_subcategory =
- @subcategories_per_categories[@category].nil? ? nil :
- ((@subcategories_per_categories[@category].include? @category) ? @category : @subcategories_per_categories[@category][0])
- @subcategory = default_subcategory
- else
- @subcategory = @subcategories_per_categories[@category].find {|s| s && s.key.casecmp(params[:subcategory])==0}
- not_found('subcategory') if @subcategory.nil?
- end
-
- @definitions = definitions_per_category[@category] || {}
- @definitions = @definitions[@subcategory] || []
- end
- end
-
end
SECTION=Navigation::SECTION_RESOURCE
helper :dashboard
- helper UsersHelper
# DO NOT REMOVE - used by eclipse plugin
def index
SECTION=Navigation::SECTION_QUALITY_PROFILES
- RULE_PRIORITIES = Sonar::RulePriority.as_options.reverse
-
# deprecated since 2.3
def export
redirect_to request.query_parameters.merge({:controller => 'profiles', :action => 'export'})
metrics.map {|m| m.domain(translate)}.uniq.compact.sort
end
- def options_grouped_by_domain(metrics, selected_key='', options={})
- metrics_per_domain={}
- metrics.each do |metric|
- domain=metric.domain || ''
- metrics_per_domain[domain]||=[]
- metrics_per_domain[domain]<<metric
- end
-
- html=''
- if options[:include_empty]==true
- html+= "<option value=''></option>"
- end
-
- metrics_per_domain.keys.sort.each do |domain|
- html += "<optgroup label=\"#{html_escape(domain)}\">"
- metrics_per_domain[domain].each do |m|
- selected_attr = (m.key==selected_key || m.id==selected_key) ? " selected='selected'" : ''
- html += "<option value='#{html_escape(m.key)}'#{selected_attr}>#{html_escape(m.short_name)}</option>"
- end
- html += '</optgroup>'
- end
- html
- end
end
+++ /dev/null
- #
- # SonarQube, open source software quality management tool.
- # Copyright (C) 2008-2014 SonarSource
- # mailto:contact AT sonarsource DOT com
- #
- # SonarQube is free software; you can redistribute it and/or
- # modify it under the terms of the GNU Lesser General Public
- # License as published by the Free Software Foundation; either
- # version 3 of the License, or (at your option) any later version.
- #
- # SonarQube is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- # Lesser General Public License for more details.
- #
- # You should have received a copy of the GNU Lesser General Public License
- # along with this program; if not, write to the Free Software Foundation,
- # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- #
-module PluginsHelper
-
-end
+++ /dev/null
-#
-# SonarQube, open source software quality management tool.
-# Copyright (C) 2008-2014 SonarSource
-# mailto:contact AT sonarsource DOT com
-#
-# SonarQube is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 3 of the License, or (at your option) any later version.
-#
-# SonarQube is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License
-# along with this program; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-module ProfilesHelper
-
- def languages
- controller.java_facade.getLanguages()
- end
-
- def label_for_rules_count(qProfile, all_profile_stats)
- profile_stat = all_profile_stats[qProfile.key()] if all_profile_stats
- profile_rules_count = profile_rules_count(profile_stat)
- label = "#{profile_rules_count} #{message('rules').downcase}"
-
- count_overriding = overriding_rules_count(profile_stat)
- if count_overriding && count_overriding>0
- label += message('quality_profiles.including_x_overriding.suffix', :params => count_overriding)
- label += image_tag('overrides.png')
- end
- label
- end
-
- def options_for_profiles(profiles, selected_id=nil)
- html=""
- profiles.group_by(&:language).each do |language, profiles|
- html += "<optgroup label=\"#{html_escape(language)}\">"
- profiles.each do |profile|
- html += "<option value='#{profile.id}' #{'selected' if profile.id==selected_id}>#{html_escape(profile.name)}</option>"
- end
- html += "</optgroup>"
- end
- html
- end
-
- def projects_count(qProfile)
- Internal.quality_profiles.countProjects(qProfile).to_i
- end
-
- def profile_rules_count(profile_stat)
- count = 0
- count = profile_stat.get('countActiveRules').get(0).getValue() if profile_stat && profile_stat.get('countActiveRules')
- count
- end
-
- def overriding_rules_count(profile_stat)
- inheritance_stats = Hash[ *profile_stat.get('inheritance').collect { |v| [ v.getKey(), v ] }.flatten ] if profile_stat
- inheritance_stats['OVERRIDES'].getValue().to_i if inheritance_stats && inheritance_stats['OVERRIDES']
- end
-end
#
module ProjectHelper
include ActionView::Helpers::UrlHelper
- include SettingsHelper
def formatted_value(measure, default='')
measure ? measure.formatted_value : default
Api::Utils.insensitive_sort(groups) { |group| group ? group.name : '' }
end
- def all_groups
- [nil].concat(Api::Utils.insensitive_sort(Group.all) { |group| group.name })
- end
-
def group_name(group)
group ? group.name : 'Anyone'
end
- def group_ref(group_name)
- group_name.blank? ? 'Anyone' : group_name
- end
-
- def default_project_group_names(role, qualifier)
- group_names=(controller.java_facade.getConfigurationValue("sonar.role.#{role}.#{qualifier}.defaultGroups")||'').split(',')
-
- # verify that groups still exist
- result = []
- if group_names.size>0
- groups = Group.all(:conditions => ['name in (?)', group_names])
- result = Api::Utils.insensitive_sort(groups.map{|g| g.name})
- result = ['Anyone'].concat(result) if group_names.include? 'Anyone'
- end
- result
- end
-
- def default_project_users(role, qualifier)
- logins=(controller.java_facade.getConfigurationValue("sonar.role.#{role}.#{qualifier}.defaultUsers") || '').split(',')
- users = User.all(:conditions => ['login in (?) and active=?', logins, true])
- Api::Utils.insensitive_sort(users) { |user| user.name }
- end
-
- def role_name(role)
- case (role.to_s)
- when 'admin' then
- 'Administrators'
- when 'user' then
- 'Users'
- when 'codeviewer' then
- 'Code Viewers'
- else
- role.to_s
- end
- end
-
- def global_role_name(role)
- message("global_permissions.#{role}", :default => role)
- end
-
- def link_to_edit_roles_permission_form(label, role, resource_id, html_id)
- link_to message(label), {:controller => :roles, :action => :edit_users, :role => role, :resource => resource_id},
- :id => html_id, :class => 'open-modal link-action nowrap', 'modal-width' => '540px'
- end
-
- def link_to_edit_groups_permission_form(label, role, resource_id, html_id)
- link_to message(label), {:controller => :roles, :action => :edit_groups, :role => role, :resource => resource_id},
- :id => html_id, :class => 'open-modal link-action nowrap', 'modal-width' => '540px'
- end
-
end
+++ /dev/null
-#
-# SonarQube, open source software quality management tool.
-# Copyright (C) 2008-2014 SonarSource
-# mailto:contact AT sonarsource DOT com
-#
-# SonarQube is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 3 of the License, or (at your option) any later version.
-#
-# SonarQube is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License
-# along with this program; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-module RulesConfigurationHelper
- include PropertiesHelper
-
- def property_type(type)
- value_type = type.type
- return PropertyType::TYPE_STRING if value_type == 'STRING'
- return PropertyType::TYPE_INTEGER if value_type == 'INTEGER'
- return PropertyType::TYPE_BOOLEAN if value_type == 'BOOLEAN'
- return PropertyType::TYPE_STRING if value_type == 'SINGLE_SELECT_LIST'
- value_type
- end
-
- def readable_type(type)
- property_type = property_type(type)
-
- return "Number" if property_type == PropertyType::TYPE_INTEGER
- return "Set of comma delimited values" if type.type() == PropertyType::TYPE_SINGLE_SELECT_LIST
- ""
- end
-
- def param_value_input(rule, parameter, value, options = {})
- property_type = property_type(parameter.type())
- name = options[:name] || 'value'
- property_input_field name, property_type, value, 'WIDGET', {:id => "#{rule.id().to_s}#{parameter.key().to_s}", :size => options[:size]}.update(options)
- end
-
- def rule_key(qProfileRule)
- "#{qProfileRule.repositoryKey().to_s}:#{qProfileRule.key().to_s}"
- end
-
- def html_text(text)
- Api::Utils.markdown_to_html(text)
- end
-
- def plain_text(text)
- Api::Utils.convert_string_to_unix_newlines(text)
- end
-
-end
-
+++ /dev/null
-#
-# SonarQube, open source software quality management tool.
-# Copyright (C) 2008-2014 SonarSource
-# mailto:contact AT sonarsource DOT com
-#
-# SonarQube is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 3 of the License, or (at your option) any later version.
-#
-# SonarQube is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License
-# along with this program; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-module SettingsHelper
- include PropertiesHelper
-
- def category_name(category)
- # Try with lowercase key then with original key for backward compatibility
- message("property.category.#{category.key}", :default => message("property.category.#{category.originalKey}", :default => category.originalKey))
- end
-
- def subcategory_name(category, subcategory)
- if (category.key == subcategory.key)
- # If subcategory == category then it is the default one
- category_name(category)
- else
- # Try with lowercase key then with original key for backward compatibility
- message("property.category.#{category.key}.#{subcategory.key}",
- :default => message("property.category.#{category.originalKey}.#{subcategory.originalKey}", :default => subcategory.originalKey))
- end
- end
-
- def property_name(property)
- message("property.#{property.key}.name", :default => property.name)
- end
-
- def property_description(property)
- message("property.#{property.key}.description", :default => property.description)
- end
-
- def field_name(property, field)
- message("field.#{property.key}.#{field.key}.name", :default => field.name)
- end
-
- def field_description(property, field)
- message("field.#{property.key}.#{field.key}.description", :default => field.description)
- end
-
- def key_field(property)
- property.fields.find { |f| f.key == 'key' }
- end
-
- def option_name(property, field, option)
- option_name_with_key(property.key, field && field.key, option, nil)
- end
-
- def category_help(category)
- message("category.#{category}.help", :default => '')
- end
-
- def category_desc(category)
- message("property.category.#{category.key}.description", :default => '')
- end
-
- def subcategory_desc(category, subcategory)
- message("property.category.#{category.key}.#{subcategory.key}.description", :default => '')
- end
-
- def property_value(property)
- if property.multi_values?
- Property.values(property.key, @resource && @resource.id)
- else
- Property.value(property.key, @resource && @resource.id, '')
- end
- end
-
- # for backward-compatibility with properties that do not define the type TEXT
- def property_type(property, value)
- unless property.fields.blank?
- return 'PROPERTY_SET_DEFINITION'
- end
-
- if property.type.to_s=='STRING' && value && value.include?('\n')
- return 'TEXT'
- end
-
- property.type
- end
-
- def by_property_index_or_name(properties)
- properties.sort_by { |p| [p.index, property_name(p).downcase] }
- end
-
- def input_name(property)
- name = "settings[#{h property.key}]"
- if property.multi_values?
- name += '[]'
- end
- name
- end
-end
+++ /dev/null
-#
-# SonarQube, open source software quality management tool.
-# Copyright (C) 2008-2014 SonarSource
-# mailto:contact AT sonarsource DOT com
-#
-# SonarQube is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 3 of the License, or (at your option) any later version.
-#
-# SonarQube is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License
-# along with this program; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-module SystemHelper
-
-
-end
+++ /dev/null
-#
-# SonarQube, open source software quality management tool.
-# Copyright (C) 2008-2014 SonarSource
-# mailto:contact AT sonarsource DOT com
-#
-# SonarQube is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 3 of the License, or (at your option) any later version.
-#
-# SonarQube is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License
-# along with this program; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-module UpdatecenterHelper
-
- def release_date(date)
- if date
- Time.at(date.getTime() / 1000).strftime('%b %e, %Y')
- else
- nil
- end
- end
-
-end
+++ /dev/null
-#
-# SonarQube, open source software quality management tool.
-# Copyright (C) 2008-2014 SonarSource
-# mailto:contact AT sonarsource DOT com
-#
-# SonarQube is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 3 of the License, or (at your option) any later version.
-#
-# SonarQube is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License
-# along with this program; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-module UsersHelper
-
- #
- # Use this to wrap view elements that the user can't access.
- # !! Note: this is an *interface*, not *security* feature !!
- # You need to do all access control at the controller level.
- #
- # Example:
- # <%= if_authorized?(:index, User) do link_to('List all users', users_path) end %> |
- # <%= if_authorized?(:edit, @user) do link_to('Edit this user', edit_user_path) end %> |
- # <%= if_authorized?(:destroy, @user) do link_to 'Destroy', @user, :confirm => 'Are you sure?', :method => :delete end %>
- #
- #
- def if_authorized?(action, resource, &block)
- if authorized?(action, resource)
- yield action, resource
- end
- end
-
- #
- # Link to user's page ('users/1')
- #
- # By default, their login is used as link text and link title (tooltip)
- #
- # Takes options
- # * :content_text => 'Content text in place of user.login', escaped with
- # the standard h() function.
- # * :content_method => :user_instance_method_to_call_for_content_text
- # * :title_method => :user_instance_method_to_call_for_title_attribute
- # * as well as link_to()'s standard options
- #
- # Examples:
- # link_to_user @user
- # # => <a href="/users/3" title="barmy">barmy</a>
- #
- # # if you've added a .name attribute:
- # content_tag :span, :class => :vcard do
- # (link_to_user user, :class => 'fn n', :title_method => :login, :content_method => :name) +
- # ': ' + (content_tag :span, user.email, :class => 'email')
- # end
- # # => <span class="vcard"><a href="/users/3" title="barmy" class="fn n">Cyril Fotheringay-Phipps</a>: <span class="email">barmy@blandings.com</span></span>
- #
- # link_to_user @user, :content_text => 'Your user page'
- # # => <a href="/users/3" title="barmy" class="nickname">Your user page</a>
- #
- def link_to_user(user, options={})
- raise "Invalid user" unless user
- options.reverse_merge! :content_method => :login, :title_method => :login, :class => :nickname
- content_text = options.delete(:content_text)
- content_text ||= user.send(options.delete(:content_method))
- options[:title] ||= user.send(options.delete(:title_method))
- link_to h(content_text), user_path(user), options
- end
-
- #
- # Link to login page using remote ip address as link content
- #
- # The :title (and thus, tooltip) is set to the IP address
- #
- # Examples:
- # link_to_login_with_IP
- # # => <a href="/login" title="169.69.69.69">169.69.69.69</a>
- #
- # link_to_login_with_IP :content_text => 'not signed in'
- # # => <a href="/login" title="169.69.69.69">not signed in</a>
- #
- def link_to_login_with_IP content_text=nil, options={}
- ip_addr = request.remote_ip
- content_text ||= ip_addr
- options.reverse_merge! :title => ip_addr
- if tag = options.delete(:tag)
- content_tag tag, h(content_text), options
- else
- link_to h(content_text), login_path, options
- end
- end
-
- #
- # Link to the current user's page (using link_to_user) or to the login page
- # (using link_to_login_with_IP).
- #
- def link_to_current_user(options={})
- if current_user
- link_to_user current_user, options
- else
- content_text = options.delete(:content_text) || 'not signed in'
- # kill ignored options from link_to_user
- [:content_method, :title_method].each{|opt| options.delete(opt)}
- link_to_login_with_IP content_text, options
- end
- end
-
-end
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
class ActiveRule < ActiveRecord::Base
- belongs_to :rules_profile, :class_name => 'Profile', :foreign_key => 'profile_id'
belongs_to :rule
has_many :active_rule_parameters, :dependent => :destroy
nil
end
- def inherited?
- inheritance=='INHERITED'
- end
-
- def overrides?
- inheritance=='OVERRIDES'
- end
end
+++ /dev/null
-#
-# SonarQube, open source software quality management tool.
-# Copyright (C) 2008-2014 SonarSource
-# mailto:contact AT sonarsource DOT com
-#
-# SonarQube is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 3 of the License, or (at your option) any later version.
-#
-# SonarQube is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License
-# along with this program; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-class ActiveRuleChange < ActiveRecord::Base
- belongs_to :rules_profile, :class_name => 'Profile', :foreign_key => 'profile_id'
- belongs_to :rule
- has_many :active_rule_param_changes, :dependent => :destroy
-
- def action_text
- case enabled
- when true then "on"
- when false then "off"
- when nil then "modified"
- end
- end
-
- def old_severity_text
- Sonar::RulePriority.to_s old_severity
- end
-
- def new_severity_text
- Sonar::RulePriority.to_s new_severity
- end
-
- def parameters
- active_rule_param_changes
- end
-
-end
+++ /dev/null
-#
-# SonarQube, open source software quality management tool.
-# Copyright (C) 2008-2014 SonarSource
-# mailto:contact AT sonarsource DOT com
-#
-# SonarQube is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 3 of the License, or (at your option) any later version.
-#
-# SonarQube is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License
-# License along with {library}; if not, write to the Free Software
-# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
- class ActiveRuleParamChange < ActiveRecord::Base
- belongs_to :active_rule_change
- belongs_to :rules_parameter
-
- def name
- rules_parameter.name
- end
-
- def parameter
- rules_parameter
- end
-
- end
+++ /dev/null
-#
-# SonarQube, open source software quality management tool.
-# Copyright (C) 2008-2014 SonarSource
-# mailto:contact AT sonarsource DOT com
-#
-# SonarQube is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 3 of the License, or (at your option) any later version.
-#
-# SonarQube is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License
-# along with this program; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-class Author < ActiveRecord::Base
-
- belongs_to :person, :class_name => 'Project', :foreign_key => 'person_id'
-
- validates_uniqueness_of :login
- validates_presence_of :person
- validates_length_of :login, :allow_blank => false, :maximum => 255
-
- def <=>(other)
- login<=>other.login
- end
-end
validates_uniqueness_of :name
validate :name_cant_be_anyone
- # all the users that are NOT members of this group
- def available_users
- User.find(:all, :conditions => ["active=?", true], :order => 'name') - users
- end
-
- def set_users(new_users=[])
- self.users.clear
-
- new_users=(new_users||[]).compact.uniq
- self.users = User.find(new_users)
- save
- end
-
def <=>(other)
return -1 if name.nil?
return 1 if other.nil? || other.name.nil?
set_table_name 'rules_profiles'
has_many :active_rules, :class_name => 'ActiveRule', :foreign_key => 'profile_id', :dependent => :destroy, :include => ['rule']
- has_many :active_rules_with_params, :class_name => 'ActiveRule', :foreign_key => 'profile_id', :include => ['active_rule_parameters']
- has_many :changes, :class_name => 'ActiveRuleChange', :dependent => :destroy
- MAX_NAME_LENGTH = 100
after_initialize :readonly!
- # The warnings that are set on this record, equivalent to normal ActiveRecord errors but does not prevent
- # the record from saving.
- def warnings
- @warnings ||= ActiveRecord::Errors.new(self)
- end
-
- def warnings?
- !warnings.empty?
- end
-
- def notices
- @notices ||= ActiveRecord::Errors.new(self)
- end
-
- def notices?
- not notices.empty?
- end
-
def active?
active
end
Property.value("sonar.profile.#{language}")==name
end
- def active_by_rule_id(rule_id)
- active_hash_by_rule_id[rule_id]
- end
-
- def self.options_for_select
- array=[]
- Profile.all(:order => 'name').each do |profile|
- label = profile.name
- label = label + ' (active)' if profile.default_profile?
- array<<[label, profile.id]
- end
- array
- end
-
- @active_hash_by_rule_id=nil
-
- def active_hash_by_rule_id
- if @active_hash_by_rule_id.nil?
- @active_hash_by_rule_id={}
- active_rules_with_params.each do |active_rule|
- @active_hash_by_rule_id[active_rule.rule_id]=active_rule
- end
- end
- @active_hash_by_rule_id
- end
-
- def deletable?
- !default_profile? && children.empty?
- end
-
- def count_overriding_rules
- @count_overriding_rules||=
- begin
- active_rules.count(:conditions => ['inheritance=?', 'OVERRIDES'])
- end
- end
-
- def inherited?
- parent_kee.present?
- end
-
- def parent
- @parent||=
- begin
- if parent_kee.present?
- Profile.first(:conditions => ['language=? and kee=?', language, parent_kee])
- else
- nil
- end
- end
- end
-
- def children
- @children ||=
- begin
- Profile.all(:conditions => ['parent_kee=? and language=?', kee, language])
- end
- end
-
- def count_active_rules
- active_rules.select { |ar| ar.rule.enabled? }.size
- end
-
- def ancestors
- @ancestors ||=
- begin
- array=[]
- if parent
- array<<parent
- array.concat(parent.ancestors)
- end
- array
- end
- end
-
- def projects?
- !projects.empty?
- end
-
- def projects
- @projects ||=
- begin
- Project.all(:joins => 'LEFT JOIN properties ON properties.resource_id = projects.id',
- :conditions => ['properties.resource_id is not null and properties.prop_key=? and properties.text_value like ?', "sonar.profile.#{language}", name])
- end
- end
-
- def add_project_id(project_id)
- Property.set("sonar.profile.#{language}", name, project_id)
- @projects = nil
- end
-
- def remove_projects
- Property.clear_for_resources("sonar.profile.#{language}", name)
- @projects = nil
- end
-
def to_hash_json
{
:name => name,
}
end
- def self.reset_default_profile_for_project_id(lang, project_id)
- Property.clear("sonar.profile.#{lang}", project_id)
- end
-
- def self.by_project_id(language, project_id, returns_default_if_nil=false)
- profile_name=Property.value("sonar.profile.#{language}", project_id)
- profile = (profile_name.present? ? Profile.find_by_name_and_language(profile_name, language) : nil)
-
- if !profile && returns_default_if_nil
- profile = by_default(language)
- end
- profile
- end
-
def self.by_default(language)
default_name = Property.value("sonar.profile.#{language}")
default_name.present? ? Profile.first(:conditions => {:name => default_name, :language => language}) : nil
end
- # Results are NOT sorted
- def self.all_by_language(language)
- Profile.all(:conditions => {:language => language})
- end
-
def self.find_by_name_and_language(name, language)
Profile.first(:conditions => {:name => name, :language => language})
end
+++ /dev/null
-#
-# SonarQube, open source software quality management tool.
-# Copyright (C) 2008-2014 SonarSource
-# mailto:contact AT sonarsource DOT com
-#
-# SonarQube is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 3 of the License, or (at your option) any later version.
-#
-# SonarQube is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License
-# along with this program; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-
-#
-# Class that centralizes the management of resource deletions in Sonar Web UI
-#
-
-require 'singleton'
-require 'thread'
-
-class ResourceDeletionManager
-
- # mixin the singleton module to ensure we have only one instance of the class
- # it will be accessible with "ResourceDeletionManager.instance"
- include Singleton
-
- # the status of the migration
- @status
- AVAILABLE = "AVAILABLE"
- WORKING = "WORKING"
-
- # the corresponding message that can be given to the user
- @message
-
- # list of resources that could not be deleted because of a problem
- @failed_deletions
-
- # the time when the deletion was started
- @start_time
-
- def initialize
- reinit()
- end
-
- def reinit
- @message = nil
- @status = AVAILABLE
- @failed_deletions = []
- end
-
- def message
- @message
- end
-
- def currently_deleting_resources?
- @status==WORKING
- end
-
- def deletion_failures_occured?
- !failed_deletions.empty?
- end
-
- def failed_deletions
- @failed_deletions
- end
-
- def deletion_start_time
- @start_time
- end
-
- def delete_resources(resource_ids=[])
- # Use an exclusive block of code to ensure that only 1 thread will be able to proceed with the deletion
- can_start_deletion = false
- Thread.exclusive do
- unless currently_deleting_resources?
- reinit()
- @status = WORKING
- @message = Api::Utils.message('bulk_deletion.deletion_manager.deleting_resources')
- can_start_deletion = true
- end
- end
-
- if can_start_deletion
- if resource_ids.empty?
- @status = AVAILABLE
- @message = Api::Utils.message('bulk_deletion.deletion_manager.no_resource_to_delete')
- else
- Thread.new do
- Thread.current[:name] = "Bulk Deletion of Projects"
- @start_time = Time.now
-
- java_facade = Java::OrgSonarServerUi::JRubyFacade.getInstance()
- # launch the deletion
- resource_ids.each_with_index do |resource_id, index|
- resource = Project.first(:conditions => {:id => resource_id.to_i})
- @message = Api::Utils.message('bulk_deletion.deletion_manager.currently_deleting_x_out_of_x', :params => [(index+1).to_s, resource_ids.size.to_s])
- if resource && java_facade.getResourceTypeBooleanProperty(resource.qualifier, 'deletable')
- begin
- java_facade.deleteResourceTree(resource.key)
- rescue Exception => e
- @failed_deletions << resource.name
- # no need to rethrow the exception as it has been logged by the Java component
- end
- end
- end
-
- @status = AVAILABLE
- @message = Api::Utils.message('bulk_deletion.deletion_manager.deletion_completed')
- @message += ' ' + Api::Utils.message('bulk_deletion.deletion_manager.however_failures_occurred') unless @failed_deletions.empty?
- end
- end
- end
- end
-
-end
Rule.first(:conditions => ['status=? and plugin_name=? and id=?', STATUS_READY, MANUAL_REPOSITORY_KEY, id])
end
- def self.create_manual_rule(options)
- key = options[:name].strip.downcase.gsub(/\s/, '_')
- creation_options = {:name => options[:name],
- :description => options[:description],
- :plugin_rule_key => key,
- :status => STATUS_READY,
- :is_template => false,
- :plugin_name => MANUAL_REPOSITORY_KEY}
- Rule.create!(creation_options)
- end
-
def self.to_hash(java_rule)
l10n_name = java_rule.getName()
l10n_desc = java_rule.getDescription()
hash
end
- def to_hash_json(profile, active_rule = nil)
- json = {'title' => name, 'key' => key, 'plugin' => plugin_name, 'config_key' => config_key}
- json['description'] = description if description
- if profile
- active_rule = active_rule || profile.active_by_rule_id(id)
- if active_rule
- json['priority'] = active_rule.priority_text
- json['status'] = 'ACTIVE'
- else
- json['priority'] = priority_text
- json['status'] = 'INACTIVE'
- end
- else
- json['priority'] = priority_text
- end
- json['params'] = parameters.collect { |parameter| parameter.to_hash_json(active_rule) } unless parameters.empty?
- json
- end
-
- def to_xml(profile, xml)
- xml.rule do
- xml.title(name)
- xml.key(key)
- xml.config_key(config_key)
- xml.plugin(plugin_name)
- xml.description { xml.cdata!(description) } if description
- active_rule = nil
- if profile
- active_rule = profile.active_by_rule_id(id)
- if active_rule
- xml.priority(active_rule.priority_text)
- xml.status('ACTIVE')
- else
- xml.priority(priority_text)
- xml.status("INACTIVE")
- end
- else
- xml.priority(priority_text)
- end
- parameters.each do |parameter|
- parameter.to_xml(active_rule, xml)
- end
- end
- end
-
- def to_csv(profile)
- csv = [name.strip, plugin_rule_key, plugin_name]
- if profile
- active_rule = profile.active_by_rule_id(id)
- if active_rule
- csv << active_rule.priority_text
- csv << 'ACTIVE'
- else
- csv << priority_text
- csv << 'INACTIVE'
- end
- end
- csv
- end
-
def self.remove_blank(array)
if array
array = array - ['']
end
end
- def self.filter(rules, options)
- priorities = remove_blank(options[:priorities])
- profile = options[:profile]
- inheritance = options[:inheritance]
-
- if profile
- inactive = (options[:activation]=='INACTIVE')
- active = (options[:activation]=='ACTIVE')
-
- rules = rules.reject do |rule|
- active_rule = profile.active_by_rule_id(rule.id)
- ((inactive && active_rule) || (active && active_rule.nil?))
- end
-
- if priorities
- rules = rules.select do |rule|
- active_rule = profile.active_by_rule_id(rule.id)
- (active_rule && priorities.include?(active_rule.priority_text)) || (active_rule.nil? && priorities.include?(rule.priority_text))
- end
- end
-
- if inheritance=='NOT'
- rules = rules.select do |rule|
- active_rule = profile.active_by_rule_id(rule.id)
- (active_rule.nil? || active_rule.inheritance.blank?)
- end
- elsif inheritance.present? && inheritance != 'any'
- rules = rules.select do |rule|
- active_rule = profile.active_by_rule_id(rule.id)
- (active_rule && active_rule.inheritance==inheritance)
- end
- end
-
- elsif priorities
- rules = rules.select do |rule|
- priorities.include?(rule.priority_text)
- end
- end
- rules
- end
-
def self.sort_by(rules, sort_by)
case sort_by
when SORT_BY_CREATION_DATE
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
class RulesParameter < ActiveRecord::Base
- include RulesConfigurationHelper
PARAM_MAX_NUMBER = 4
#---------------------------------------------------------------------
# USER PROPERTIES
#---------------------------------------------------------------------
- def property(key)
- properties().each do |p|
- return p if (p.key==key)
- end
- nil
- end
-
- def property_value(key)
- prop=property(key)
- prop && prop.value
- end
-
- def set_property(options)
- key=options[:prop_key]
- prop=property(key)
- if prop
- prop.attributes=options
- prop.user_id=id
- prop.save!
- else
- prop=Property.new(options)
- prop.user_id=id
- properties<<prop
- end
- end
-
#
# This method is different from "set_property(options)" which can also add a new property:
# it "really" adds a property and does not try to update a existing one with the same key.
properties<<prop
end
- def delete_property(key)
- prop=property(key)
- if prop
- properties.delete(prop)
- end
- end
-
- def self.logins_to_ids(logins=[])
- if logins.size>0
- User.find(:all, :select => 'id', :conditions => ['login in (?)', logins]).map { |user| user.id }
- else
- []
- end
- end
-
#---------------------------------------------------------------------
# FAVOURITES
#---------------------------------------------------------------------
+++ /dev/null
-<%
- deletion_manager = ResourceDeletionManager.instance
- pending_deletions = deletion_manager.currently_deleting_resources?
- failed_deletions = deletion_manager.failed_deletions
- start_time = deletion_manager.deletion_start_time
-%>
-
-<% if pending_deletions %>
- <meta http-equiv='refresh' content='5;'>
-<% end %>
-
-<div class="page">
- <header class="page-header">
- <h1 class="page-title"><%= message('bulk_deletion.page') -%></h1>
- </header>
-
- <div class="<%= pending_deletions ? 'admin' : 'error' -%>" style="padding:10px">
- <% if pending_deletions %>
- <%= image_tag 'loading.gif' -%>
- <% end %>
-
- <b><%= deletion_manager.message -%></b>
- <br/>
- <br/>
- <%= message('bulk_deletion.started_since_x', :params => distance_of_time_in_words(start_time, Time.now) ) -%> (<%= l start_time -%>)
- <br/>
- <br/>
-
- <% if !pending_deletions && !failed_deletions.empty? %>
- <p>
- <%= message('bulk_deletion.following_deletions_failed') -%>
- <ul style="list-style: none outside; padding-left: 30px;">
- <% failed_deletions.each do |name| %>
- <li style="list-style: disc outside; padding: 2px;"><%= name -%></li>
- <% end %>
- </ul>
- </p>
- <p>
- <a href="<%= url_after_dismiss -%>"><%= message('bulk_deletion.hide_message') -%></a>
- </p>
- <% end %>
- </div>
-</div>