# Permission Synchronization Templates

> Referenced from `steps/step-04-perms.md` — C# code templates for Permissions.cs, PermissionConfiguration.cs, and Postman tests.

---

## Permissions.cs Template

**Target file:** `src/SmartStack.Application/Common/Authorization/Permissions.cs`

**Find the correct parent class based on `{permission_path}`:**

| Permission Path | Parent Class |
|-----------------|--------------|
| `administration.*` | `Administration` |
| `support.*` | `Support` |
| `{application}.*` | `{Application}` |
| `myspace.*` | `MySpace` |

**Add nested class:**

```csharp
public static class {module}
{
    public const string View = "{permission_path}.read";
    public const string Create = "{permission_path}.create";
    public const string Update = "{permission_path}.update";
    public const string Delete = "{permission_path}.delete";
}
```

**Example for support.tickets:**

```csharp
public static partial class Permissions
{
    public static class Support
    {
        // Existing classes...

        public static class Tickets  // NEW
        {
            public const string View = "support.tickets.read";
            public const string Create = "support.tickets.create";
            public const string Update = "support.tickets.update";
            public const string Delete = "support.tickets.delete";
        }
    }
}
```

---

## PermissionConfiguration.cs Template

**Target file:** `src/SmartStack.Infrastructure/Persistence/Configurations/PermissionConfiguration.cs`

**Find HasData section and add seeds:**

```csharp
builder.HasData(
    // Existing permissions...

    // {module} permissions
    new Permission
    {
        Id = Guid.NewGuid(), // Generate new GUID
        Code = "{permission_path}.read",
        Name = "View {module}",
        Description = "Allows viewing {module_lowercase} list and details",
        Category = "{area}",
        IsSystem = true,
        CreatedAt = new DateTime(2024, 1, 1, 0, 0, 0, DateTimeKind.Utc)
    },
    new Permission
    {
        Id = Guid.NewGuid(),
        Code = "{permission_path}.create",
        Name = "Create {module}",
        Description = "Allows creating new {module_lowercase}",
        Category = "{area}",
        IsSystem = true,
        CreatedAt = new DateTime(2024, 1, 1, 0, 0, 0, DateTimeKind.Utc)
    },
    new Permission
    {
        Id = Guid.NewGuid(),
        Code = "{permission_path}.update",
        Name = "Update {module}",
        Description = "Allows updating existing {module_lowercase}",
        Category = "{area}",
        IsSystem = true,
        CreatedAt = new DateTime(2024, 1, 1, 0, 0, 0, DateTimeKind.Utc)
    },
    new Permission
    {
        Id = Guid.NewGuid(),
        Code = "{permission_path}.delete",
        Name = "Delete {module}",
        Description = "Allows deleting {module_lowercase}",
        Category = "{area}",
        IsSystem = true,
        CreatedAt = new DateTime(2024, 1, 1, 0, 0, 0, DateTimeKind.Utc)
    }
);
```

---

## Postman Test Templates

**If `{postman_mode}` = true, generate API tests:**

```json
{
  "name": "{module} API Tests",
  "item": [
    {
      "name": "GET {module} - SuperAdmin (200)",
      "request": {
        "method": "GET",
        "url": "{{baseUrl}}/api/{area}/{module}"
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "exec": ["pm.test('Status 200', () => pm.response.to.have.status(200));"]
          }
        }
      ]
    },
    {
      "name": "GET {module} - No Permission (403)",
      "request": { "method": "GET", "url": "{{baseUrl}}/api/{area}/{module}" },
      "event": [
        {
          "listen": "prerequest",
          "script": { "exec": ["// Use NoPermUser token"] }
        },
        {
          "listen": "test",
          "script": { "exec": ["pm.test('Status 403', () => pm.response.to.have.status(403));"] }
        }
      ]
    }
  ]
}
```
