mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 00:45:44 +01:00
move to scm-webapp
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package sonia.scm.user;
|
||||
|
||||
import com.github.legman.Subscribe;
|
||||
import sonia.scm.ContextEntry;
|
||||
import sonia.scm.EagerSingleton;
|
||||
import sonia.scm.HandlerEventType;
|
||||
import sonia.scm.SCMContext;
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
import sonia.scm.plugin.Extension;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@EagerSingleton
|
||||
@Extension
|
||||
public class AnonymousUserDeletionEventHandler {
|
||||
|
||||
private ScmConfiguration scmConfiguration;
|
||||
|
||||
@Inject
|
||||
public AnonymousUserDeletionEventHandler(ScmConfiguration scmConfiguration) {
|
||||
this.scmConfiguration = scmConfiguration;
|
||||
}
|
||||
|
||||
@Subscribe(async = false)
|
||||
public void onEvent(UserEvent event) {
|
||||
if (isAnonymousUserDeletionNotAllowed(event)) {
|
||||
throw new AnonymousUserDeletionException(ContextEntry.ContextBuilder.entity(User.class, event.getItem().getId()));
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isAnonymousUserDeletionNotAllowed(UserEvent event) {
|
||||
return event.getEventType() == HandlerEventType.BEFORE_DELETE
|
||||
&& event.getItem().getName().equals(SCMContext.USER_ANONYMOUS)
|
||||
&& scmConfiguration.isAnonymousAccessEnabled();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package sonia.scm.user;
|
||||
|
||||
import sonia.scm.ContextEntry;
|
||||
import sonia.scm.ExceptionWithContext;
|
||||
|
||||
public class AnonymousUserDeletionException extends ExceptionWithContext {
|
||||
|
||||
private static final String CODE = "1yRiASshD1";
|
||||
|
||||
public AnonymousUserDeletionException(ContextEntry.ContextBuilder context) {
|
||||
super(context.build(), "_anonymous user can not be deleted if anonymous access is enabled");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCode() {
|
||||
return CODE;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user