Commit 4931ad0b authored by mhellka's avatar mhellka
Browse files

Forward owner and ACL changes to ArchiveListener

parent 993eb8f5
package de.gwdg.cdstar.runtime.listener;
import java.util.List;
import java.util.Set;
import de.gwdg.cdstar.runtime.client.CDStarACLEntry;
import de.gwdg.cdstar.runtime.client.CDStarArchive;
import de.gwdg.cdstar.runtime.client.CDStarAttribute;
import de.gwdg.cdstar.runtime.client.CDStarFile;
import de.gwdg.cdstar.runtime.client.CDStarProfile;
import de.gwdg.cdstar.runtime.client.auth.ArchivePermission;
/**
* Interface for plugins that want to listen for cdstar archive changes. The
......@@ -21,7 +24,12 @@ public interface ArchiveListener {
}
default void profileChanged(CDStarArchive archive, CDStarProfile oldProfile) {
}
default void ownerChanged(CDStarArchive archive, String oldOwner) {
}
default void aclChanged(CDStarArchive archive, CDStarACLEntry entry, Set<ArchivePermission> oldPermissions) {
}
default void propertyChanged(CDStarAttribute property, CDStarFile file, List<String> originalValues) {
......
......@@ -33,31 +33,43 @@ public class AclEntryImpl implements CDStarACLEntry {
public void permit(ArchivePermission permit) {
archive.checkPermission(ArchivePermission.CHANGE_ACL);
archive.requireTransactionWriteable();
if (permissions.add(permit))
archive.markModified();
EnumSet<ArchivePermission> old = permissions.clone();
if (!permissions.add(permit))
return;
archive.markModified();
archive.forEachListener(l -> l.aclChanged(archive, this, old));
}
@Override
public void permit(ArchivePermissionSet permissionSet) {
archive.checkPermission(ArchivePermission.CHANGE_ACL);
archive.requireTransactionWriteable();
if (permissions.addAll(permissionSet.getPermissions()))
archive.markModified();
EnumSet<ArchivePermission> old = permissions.clone();
if (!permissions.addAll(permissionSet.getPermissions()))
return;
archive.markModified();
archive.forEachListener(l -> l.aclChanged(archive, this, old));
}
@Override
public void revoke(ArchivePermission permit) {
archive.checkPermission(ArchivePermission.CHANGE_ACL);
archive.requireTransactionWriteable();
if (permissions.remove(permit))
archive.markModified();
EnumSet<ArchivePermission> old = permissions.clone();
if (!permissions.remove(permit))
return;
archive.markModified();
archive.forEachListener(l -> l.aclChanged(archive, this, old));
}
@Override
public void revoke(ArchivePermissionSet permissionSet) {
archive.checkPermission(ArchivePermission.CHANGE_ACL);
archive.requireTransactionWriteable();
if (permissions.removeAll(permissionSet.getPermissions()))
archive.markModified();
EnumSet<ArchivePermission> old = permissions.clone();
if (!permissions.removeAll(permissionSet.getPermissions()))
return;
archive.markModified();
archive.forEachListener(l -> l.aclChanged(archive, this, old));
}
}
\ No newline at end of file
......@@ -467,7 +467,9 @@ class ArchiveImpl implements CDStarArchive {
requireTransactionWriteable();
checkPermission(ArchivePermission.CHANGE_OWNER);
markModified();
String oldOwner = getOwner();
xOwner = new StringSubject.PrincipalSubject(owner);
forEachListener(l -> l.ownerChanged(this, oldOwner));
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment