mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-01-18 13:32:10 +01:00
Invalidate authorization cache when namespace permissions are changed
This commit is contained in:
@@ -24,6 +24,10 @@
|
||||
|
||||
package sonia.scm.repository;
|
||||
|
||||
import com.github.legman.EventBus;
|
||||
import sonia.scm.HandlerEventType;
|
||||
import sonia.scm.event.ScmEventBus;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
@@ -36,11 +40,13 @@ public class DefaultNamespaceManager implements NamespaceManager {
|
||||
|
||||
private final RepositoryManager repositoryManager;
|
||||
private final NamespaceDao dao;
|
||||
private final EventBus eventBus;
|
||||
|
||||
@Inject
|
||||
public DefaultNamespaceManager(RepositoryManager repositoryManager, NamespaceDao dao) {
|
||||
public DefaultNamespaceManager(RepositoryManager repositoryManager, NamespaceDao dao, EventBus eventBus) {
|
||||
this.repositoryManager = repositoryManager;
|
||||
this.dao = dao;
|
||||
this.eventBus = eventBus;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -64,10 +70,14 @@ public class DefaultNamespaceManager implements NamespaceManager {
|
||||
|
||||
@Override
|
||||
public void modify(Namespace namespace) {
|
||||
Namespace oldNamespace = get(namespace.getNamespace())
|
||||
.orElseThrow(() -> notFound(entity(Namespace.class, namespace.getNamespace())));
|
||||
fireEvent(HandlerEventType.BEFORE_MODIFY, namespace, oldNamespace);
|
||||
if (!get(namespace.getNamespace()).isPresent()) {
|
||||
throw notFound(entity("Namespace", namespace.getNamespace()));
|
||||
}
|
||||
dao.add(namespace);
|
||||
fireEvent(HandlerEventType.MODIFY, namespace, oldNamespace);
|
||||
}
|
||||
|
||||
private Namespace createNamespaceForName(String namespace) {
|
||||
@@ -75,4 +85,8 @@ public class DefaultNamespaceManager implements NamespaceManager {
|
||||
.map(Namespace::clone)
|
||||
.orElse(new Namespace(namespace));
|
||||
}
|
||||
|
||||
protected void fireEvent(HandlerEventType event, Namespace namespace, Namespace oldNamespace) {
|
||||
eventBus.post(new NamespaceModificationEvent(event, namespace, oldNamespace));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user