feat(permissions): Adds server permissions
This commit is contained in:
parent
d46bbd84c5
commit
cf9c88a2d6
24 changed files with 415 additions and 69 deletions
70
source/Configuration/Server/ServerConfigurationProvider.ts
Normal file
70
source/Configuration/Server/ServerConfigurationProvider.ts
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
import {ConfigurationProvider} from "../ConfigurationProvider";
|
||||
import {ServerConfigurationModel} from "../../Database/Models/ServerConfigurationModel";
|
||||
import {ServerConfigurationRepository} from "../../Database/Repositories/ServerConfigurationRepository";
|
||||
import {Snowflake} from "discord.js";
|
||||
import { ConfigurationModel } from "../../Database/Models/ConfigurationModel";
|
||||
import { Model } from "../../Database/Models/Model";
|
||||
import { Nullable } from "../../types/Nullable";
|
||||
import {ConfigurationTransformer, TransformerType} from "../ConfigurationTransformer";
|
||||
|
||||
export type RuntimeServerConfiguration = {
|
||||
permissions: PermissionRuntimeServerConfiguration
|
||||
}
|
||||
|
||||
export type PermissionRuntimeServerConfiguration = {
|
||||
groupCreation: GroupCreatePermissionRuntimeServerConfiguration
|
||||
}
|
||||
|
||||
export type GroupCreatePermissionRuntimeServerConfiguration = {
|
||||
allowEveryone: boolean
|
||||
}
|
||||
|
||||
export class ServerConfigurationProvider implements ConfigurationProvider<
|
||||
ServerConfigurationModel,
|
||||
RuntimeServerConfiguration
|
||||
> {
|
||||
constructor(
|
||||
private readonly repository: ServerConfigurationRepository,
|
||||
private readonly serverid: Snowflake
|
||||
) {
|
||||
}
|
||||
|
||||
get defaults(): RuntimeServerConfiguration {
|
||||
return {
|
||||
permissions: {
|
||||
groupCreation: {
|
||||
allowEveryone: false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
get(path: string): Nullable<ServerConfigurationModel> {
|
||||
return this.repository.findConfigurationByPath(this.serverid, path);
|
||||
}
|
||||
getAll(): ServerConfigurationModel[] {
|
||||
return this.repository.findServerConfigurations(this.serverid);
|
||||
}
|
||||
save(value: Omit<ConfigurationModel, "id"> & Partial<Model>): void {
|
||||
if (value.id) {
|
||||
// @ts-expect-error id is set, due to the check on line above
|
||||
this.repository.update(value);
|
||||
return
|
||||
}
|
||||
|
||||
this.repository.create({
|
||||
...value,
|
||||
serverid: this.serverid
|
||||
});
|
||||
}
|
||||
getTransformer(): ConfigurationTransformer {
|
||||
return new ConfigurationTransformer(
|
||||
[
|
||||
{
|
||||
path: ['permissions', 'groupCreation', 'allowEveryone'],
|
||||
type: TransformerType.PermissionBoolean
|
||||
}
|
||||
]
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue