aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2013-08-16 10:54:22 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2013-08-16 10:54:22 +0200
commit5db787d457fdf31c73322d9dad0b8dc726ddb2d1 (patch)
treec7a8fd734ec8f3c58a00a2e4ebfe0385f1d952ec /sonar-server
parentdb19e222c5c7b9564ab13e096faa03cf69772701 (diff)
downloadsonarqube-5db787d457fdf31c73322d9dad0b8dc726ddb2d1.tar.gz
sonarqube-5db787d457fdf31c73322d9dad0b8dc726ddb2d1.zip
SONAR-4475 Revert commit 3554f0dddf that makes tests fail
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/java/org/sonar/server/permission/InternalPermissionService.java7
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/groups_controller.rb4
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/users_controller.rb17
-rw-r--r--sonar-server/src/main/webapp/javascripts/application.js2
-rw-r--r--sonar-server/src/test/java/org/sonar/server/permission/InternalPermissionServiceTest.java19
5 files changed, 12 insertions, 37 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/permission/InternalPermissionService.java b/sonar-server/src/main/java/org/sonar/server/permission/InternalPermissionService.java
index c6e22f94435..3fdcc998ab8 100644
--- a/sonar-server/src/main/java/org/sonar/server/permission/InternalPermissionService.java
+++ b/sonar-server/src/main/java/org/sonar/server/permission/InternalPermissionService.java
@@ -24,7 +24,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.ServerComponent;
import org.sonar.api.security.DefaultGroups;
-import org.sonar.api.utils.MessageException;
import org.sonar.core.permission.ComponentPermissionFacade;
import org.sonar.core.permission.Permission;
import org.sonar.core.user.*;
@@ -72,12 +71,6 @@ public class InternalPermissionService implements ServerComponent {
}
}
- public void checkAtLeatOneSysAdminExists(){
- if (roleDao.countUserWithPermission(Permission.SYSTEM_ADMIN.key()) == 0){
- throw new MessageException(null, "global_permissions.error.need_at_lest_one_admin", null);
- }
- }
-
private void applyPermissionTemplate(String templateKey, String componentId) {
permissionFacade.applyPermissionTemplate(templateKey, Long.parseLong(componentId));
}
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/groups_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/groups_controller.rb
index 1105fa5292b..f2d5fd5d878 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/groups_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/groups_controller.rb
@@ -23,7 +23,7 @@ class GroupsController < ApplicationController
before_filter :admin_required
def index
- @groups = Group.all(:order => 'name')
+ @groups = Group.find(:all, :order => 'name')
if params[:id]
@group = Group.find(params[:id])
else
@@ -72,7 +72,7 @@ class GroupsController < ApplicationController
end
def to_index(errors, id)
- unless errors.empty?
+ if !errors.empty?
flash[:error] = errors.full_messages.join("<br/>\n")
end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/users_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/users_controller.rb
index 98bcbad7e30..97807f9a749 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/users_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/users_controller.rb
@@ -130,16 +130,17 @@ class UsersController < ApplicationController
end
def destroy
- begin
- user = User.find(params[:id])
- Api.users.deactivate(user.login)
+ @user = User.find(params[:id])
+
+ if current_user.id==@user.id
+ flash[:error] = 'Please log in with another user in order to delete yourself.'
+
+ else
+ Api.users.deactivate(@user.login)
flash[:notice] = 'User is deleted.'
- rescue Java::OrgSonarServerExceptions::HttpException => exception
- error = exception.cause
- flash[:error] = (error.getMessage ? error.getMessage : Api::Utils.message(error.l10nKey, :params => error.l10nParams.to_a))
end
- redirect_to(:action => 'index', :id => nil)
+ to_index(@user.errors, nil)
end
def select_group
@@ -157,7 +158,7 @@ class UsersController < ApplicationController
end
def to_index(errors, id)
- unless errors.empty?
+ if !errors.empty?
flash[:error] = errors.full_messages.join("<br/>\n")
end
diff --git a/sonar-server/src/main/webapp/javascripts/application.js b/sonar-server/src/main/webapp/javascripts/application.js
index 501fd589a24..773170b1a38 100644
--- a/sonar-server/src/main/webapp/javascripts/application.js
+++ b/sonar-server/src/main/webapp/javascripts/application.js
@@ -320,8 +320,8 @@ function openModalWindow(url, options) {
$j('input[type=submit]', obj).removeAttr('disabled');
errorElt.show();
errorElt.html(xhr.responseText);
- } else {
// otherwise replace modal window by the returned text
+ } else {
$j("#modal").html(xhr.responseText);
}
}
diff --git a/sonar-server/src/test/java/org/sonar/server/permission/InternalPermissionServiceTest.java b/sonar-server/src/test/java/org/sonar/server/permission/InternalPermissionServiceTest.java
index 04d8daceb6a..6dd2f92fca6 100644
--- a/sonar-server/src/test/java/org/sonar/server/permission/InternalPermissionServiceTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/permission/InternalPermissionServiceTest.java
@@ -30,7 +30,6 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.sonar.api.security.DefaultGroups;
-import org.sonar.api.utils.MessageException;
import org.sonar.core.permission.ComponentPermissionFacade;
import org.sonar.core.permission.Permission;
import org.sonar.core.user.*;
@@ -41,8 +40,6 @@ import org.sonar.server.user.MockUserSession;
import java.util.Map;
-import static org.fest.assertions.Assertions.assertThat;
-import static org.fest.assertions.Fail.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.argThat;
import static org.mockito.Mockito.*;
@@ -194,22 +191,6 @@ public class InternalPermissionServiceTest {
verify(permissionFacade).applyPermissionTemplate("my_template_key", 3L);
}
- @Test
- public void should_check_at_least_one_sys_admin_exists() throws Exception {
- // One admin exists -> all is ok
- when(roleDao.countUserWithPermission(anyString())).thenReturn(1);
- service.checkAtLeatOneSysAdminExists();
-
- // No admin -> fail
- try {
- when(roleDao.countUserWithPermission(anyString())).thenReturn(0);
- service.checkAtLeatOneSysAdminExists();
- fail();
- } catch (Exception e){
- assertThat(e).isInstanceOf(MessageException.class);
- }
- }
-
protected static class MatchesUserRole extends BaseMatcher<UserRoleDto> {
private final UserRoleDto referenceDto;