mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-01-27 23:09:05 +00:00
added command to remove the role from mod mail configuration again
added convenience method to disallow a whole feature for a role
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package dev.sheldan.abstracto.modmail.commands;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
|
||||
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
|
||||
import dev.sheldan.abstracto.core.command.config.HelpInfo;
|
||||
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.config.FeatureEnum;
|
||||
import dev.sheldan.abstracto.core.models.database.ARole;
|
||||
import dev.sheldan.abstracto.modmail.config.ModMailFeatures;
|
||||
import dev.sheldan.abstracto.modmail.service.ModMailRoleService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class RemoveModMailRole extends AbstractConditionableCommand {
|
||||
|
||||
@Autowired
|
||||
private ModMailRoleService modMailRoleService;
|
||||
|
||||
@Override
|
||||
public CommandResult execute(CommandContext commandContext) {
|
||||
ARole role = (ARole) commandContext.getParameters().getParameters().get(0);
|
||||
modMailRoleService.removeRoleFromModMailRoles(role, commandContext.getUserInitiatedContext().getServer());
|
||||
return CommandResult.fromSuccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
Parameter categoryId = Parameter.builder().name("role").type(ARole.class).description("The role to not be notified about new threads.").build();
|
||||
List<Parameter> parameters = Arrays.asList(categoryId);
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
List<String> aliases = Arrays.asList("rmMmRole");
|
||||
return CommandConfiguration.builder()
|
||||
.name("removeModMailRole")
|
||||
.module(ModMailModuleInterface.MODMAIL)
|
||||
.aliases(aliases)
|
||||
.parameters(parameters)
|
||||
.help(helpInfo)
|
||||
.templated(true)
|
||||
.causesReaction(true)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureEnum getFeature() {
|
||||
return ModMailFeatures.MODMAIL;
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import java.util.List;
|
||||
@Repository
|
||||
public interface ModMailRoleRepository extends JpaRepository<ModMailRole, Long> {
|
||||
boolean existsByServerAndRole(AServer server, ARole role);
|
||||
void deleteByServerAndRole(AServer server, ARole role);
|
||||
|
||||
List<ModMailRole> findByServer(AServer server);
|
||||
}
|
||||
|
||||
@@ -28,4 +28,10 @@ public class ModMailRoleServiceBean implements ModMailRoleService {
|
||||
}
|
||||
commandService.allowFeatureForRole(ModMailFeatures.MODMAIL, role);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeRoleFromModMailRoles(ARole role, AServer server) {
|
||||
modMailRoleManagementService.removeRoleFromModMailRoles(role, server);
|
||||
commandService.disAllowFeatureForRole(ModMailFeatures.MODMAIL, role);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,11 @@ public class ModMailRoleManagementServiceBean implements ModMailRoleManagementSe
|
||||
modMailRoleRepository.save(roleToAdd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeRoleFromModMailRoles(ARole role, AServer server) {
|
||||
modMailRoleRepository.deleteByServerAndRole(server, role);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ModMailRole> getRolesForServer(AServer server) {
|
||||
return modMailRoleRepository.findByServer(server);
|
||||
|
||||
@@ -5,4 +5,5 @@ import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
|
||||
public interface ModMailRoleService {
|
||||
void addRoleToModMailRoles(ARole role, AServer server);
|
||||
void removeRoleFromModMailRoles(ARole role, AServer server);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import java.util.List;
|
||||
|
||||
public interface ModMailRoleManagementService {
|
||||
void addRoleToModMailRoles(ARole role, AServer server);
|
||||
void removeRoleFromModMailRoles(ARole role, AServer server);
|
||||
List<ModMailRole> getRolesForServer(AServer server);
|
||||
boolean isRoleAlreadyAssigned(ARole role, AServer server);
|
||||
}
|
||||
|
||||
@@ -97,5 +97,13 @@ public class CommandServiceBean implements CommandService {
|
||||
commandForServer.getAllowedRoles().removeIf(role1 -> role1.getId().equals(role.getId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disAllowFeatureForRole(FeatureEnum featureEnum, ARole role) {
|
||||
AFeature feature = featureManagementService.getFeature(featureEnum.getKey());
|
||||
feature.getCommands().forEach(command -> {
|
||||
this.disAllowCommandForRole(command, role);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -15,4 +15,5 @@ public interface CommandService {
|
||||
void restrictCommand(ACommand aCommand, AServer server);
|
||||
void unRestrictCommand(ACommand aCommand, AServer server);
|
||||
void disAllowCommandForRole(ACommand aCommand, ARole role);
|
||||
void disAllowFeatureForRole(FeatureEnum featureEnum, ARole role);
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
Removes the role from the roles being notified when a new thread is created by an user.
|
||||
@@ -0,0 +1,2 @@
|
||||
Removes this role from the roles being notified when a new thread is opened by a user.
|
||||
This also automatically removes them from the allowed roles of all commands in the mod mail feature.
|
||||
@@ -0,0 +1 @@
|
||||
removeModMailRole <role>
|
||||
@@ -1 +1 @@
|
||||
Sends the given text to the user in an embed containing you as the author of the message. Only pictures as embeds are supported.
|
||||
Sends the given text to the user in an embed containing you as the author of the message. Only pictures as attachments are supported.
|
||||
Reference in New Issue
Block a user