BareGit
#include "authorization.h"

bool AuthorizationService::canViewCard(
    const User& actor, const Card& card, bool actor_owns_card) const
{
    return actor_owns_card || actor.role == UserRole::ADMINISTRATOR ||
           (actor.role == UserRole::CREATOR &&
            card.creator_user_id == actor.id);
}

bool AuthorizationService::canCreateCard(const User& actor) const
{
    return actor.role == UserRole::CREATOR ||
           actor.role == UserRole::ADMINISTRATOR;
}

bool AuthorizationService::canEditCard(
    const User& actor, const Card& card) const
{
    return actor.role == UserRole::ADMINISTRATOR ||
           (actor.role == UserRole::CREATOR &&
            card.creator_user_id == actor.id);
}

bool AuthorizationService::canDeleteCard(const User& actor) const
{
    return actor.role == UserRole::ADMINISTRATOR;
}

bool AuthorizationService::canSetRarity(const User& actor) const
{
    return actor.role == UserRole::ADMINISTRATOR;
}

bool AuthorizationService::canAdminister(const User& actor) const
{
    return actor.role == UserRole::ADMINISTRATOR;
}

GameContentScope AuthorizationService::gameContentScope(
    const User& actor) const
{
    return actor.role == UserRole::ADMINISTRATOR
        ? GameContentScope::INCLUDE_INTERNAL
        : GameContentScope::PUBLIC_ONLY;
}

bool AuthorizationService::canUseGame(
    const User& actor, const Game& game) const
{
    return game.visibility == GameVisibility::PUBLIC ||
           actor.role == UserRole::ADMINISTRATOR;
}