package org.sonar.server.permission.ws;
-import com.google.common.collect.ImmutableSet;
-import org.sonar.api.security.DefaultGroups;
-import org.sonar.api.server.ws.RailsHandler;
import org.sonar.api.server.ws.WebService;
-import org.sonar.core.permission.GlobalPermissions;
-import org.sonar.core.permission.ProjectPermissions;
public class PermissionsWs implements WebService {
action.define(controller);
}
- defineAddAction(controller);
- defineRemoveAction(controller);
-
controller.done();
}
-
- private static void defineAddAction(NewController controller) {
- NewAction action = controller.createAction("add")
- .setDescription("Add a global or a project permission. Requires Administer System permission for global permissions, " +
- "requires Administer permission on project for project permissions")
- .setSince("3.7")
- .setPost(true)
- .setHandler(RailsHandler.INSTANCE);
- action.createParam("permission")
- .setDescription("Key of the permission to add")
- .setRequired(true)
- .setPossibleValues(ImmutableSet.<String>builder().addAll(GlobalPermissions.ALL).addAll(ProjectPermissions.ALL).build())
- .setExampleValue("shareDashboard");
- action.createParam("user")
- .setDescription("User login. Required if group is not set")
- .setExampleValue("myuser");
- action.createParam("group")
- .setDescription("Group name or \"" + DefaultGroups.ANYONE + "\". Required if user is not set")
- .setExampleValue(DefaultGroups.ADMINISTRATORS);
- action.createParam("component")
- .setDescription("Key of the project. Required if a project permission is set. Available since version 4.0")
- .setExampleValue("org.codehaus.sonar");
- RailsHandler.addFormatParam(action);
- }
-
- private static void defineRemoveAction(NewController controller) {
- NewAction action = controller.createAction("remove")
- .setDescription("Remove a global or a project permission. Requires Administer System permission for global permissions, " +
- "requires Administer permission on project for project permissions")
- .setSince("3.7")
- .setPost(true)
- .setHandler(RailsHandler.INSTANCE);
-
- action.createParam("permission")
- .setDescription("Key of the permission to remove")
- .setRequired(true)
- .setPossibleValues(ImmutableSet.<String>builder().addAll(GlobalPermissions.ALL).addAll(ProjectPermissions.ALL).build())
- .setExampleValue("shareDashboard");
- action.createParam("user")
- .setDescription("User login. Required if group is not set")
- .setExampleValue("myuser");
- action.createParam("group")
- .setDescription("Group name or \"" + DefaultGroups.ANYONE + "\". Required if user is not set")
- .setExampleValue(DefaultGroups.ADMINISTRATORS);
- action.createParam("component")
- .setDescription("Key of the project. Required if a project permission is set. Available since version 4.0")
- .setExampleValue("org.codehaus.sonar");
- RailsHandler.addFormatParam(action);
- }
-
}
import org.junit.Before;
import org.junit.Test;
-import org.sonar.api.server.ws.RailsHandler;
import org.sonar.api.server.ws.WebService;
import org.sonar.db.DbClient;
import org.sonar.server.user.UserSession;
assertThat(controller).isNotNull();
assertThat(controller.description()).isNotEmpty();
assertThat(controller.since()).isEqualTo("3.7");
- assertThat(controller.actions()).hasSize(4);
- }
-
- @Test
- public void define_add_action() {
- WebService.Action action = controller().action("add");
- assertThat(action).isNotNull();
- assertThat(action.handler()).isInstanceOf(RailsHandler.INSTANCE.getClass());
- assertThat(action.params()).hasSize(5);
-
- WebService.Param permission = action.param("permission");
- assertThat(permission).isNotNull();
- assertThat(permission.possibleValues()).hasSize(9);
- }
-
- @Test
- public void define_remove_action() {
- WebService.Action action = controller().action("remove");
- assertThat(action).isNotNull();
- assertThat(action.handler()).isInstanceOf(RailsHandler.INSTANCE.getClass());
- assertThat(action.params()).hasSize(5);
+ assertThat(controller.actions()).hasSize(2);
}
@Test