public void testStore() {
    Org org = UserTestUtils.findNewOrg("testorg");

    String login = TestUtils.randomString();
    command.setLogin(login);
    command.setPassword("password");
    command.setEmail("*****@*****.**");
    command.setPrefix("Dr.");
    command.setFirstNames("Chuck Norris");
    command.setLastName("Texas Ranger");
    command.setOrg(org);
    command.setCompany("Test company");

    Object[] errors = command.validate();
    assertEquals(0, errors.length);

    command.storeNewUser();

    Long uid = command.getUser().getId();
    assertNotNull(uid);

    User result = UserFactory.lookupById(uid);
    assertEquals(login, result.getLogin());
    assertEquals(PageSizeDecorator.getDefaultPageSize(), result.getPageSize());
  }
Esempio n. 2
0
  /**
   * Gets the list of com.redhat.rhn.domain.user.User objects taking in DataResult. Do we need to
   * make this public?
   *
   * @param dataresult the dataresult object containing the results of a query
   * @return Returns the userList
   */
  private List<User> getUsers(DataResult dataresult) {
    List userList = new ArrayList();
    Collection userIds = getListFromResult(dataresult, USER_ID_KEY);

    if (!userIds.isEmpty()) {
      userList = UserFactory.lookupByIds(userIds);
    }
    return userList;
  }
 /** {@inheritDoc} */
 public void setUp() throws Exception {
   super.setUp();
   user.addPermanentRole(RoleFactory.ORG_ADMIN);
   UserFactory.save(user);
   ksdata = KickstartDataTest.createKickstartWithOptions(user.getOrg());
   // ksdata = KickstartDataTest.createKickstartWithChannel(user.getOrg());
   mockRequest = new RhnMockHttpServletRequest();
   mockRequest.setupGetRemoteAddr("127.0.0.1");
   request = new RhnHttpServletRequest(mockRequest);
   helper = new KickstartHelper(request);
 }
Esempio n. 4
0
 /**
  * Handles the vagaries related to granting or revoking sat admin role
  *
  * @param loggedInUser the logged in user
  * @param login the login of the user who needs to be granted/revoked sat admin role
  * @param grant true if granting the role to the login, false for revoking...
  * @return 1 if it success.. Ofcourse error on failure..
  */
 private int modifySatAdminRole(User loggedInUser, String login, boolean grant) {
   ensureUserRole(loggedInUser, RoleFactory.SAT_ADMIN);
   SatManager manager = SatManager.getInstance();
   User user = UserFactory.lookupByLogin(login);
   if (grant) {
     manager.grantSatAdminRoleTo(user, loggedInUser);
   } else {
     manager.revokeSatAdminRoleFrom(user, loggedInUser);
   }
   UserManager.storeUser(user);
   return 1;
 }
  protected void doExecute(EventMessage msg) {
    SsmInstallPackagesEvent event = (SsmInstallPackagesEvent) msg;

    User user = UserFactory.lookupById(event.getUserId());

    // Log the action has been created
    long operationId =
        SsmOperationManager.createOperation(
            user, "ssm.package.install.operationname", RhnSetDecl.SYSTEMS.getLabel());

    try {
      scheduleInstalls(event, user);
    } catch (Exception e) {
      log.error("Error scheduling package installations for event " + event, e);
    } finally {
      // This should stay in the finally block so the operation is
      // not perpetually left in an in progress state
      SsmOperationManager.completeOperation(user, operationId);
    }
  }