(→AHPSCRIPTS-41)
|
(→Add Random Test Results to a BuildLife)
|
Line 542: | |||
}</pre> | }</pre> | ||
+ | = Change Owner of Project or Other Resource = | ||
+ | This script must be run as the admin user. Just change the '''projectName''' and '''newOwnerName'''. | ||
+ | ==== AHPSCRIPTS-35 ==== | ||
+ | <pre>import com.urbancode.anthill3.main.client.AnthillClient; | ||
+ | import com.urbancode.anthill3.persistence.UnitOfWork; | ||
+ | import com.urbancode.anthill3.domain.project.*; | ||
+ | import com.urbancode.anthill3.domain.security.*; | ||
+ | String projectName = "JUnit"; | ||
+ | String newOwnerName = "user"; | ||
+ | String serverHost = "localhost"; | ||
+ | int serverPort = 4567; | ||
+ | String userName = "admin"; | ||
+ | String password = "admin"; | ||
+ | //serverHost = bsh.args[0]; | ||
+ | //serverPort = Integer.parseInt(bsh.args[1]); | ||
+ | //userName = bsh.args[2]; | ||
+ | //password = bsh.args[3]; | ||
+ | // obtain connection to the Anthill server | ||
+ | AnthillClient anthill = AnthillClient.connect(serverHost, serverPort, | ||
+ | userName, password); | ||
+ | // create a Unit of Work | ||
+ | UnitOfWork uow = anthill.createUnitOfWork(); | ||
+ | // Project | ||
+ | Project project = ProjectFactory.getInstance().restoreForName(projectName); | ||
+ | if (project == null) { | ||
+ | throw new Exception("Project not found. Please check the project name and if this user has permissions to it."); | ||
+ | } | ||
+ | User user = UserFactory.getInstance().restoreForName(newOwnerName); | ||
+ | if (user == null) { | ||
+ | throw new Exception("New Owner User not found. Please check the user name and if this user has permissions to it."); | ||
+ | } | ||
+ | Role ownerRole = RoleFactory.getInstance().restoreUserRole(user); | ||
+ | if (ownerRole == null) { | ||
+ | throw new Exception("New Owner User Role not found. This could be due to data inconsistency, every user should have a unique role."); | ||
+ | } | ||
+ | Resource resource = ResourceFactory.getInstance().restoreForPersistent(project); | ||
+ | if (resource == null) { | ||
+ | throw new Exception("Project Resource not found. Please contact support."); | ||
+ | } | ||
+ | Permission[] permissions = PermissionFactory.getInstance().restoreAllForResource(resource); | ||
+ | for (int p=0; p<permissions.length; p++) { | ||
+ | System.out.println("Found " + projectName + " / " + permissions[p].getRole().getName() + " / " + permissions[p].getAction()); | ||
+ | if (permissions[p].getRole().isUserRole() && permissions[p].isDeleteable()) { | ||
+ | System.out.println(" -- Removing this permission."); | ||
+ | permissions[p].delete(); | ||
+ | } | ||
+ | } | ||
+ | uow.commit(); | ||
+ | System.out.println("===================="); | ||
+ | Permission read = new Permission(resource, "read", ownerRole); | ||
+ | System.out.println("Creating " + projectName + " / " + ownerRole.getName() + " / read"); | ||
+ | read.store(); | ||
+ | Permission write = new Permission(resource, "write", ownerRole); | ||
+ | System.out.println("Creating " + projectName + " / " + ownerRole.getName() + " / write"); | ||
+ | write.store(); | ||
+ | Permission security = new Permission(resource, "security", ownerRole); | ||
+ | System.out.println("Creating " + projectName + " / " + ownerRole.getName() + " / security"); | ||
+ | security.store(); | ||
+ | // commit to database | ||
+ | uow.commitAndClose(); | ||
+ | System.out.println("Changed owner of project " + project.getName() + " [" + project.getId() + "] to " + user.getName());</pre> | ||
= Set Property Based on Results of RESOLVE DEPENDENCY ARTIFACTS Step = | = Set Property Based on Results of RESOLVE DEPENDENCY ARTIFACTS Step = | ||
Use this script if you need a property to define whether the resolve step was successful or had conflicts. | Use this script if you need a property to define whether the resolve step was successful or had conflicts. |