From 2ffb378bbc42baca230efec822ef78589654713f Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Tue, 17 Dec 2013 16:54:14 +0100 Subject: [PATCH] SONAR-4535 Use Java service when loading form to rename a profile --- .../java/org/sonar/server/qualityprofile/QProfiles.java | 5 +++++ .../WEB-INF/app/controllers/profiles_controller.rb | 6 +++--- .../org/sonar/server/qualityprofile/QProfilesTest.java | 9 +++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfiles.java b/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfiles.java index edb178eb17b..cd6294d481f 100644 --- a/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfiles.java +++ b/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfiles.java @@ -92,6 +92,11 @@ public class QProfiles implements ServerComponent { // edit template rule // delete template rule + public QProfile profile(int id) { + QualityProfileDto dto = findNotNull(id); + return QProfile.from(dto); + } + public List allProfiles() { return search.allProfiles(); } diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb index cafa245112c..84208d29d49 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb @@ -35,7 +35,6 @@ class ProfilesController < ApplicationController # GET /profiles/create_form?language= def create_form - access_denied unless has_role?(:profileadmin) require_parameters 'language' render :partial => 'profiles/create_form', :locals => {:language_key => params[:language]} end @@ -325,9 +324,10 @@ class ProfilesController < ApplicationController # GET /profiles/rename_form?id= def rename_form - access_denied unless has_role?(:profileadmin) require_parameters 'id' - @profile = Profile.find(params[:id]) + call_backend do + @profile = Internal.quality_profiles.profile(params[:id].to_i) + end render :partial => 'profiles/rename_form' end diff --git a/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfilesTest.java b/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfilesTest.java index 460e8baf902..e54c445768d 100644 --- a/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfilesTest.java +++ b/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfilesTest.java @@ -73,6 +73,15 @@ public class QProfilesTest { qProfiles = new QProfiles(qualityProfileDao, resourceDao, projectService, search, service, rules); } + @Test + public void search_profile() throws Exception { + QualityProfileDto qualityProfile = new QualityProfileDto().setId(1).setName("Default").setLanguage("java"); + when(qualityProfileDao.selectById(1)).thenReturn(qualityProfile); + + qProfiles.profile(1); + verify(qualityProfileDao).selectById(1); + } + @Test public void search_profiles() throws Exception { qProfiles.allProfiles(); -- 2.39.5