use of com.google.gerrit.reviewdb.client.AccountGroupByIdAud in project gerrit by GerritCodeReview.
the class DbGroupMemberAuditListener method onAddGroupsToGroup.
@Override
public void onAddGroupsToGroup(Account.Id me, Collection<AccountGroupById> added) {
List<AccountGroupByIdAud> includesAudit = new ArrayList<>();
for (AccountGroupById groupInclude : added) {
AccountGroupByIdAud audit = new AccountGroupByIdAud(groupInclude, me, TimeUtil.nowTs());
includesAudit.add(audit);
}
try (ReviewDb db = schema.open()) {
db.accountGroupByIdAud().insert(includesAudit);
} catch (OrmException e) {
logOrmExceptionForGroups("Cannot log add groups to group event performed by user", me, added, e);
}
}
use of com.google.gerrit.reviewdb.client.AccountGroupByIdAud in project gerrit by GerritCodeReview.
the class DbGroupMemberAuditListener method onDeleteGroupsFromGroup.
@Override
public void onDeleteGroupsFromGroup(Account.Id me, Collection<AccountGroupById> removed) {
final List<AccountGroupByIdAud> auditUpdates = new ArrayList<>();
try (ReviewDb db = schema.open()) {
for (final AccountGroupById g : removed) {
AccountGroupByIdAud audit = null;
for (AccountGroupByIdAud a : db.accountGroupByIdAud().byGroupInclude(g.getGroupId(), g.getIncludeUUID())) {
if (a.isActive()) {
audit = a;
break;
}
}
if (audit != null) {
audit.removed(me, TimeUtil.nowTs());
auditUpdates.add(audit);
}
}
db.accountGroupByIdAud().update(auditUpdates);
} catch (OrmException e) {
logOrmExceptionForGroups("Cannot log delete groups from group event performed by user", me, removed, e);
}
}
use of com.google.gerrit.reviewdb.client.AccountGroupByIdAud in project gerrit by GerritCodeReview.
the class GetAuditLog method apply.
@Override
public List<? extends GroupAuditEventInfo> apply(GroupResource rsrc) throws AuthException, ResourceNotFoundException, MethodNotAllowedException, OrmException {
if (rsrc.toAccountGroup() == null) {
throw new MethodNotAllowedException();
} else if (!rsrc.getControl().isOwner()) {
throw new AuthException("Not group owner");
}
AccountGroup group = db.get().accountGroups().get(rsrc.toAccountGroup().getId());
if (group == null) {
throw new ResourceNotFoundException();
}
AccountLoader accountLoader = accountLoaderFactory.create(true);
List<GroupAuditEventInfo> auditEvents = new ArrayList<>();
for (AccountGroupMemberAudit auditEvent : db.get().accountGroupMembersAudit().byGroup(group.getId()).toList()) {
AccountInfo member = accountLoader.get(auditEvent.getKey().getParentKey());
auditEvents.add(GroupAuditEventInfo.createAddUserEvent(accountLoader.get(auditEvent.getAddedBy()), auditEvent.getKey().getAddedOn(), member));
if (!auditEvent.isActive()) {
auditEvents.add(GroupAuditEventInfo.createRemoveUserEvent(accountLoader.get(auditEvent.getRemovedBy()), auditEvent.getRemovedOn(), member));
}
}
for (AccountGroupByIdAud auditEvent : db.get().accountGroupByIdAud().byGroup(group.getId()).toList()) {
AccountGroup.UUID includedGroupUUID = auditEvent.getKey().getIncludeUUID();
AccountGroup includedGroup = groupCache.get(includedGroupUUID);
GroupInfo member;
if (includedGroup != null) {
member = groupJson.format(GroupDescriptions.forAccountGroup(includedGroup));
} else {
GroupDescription.Basic groupDescription = groupBackend.get(includedGroupUUID);
member = new GroupInfo();
member.id = Url.encode(includedGroupUUID.get());
member.name = groupDescription.getName();
}
auditEvents.add(GroupAuditEventInfo.createAddGroupEvent(accountLoader.get(auditEvent.getAddedBy()), auditEvent.getKey().getAddedOn(), member));
if (!auditEvent.isActive()) {
auditEvents.add(GroupAuditEventInfo.createRemoveGroupEvent(accountLoader.get(auditEvent.getRemovedBy()), auditEvent.getRemovedOn(), member));
}
}
accountLoader.fill();
// sort by date in reverse order so that the newest audit event comes first
Collections.sort(auditEvents, new Comparator<GroupAuditEventInfo>() {
@Override
public int compare(GroupAuditEventInfo e1, GroupAuditEventInfo e2) {
return e2.date.compareTo(e1.date);
}
});
return auditEvents;
}
Aggregations