Search in sources :

Example 1 with OPERATION_ENABLE

use of org.craftercms.studio.api.v2.dal.AuditLogConstants.OPERATION_ENABLE in project studio by craftercms.

the class UserServiceImpl method enableUsers.

@Override
@HasPermission(type = DefaultPermission.class, action = "update_users")
public List<User> enableUsers(List<Long> userIds, List<String> usernames, boolean enabled) throws ServiceLayerException, UserNotFoundException, AuthenticationException {
    List<User> users = userServiceInternal.enableUsers(userIds, usernames, enabled);
    SiteFeed siteFeed = siteService.getSite(studioConfiguration.getProperty(CONFIGURATION_GLOBAL_SYSTEM_SITE));
    AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
    auditLog.setSiteId(siteFeed.getId());
    if (enabled) {
        auditLog.setOperation(OPERATION_ENABLE);
    } else {
        auditLog.setOperation(OPERATION_DISABLE);
    }
    auditLog.setActorId(getCurrentUser().getUsername());
    auditLog.setPrimaryTargetId(siteFeed.getSiteId());
    auditLog.setPrimaryTargetType(TARGET_TYPE_USER);
    auditLog.setPrimaryTargetValue(siteFeed.getName());
    List<AuditLogParameter> paramters = new ArrayList<AuditLogParameter>();
    for (User u : users) {
        AuditLogParameter paramter = new AuditLogParameter();
        paramter.setTargetId(Long.toString(u.getId()));
        paramter.setTargetType(TARGET_TYPE_USER);
        paramter.setTargetValue(u.getUsername());
        paramters.add(paramter);
    }
    auditLog.setParameters(paramters);
    auditServiceInternal.insertAuditLog(auditLog);
    return users;
}
Also used : User(org.craftercms.studio.api.v2.dal.User) AuthenticatedUser(org.craftercms.studio.model.AuthenticatedUser) SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed) ArrayList(java.util.ArrayList) AuditLogParameter(org.craftercms.studio.api.v2.dal.AuditLogParameter) AuditLog(org.craftercms.studio.api.v2.dal.AuditLog) HasPermission(org.craftercms.commons.security.permissions.annotations.HasPermission)

Aggregations

ArrayList (java.util.ArrayList)1 HasPermission (org.craftercms.commons.security.permissions.annotations.HasPermission)1 SiteFeed (org.craftercms.studio.api.v1.dal.SiteFeed)1 AuditLog (org.craftercms.studio.api.v2.dal.AuditLog)1 AuditLogParameter (org.craftercms.studio.api.v2.dal.AuditLogParameter)1 User (org.craftercms.studio.api.v2.dal.User)1 AuthenticatedUser (org.craftercms.studio.model.AuthenticatedUser)1