Files
DarkflameServer/dDatabase/GameDatabase/ITables/IPermissionGrants.h
Aaron Kimbrell c575eba4e7 feat(db): permission_grants, permissions and commands given to one account or character
A new table, permission_grants (MySQL migration 96, SQLite 79), and the IPermissionGrants interface with MySQL, SQLite
and TestSQL implementations. A row grants (or with deny, takes away) a dashboard permission, a slash command, a
permission category or every command up to a GM level, for one account or one character, with an optional expiry, who
granted it and when, and a note. Rows are never deleted: removing one sets revoked_at/revoked_by, so the table is also
the history. Nothing reads it yet.

Check: both migrations run on a fresh and an existing database; DatabaseParityTests PermissionGrants passes against
MariaDB (DLU_TEST_MYSQL_HOST) and SQLite gives the same results.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 01:16:37 -05:00

44 lines
2.0 KiB
C++

#ifndef __IPERMISSIONGRANTS__H__
#define __IPERMISSIONGRANTS__H__
#include <cstdint>
#include <optional>
#include <string>
#include <vector>
/**
* Permissions and slash commands granted to (or denied from) one account or one character, on top of what its GM level
* allows (PermissionGrants.h). Rows are never deleted: removing a grant sets revokedAt, so the rows are also the history.
*/
class IPermissionGrants {
public:
struct Grant {
uint64_t id{};
std::string targetType; // "account" or "character"
int64_t targetId{}; // the account's ID, or the character's charinfo ID
std::string kind; // "permission", "command", "permission_group" or "command_group"
std::string name; // the permission key, command name, permission category or GM level
bool deny{};
int64_t expiresAt{}; // 0: never
std::string note;
int64_t grantedAt{};
uint32_t grantedById{}; // the account that granted it
std::string grantedBy;
int64_t revokedAt{}; // 0: not removed
std::string revokedBy;
};
virtual uint64_t InsertPermissionGrant(const Grant& grant) = 0;
virtual std::optional<Grant> GetPermissionGrant(uint64_t id) = 0;
// Every grant of one target, removed and expired ones too, newest first
virtual std::vector<Grant> GetPermissionGrants(const std::string& targetType, int64_t targetId) = 0;
// The grants in force at `now` (not removed, not expired) of an account and, when characterId isn't 0, one character
virtual std::vector<Grant> GetActivePermissionGrants(uint32_t accountId, int64_t characterId, int64_t now) = 0;
// Every target's grants, newest first: only the ones in force at `now`, or all of them (the history)
virtual std::vector<Grant> GetRecentPermissionGrants(bool activeOnly, int64_t now, uint32_t limit) = 0;
// Whether it was in force until now (false: no such grant, or already removed)
virtual bool RevokePermissionGrant(uint64_t id, const std::string& revokedBy, int64_t time) = 0;
};
#endif //!__IPERMISSIONGRANTS__H__