Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 23 additions & 15 deletions api/src/org/labkey/api/security/UserManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
import org.labkey.api.security.permissions.SiteAdminPermission;
import org.labkey.api.security.roles.ApplicationAdminRole;
import org.labkey.api.security.roles.SiteAdminRole;
import org.labkey.api.thumbnail.ThumbnailProvider;
import org.labkey.api.thumbnail.ThumbnailService;
import org.labkey.api.thumbnail.ThumbnailService.ImageType;
import org.labkey.api.util.HeartBeat;
import org.labkey.api.util.HtmlString;
import org.labkey.api.util.LinkBuilder;
Expand Down Expand Up @@ -455,7 +458,7 @@ public static Date getMostRecentLogin()
Aggregate maxLoginValue = new Aggregate(createdFk, Aggregate.BaseType.MAX, null, true);

TableSelector logins = getRecentLoginOrOuts(LoggedInOrOut.in, null, uat, Collections.singleton(createdCol));
Aggregate.Result result = logins.getAggregates(Collections.singletonList(maxLoginValue)).get(createdCol.getName()).get(0);
Aggregate.Result result = logins.getAggregates(Collections.singletonList(maxLoginValue)).get(createdCol.getName()).getFirst();
return (Date) result.getValue();
}

Expand All @@ -472,7 +475,7 @@ public static int getActiveDaysCount(Date since)
Aggregate countDistinctDates = new Aggregate(datePartCol.getFieldKey(), Aggregate.BaseType.COUNT, null, true);

TableSelector logins = getRecentLoginOrOuts(LoggedInOrOut.in, since, uat, Collections.singleton(datePartCol));
Aggregate.Result result = logins.getAggregates(Collections.singletonList(countDistinctDates)).get(datePartCol.getName()).get(0);
Aggregate.Result result = logins.getAggregates(Collections.singletonList(countDistinctDates)).get(datePartCol.getName()).getFirst();
return Math.toIntExact((long) result.getValue());
}

Expand Down Expand Up @@ -502,7 +505,6 @@ public static int getAuthCount(@Nullable Date since, boolean excludeSystemUsers,
sql.append(" AND uat.Comment LIKE ");
sql.appendStringLiteral("%" + UserAuditEvent.LOGGED_IN + "%", uat.getSqlDialect());


if (apiKeyOnly)
{
sql.append(" AND uat.Comment LIKE ");
Expand Down Expand Up @@ -908,17 +910,17 @@ public static void auditBadVerificationToken(int userId, String oldEmail, String

public static void deleteUser(int userId) throws UserManagementException
{
User deletUser = getUser(userId);
if (null == deletUser)
User deleteUser = getUser(userId);
if (null == deleteUser)
return;

removeRecentUser(deletUser);
removeRecentUser(deleteUser);

List<Throwable> errors = fireDeleteUser(deletUser);
List<Throwable> errors = fireDeleteUser(deleteUser);

if (!errors.isEmpty())
{
Throwable first = errors.get(0);
Throwable first = errors.getFirst();
if (first instanceof RuntimeException)
throw (RuntimeException)first;
else
Expand All @@ -927,19 +929,25 @@ public static void deleteUser(int userId) throws UserManagementException

try (Transaction transaction = CORE.getScope().ensureTransaction())
{
boolean needToEnsureRootAdmins = SecurityManager.isRootAdmin(deletUser);
boolean needToEnsureRootAdmins = SecurityManager.isRootAdmin(deleteUser);

SqlExecutor executor = new SqlExecutor(CORE.getSchema());
executor.execute("DELETE FROM " + CORE.getTableInfoRoleAssignments() + " WHERE UserId=?", userId);
executor.execute("DELETE FROM " + CORE.getTableInfoMembers() + " WHERE UserId=?", userId);
addToUserHistory(deletUser, deletUser.getEmail() + " was deleted from the system");
addToUserHistory(deleteUser, deleteUser.getEmail() + " was deleted from the system");

executor.execute("DELETE FROM " + CORE.getTableInfoUsersData() + " WHERE UserId=?", userId);
LoginManager.deleteLoginsRow(deletUser, null);
LoginManager.deleteLoginsRow(deleteUser, null);
executor.execute("DELETE FROM " + CORE.getTableInfoPrincipals() + " WHERE UserId=?", userId);
ApiKeyManager.get().deleteKeys(new SimpleFilter(FieldKey.fromParts("CreatedBy"), userId));

OntologyManager.deleteOntologyObject(deletUser.getEntityId(), ContainerManager.getSharedContainer(), true);
OntologyManager.deleteOntologyObject(deleteUser.getEntityId(), ContainerManager.getSharedContainer(), true);

// GitHub Issue #714: Delete the user's avatar. Avatars use ImageType.Large, but delete all types just in case that changes.
ThumbnailService svc = ThumbnailService.get();
ThumbnailProvider provider = new AvatarThumbnailProvider(deleteUser);
Arrays.stream(ImageType.values())
.forEach(imageType -> svc.deleteThumbnail(provider, imageType));

// Clear user list immediately (before the last root admin check) and again after commit/rollback
transaction.addCommitTask(UserManager::clearUserList, CommitTaskOption.IMMEDIATE, CommitTaskOption.POSTCOMMIT, CommitTaskOption.POSTROLLBACK);
Expand All @@ -952,7 +960,7 @@ public static void deleteUser(int userId) throws UserManagementException
catch (Exception e)
{
LOG.error("deleteUser", e);
throw new UserManagementException(deletUser.getEmail(), e);
throw new UserManagementException(deleteUser.getEmail(), e);
}

//TODO: Delete User files
Expand Down Expand Up @@ -986,7 +994,7 @@ public static void setUserActive(User currentUser, User userToAdjust, boolean ac

if (!errors.isEmpty())
{
Throwable first = errors.get(0);
Throwable first = errors.getFirst();
if (first instanceof RuntimeException)
throw (RuntimeException)first;
else
Expand Down Expand Up @@ -1027,7 +1035,7 @@ public static void setUserActive(User currentUser, User userToAdjust, boolean ac
}
catch(RuntimeSQLException e)
{
LOG.error("setUserActive: " + e);
LOG.error("setUserActive", e);
throw new UserManagementException(userToAdjust.getEmail(), e);
}
}
Expand Down
8 changes: 4 additions & 4 deletions api/src/org/labkey/api/thumbnail/ThumbnailService.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.labkey.api.thumbnail;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.labkey.api.data.CacheableWriter;
import org.labkey.api.data.views.DataViewProvider.EditInfo.ThumbnailType;
Expand All @@ -23,18 +24,17 @@
import org.labkey.api.view.ViewContext;

import java.io.IOException;
import java.util.Objects;
import java.util.Set;

/**
* Works with {@link ThumbnailProvider} implementations to cache thumbnails.
* User: adam
* Date: 10/8/11
*/
public interface ThumbnailService
{
static ThumbnailService get()
static @NotNull ThumbnailService get()
{
return ServiceRegistry.get().getService(ThumbnailService.class);
return Objects.requireNonNull(ServiceRegistry.get().getService(ThumbnailService.class));
}

static void setInstance(ThumbnailService impl)
Expand Down
Loading