feat(settings): complete remaining settings tabs (account, tags, turns)
Fill the three previously-placeholder settings sections so every menu item is now a real page inside the settings shell: - حساب کاربری: new authenticated POST /api/v1/user/change-password (verifies current password, ≥8 chars, must differ) + account page with a profile summary and change-password form. - برچسبها: new per-tenant TenantTag domain (entity/repo/controller + migration) with tenant-scoped CRUD at /api/v1/tenant-tag(s), plus a tags management page (list + color + add/edit/delete). - مدیریت نوبت دهی: export the existing WeeklyScheduleTab from DoctorDetailPage and reuse it in a standalone AppointmentSettingsPage (current doctor's uuid + addresses). Wire all three menu entries to their routes. Backend covered by PHPUnit (change-password, tenant-tag CRUD + ownership); FE covered by Vitest. API docs updated (auth.md, tag.md). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -430,6 +430,35 @@ class AuthController extends BaseController
|
||||
return $this->success(['message' => 'رمز عبور با موفقیت تغییر یافت']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the password of the authenticated user. Requires the current
|
||||
* password (verified against the stored hash); the new one must be ≥ 8
|
||||
* chars and different from the current.
|
||||
*/
|
||||
#[Route('/api/v1/user/change-password', methods: ['POST'])]
|
||||
#[IsGranted('IS_AUTHENTICATED_FULLY')]
|
||||
public function changePassword(Request $request, #[CurrentUser] User $user): JsonResponse
|
||||
{
|
||||
$data = json_decode($request->getContent(), true) ?? [];
|
||||
$current = trim($data['current_password'] ?? '');
|
||||
$new = trim($data['new_password'] ?? '');
|
||||
|
||||
if (mb_strlen($new) < 8) {
|
||||
return $this->error(ErrorCodes::ERR_VALIDATION_001, 'رمز عبور جدید باید حداقل ۸ کاراکتر باشد', 422, 'new_password');
|
||||
}
|
||||
if ($current === '' || !$this->hasher->isPasswordValid($user, $current)) {
|
||||
return $this->error(ErrorCodes::ERR_VALIDATION_001, 'رمز عبور فعلی نادرست است', 422, 'current_password');
|
||||
}
|
||||
if ($this->hasher->isPasswordValid($user, $new)) {
|
||||
return $this->error(ErrorCodes::ERR_VALIDATION_001, 'رمز جدید نباید با رمز فعلی یکسان باشد', 422, 'new_password');
|
||||
}
|
||||
|
||||
$user->setPasswordHash($this->hasher->hashPassword($user, $new));
|
||||
$this->em->flush();
|
||||
|
||||
return $this->success(['message' => 'رمز عبور با موفقیت تغییر یافت']);
|
||||
}
|
||||
|
||||
#[OA\Post(
|
||||
path: '/oauth/token/refresh',
|
||||
summary: 'Refresh access token using a refresh token',
|
||||
|
||||
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
|
||||
namespace App\Tag\Controller;
|
||||
|
||||
use App\Auth\Entity\User;
|
||||
use App\Auth\Repository\UserActiveContextRepository;
|
||||
use App\Clinic\Repository\ClinicRepository;
|
||||
use App\Doctor\Repository\DoctorRepository;
|
||||
use App\Shared\Constant\ErrorCodes;
|
||||
use App\Shared\Controller\BaseController;
|
||||
use App\Tag\Entity\TenantTag;
|
||||
use App\Tag\Repository\TenantTagRepository;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\CurrentUser;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
use OpenApi\Attributes as OA;
|
||||
|
||||
/**
|
||||
* Per-tenant (doctor/clinic) tag management. Every tag is scoped to the caller's
|
||||
* resolved entity; a tenant can only see and mutate its own tags.
|
||||
*/
|
||||
#[OA\Tag(name: 'Tenant Tags')]
|
||||
#[IsGranted('IS_AUTHENTICATED_FULLY')]
|
||||
class TenantTagController extends BaseController
|
||||
{
|
||||
private const HEX = '/^#([0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/';
|
||||
|
||||
public function __construct(
|
||||
private readonly TenantTagRepository $tagRepo,
|
||||
private readonly DoctorRepository $doctorRepo,
|
||||
private readonly ClinicRepository $clinicRepo,
|
||||
private readonly UserActiveContextRepository $contextRepo,
|
||||
) {}
|
||||
|
||||
#[Route('/api/v1/tenant-tags', methods: ['GET'])]
|
||||
public function list(#[CurrentUser] User $user): JsonResponse
|
||||
{
|
||||
[$type, $id] = $this->resolveEntity($user);
|
||||
if ($id === null) {
|
||||
return $this->error(ErrorCodes::ERR_FORBIDDEN_001, 'پروفایل یافت نشد', 403);
|
||||
}
|
||||
|
||||
return $this->success(array_map(
|
||||
fn(TenantTag $t) => $t->toArray(),
|
||||
$this->tagRepo->findByEntity($type, $id)
|
||||
));
|
||||
}
|
||||
|
||||
#[Route('/api/v1/tenant-tag', methods: ['POST'])]
|
||||
public function create(Request $request, #[CurrentUser] User $user): JsonResponse
|
||||
{
|
||||
[$type, $id] = $this->resolveEntity($user);
|
||||
if ($id === null) {
|
||||
return $this->error(ErrorCodes::ERR_FORBIDDEN_001, 'پروفایل یافت نشد', 403);
|
||||
}
|
||||
|
||||
$data = json_decode($request->getContent(), true) ?? [];
|
||||
$name = trim($data['name'] ?? '');
|
||||
$color = trim($data['color'] ?? '#5559CE');
|
||||
|
||||
if ($name === '') {
|
||||
return $this->error(ErrorCodes::ERR_VALIDATION_001, 'نام برچسب الزامی است', 422, 'name');
|
||||
}
|
||||
if (!preg_match(self::HEX, $color)) {
|
||||
return $this->error(ErrorCodes::ERR_VALIDATION_001, 'رنگ نامعتبر است', 422, 'color');
|
||||
}
|
||||
|
||||
$tag = new TenantTag($type, $id, $name, $color);
|
||||
$this->tagRepo->save($tag);
|
||||
|
||||
return $this->success($tag->toArray(), 201);
|
||||
}
|
||||
|
||||
#[Route('/api/v1/tenant-tag/{uuid}', methods: ['PATCH'])]
|
||||
public function update(string $uuid, Request $request, #[CurrentUser] User $user): JsonResponse
|
||||
{
|
||||
$tag = $this->ownedTag($uuid, $user);
|
||||
if ($tag === null) {
|
||||
return $this->error(ErrorCodes::ERR_NOT_FOUND_001, 'برچسب یافت نشد', 404);
|
||||
}
|
||||
|
||||
$data = json_decode($request->getContent(), true) ?? [];
|
||||
|
||||
if (isset($data['name'])) {
|
||||
$name = trim($data['name']);
|
||||
if ($name === '') {
|
||||
return $this->error(ErrorCodes::ERR_VALIDATION_001, 'نام برچسب الزامی است', 422, 'name');
|
||||
}
|
||||
$tag->setName($name);
|
||||
}
|
||||
if (isset($data['color'])) {
|
||||
if (!preg_match(self::HEX, trim($data['color']))) {
|
||||
return $this->error(ErrorCodes::ERR_VALIDATION_001, 'رنگ نامعتبر است', 422, 'color');
|
||||
}
|
||||
$tag->setColor(trim($data['color']));
|
||||
}
|
||||
if (isset($data['active'])) {
|
||||
$tag->setActive((bool) $data['active']);
|
||||
}
|
||||
|
||||
$this->tagRepo->save($tag);
|
||||
|
||||
return $this->success($tag->toArray());
|
||||
}
|
||||
|
||||
#[Route('/api/v1/tenant-tag/{uuid}', methods: ['DELETE'])]
|
||||
public function delete(string $uuid, #[CurrentUser] User $user): JsonResponse
|
||||
{
|
||||
$tag = $this->ownedTag($uuid, $user);
|
||||
if ($tag === null) {
|
||||
return $this->error(ErrorCodes::ERR_NOT_FOUND_001, 'برچسب یافت نشد', 404);
|
||||
}
|
||||
|
||||
$this->tagRepo->remove($tag);
|
||||
|
||||
return $this->success(['message' => 'برچسب حذف شد']);
|
||||
}
|
||||
|
||||
// ── Helpers ─────────────────────────────────────────────────────────────
|
||||
|
||||
/** The tag only if it belongs to the caller's entity, else null. */
|
||||
private function ownedTag(string $uuid, User $user): ?TenantTag
|
||||
{
|
||||
[$type, $id] = $this->resolveEntity($user);
|
||||
$tag = $this->tagRepo->findByUuid($uuid);
|
||||
if ($tag === null || $id === null || $tag->getEntityType() !== $type || $tag->getEntityId() !== $id) {
|
||||
return null;
|
||||
}
|
||||
return $tag;
|
||||
}
|
||||
|
||||
/** @return array{0: string, 1: int|null} [entityType, entityId] */
|
||||
private function resolveEntity(User $user): array
|
||||
{
|
||||
if ($user->hasRole('ROLE_DOCTOR')) {
|
||||
$doctor = $this->doctorRepo->findByUser($user);
|
||||
return ['doctor', $doctor?->getId()];
|
||||
}
|
||||
if ($user->hasRole('ROLE_CLINIC')) {
|
||||
$clinic = $this->clinicRepo->findByUser($user);
|
||||
return ['clinic', $clinic?->getId()];
|
||||
}
|
||||
if ($user->hasRole('ROLE_SECRETARY')) {
|
||||
$dbUuid = $this->contextRepo->findByUser($user)?->getDbUuid();
|
||||
if ($dbUuid !== null) {
|
||||
$clinic = $this->clinicRepo->findByUuid($dbUuid);
|
||||
if ($clinic !== null) {
|
||||
return ['clinic', $clinic->getId()];
|
||||
}
|
||||
$doctor = $this->doctorRepo->findByUuid($dbUuid);
|
||||
if ($doctor !== null) {
|
||||
return ['doctor', $doctor->getId()];
|
||||
}
|
||||
}
|
||||
}
|
||||
return ['unknown', null];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace App\Tag\Entity;
|
||||
|
||||
use App\Tag\Repository\TenantTagRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Uid\Uuid;
|
||||
|
||||
/**
|
||||
* A per-tenant (doctor/clinic) label with a display color. Distinct from the
|
||||
* global slug-based {@see Tag} taxonomy — these are owned and managed by each
|
||||
* tenant for their own use (e.g. patient/appointment labelling).
|
||||
*/
|
||||
#[ORM\Entity(repositoryClass: TenantTagRepository::class)]
|
||||
#[ORM\Table(name: 'tenant_tags')]
|
||||
#[ORM\Index(columns: ['entity_type', 'entity_id'], name: 'idx_tenant_tags_owner')]
|
||||
class TenantTag
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column(type: 'integer')]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(type: 'string', length: 36, unique: true)]
|
||||
private string $uuid;
|
||||
|
||||
#[ORM\Column(name: 'entity_type', type: 'string', length: 20)]
|
||||
private string $entityType;
|
||||
|
||||
#[ORM\Column(name: 'entity_id', type: 'integer')]
|
||||
private int $entityId;
|
||||
|
||||
#[ORM\Column(type: 'string', length: 60)]
|
||||
private string $name;
|
||||
|
||||
/** Hex color, e.g. "#5559CE". */
|
||||
#[ORM\Column(type: 'string', length: 9)]
|
||||
private string $color = '#5559CE';
|
||||
|
||||
#[ORM\Column(type: 'boolean')]
|
||||
private bool $active = true;
|
||||
|
||||
#[ORM\Column(name: 'created_at', type: 'integer')]
|
||||
private int $createdAt;
|
||||
|
||||
#[ORM\Column(name: 'updated_at', type: 'integer')]
|
||||
private int $updatedAt;
|
||||
|
||||
public function __construct(string $entityType, int $entityId, string $name, string $color = '#5559CE')
|
||||
{
|
||||
$this->uuid = Uuid::v4()->toRfc4122();
|
||||
$this->entityType = $entityType;
|
||||
$this->entityId = $entityId;
|
||||
$this->name = $name;
|
||||
$this->color = $color;
|
||||
$this->createdAt = time();
|
||||
$this->updatedAt = time();
|
||||
}
|
||||
|
||||
public function getId(): ?int { return $this->id; }
|
||||
public function getUuid(): string { return $this->uuid; }
|
||||
public function getEntityType(): string { return $this->entityType; }
|
||||
public function getEntityId(): int { return $this->entityId; }
|
||||
public function getName(): string { return $this->name; }
|
||||
public function getColor(): string { return $this->color; }
|
||||
public function isActive(): bool { return $this->active; }
|
||||
|
||||
public function setName(string $v): self { $this->name = $v; $this->updatedAt = time(); return $this; }
|
||||
public function setColor(string $v): self { $this->color = $v; $this->updatedAt = time(); return $this; }
|
||||
public function setActive(bool $v): self { $this->active = $v; $this->updatedAt = time(); return $this; }
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'uuid' => $this->uuid,
|
||||
'name' => $this->name,
|
||||
'color' => $this->color,
|
||||
'active' => $this->active,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Tag\Repository;
|
||||
|
||||
use App\Tag\Entity\TenantTag;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
class TenantTagRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, TenantTag::class);
|
||||
}
|
||||
|
||||
public function findByUuid(string $uuid): ?TenantTag
|
||||
{
|
||||
return $this->findOneBy(['uuid' => $uuid]);
|
||||
}
|
||||
|
||||
/** @return TenantTag[] */
|
||||
public function findByEntity(string $entityType, int $entityId): array
|
||||
{
|
||||
return $this->createQueryBuilder('t')
|
||||
->where('t.entityType = :type AND t.entityId = :id')
|
||||
->setParameter('type', $entityType)
|
||||
->setParameter('id', $entityId)
|
||||
->orderBy('t.name', 'ASC')
|
||||
->getQuery()
|
||||
->getResult();
|
||||
}
|
||||
|
||||
public function save(TenantTag $tag): void
|
||||
{
|
||||
$this->getEntityManager()->persist($tag);
|
||||
$this->getEntityManager()->flush();
|
||||
}
|
||||
|
||||
public function remove(TenantTag $tag): void
|
||||
{
|
||||
$this->getEntityManager()->remove($tag);
|
||||
$this->getEntityManager()->flush();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user