---
name: step-04-perms
description: Synchronize permissions in Permissions.cs and PermissionConfiguration.cs
next_step: steps/step-05-validate.md
---

# Step 4: Synchronize Permissions

## YOUR TASK:

Add permissions to both Permissions.cs (constants) and PermissionConfiguration.cs (database seeds).

**CRITICAL: Both files MUST be in sync. Missing permissions = runtime 403 errors.**

---

## EXECUTION SEQUENCE:

### 1. Update Permissions.cs

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

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

| Permission Path | Parent Class |
|-----------------|--------------|
| `platform.administration.*` | `Platform.Administration` |
| `platform.support.*` | `Platform.Support` |
| `business.*` | `Business` |
| `personal.myspace.*` | `Personal.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 platform.support.tickets:**

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

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

### 2. Update PermissionConfiguration.cs

**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)
    }
);
```

### 3. Generate Migration (Required)

**After updating PermissionConfiguration:**

```
IMPORTANT: New HasData entries require a migration!

Suggest command:
/efcore:migration Add{module}Permissions
```

**If auto_mode:**
- Inform user that migration is needed
- Do NOT auto-run migration (user decision)

### 4. Validation Check

**Verify sync between files:**

| Permission Code | In Permissions.cs | In PermissionConfiguration.cs |
|-----------------|-------------------|------------------------------|
| `{permission_path}.read` | ✅ | ✅ |
| `{permission_path}.create` | ✅ | ✅ |
| `{permission_path}.update` | ✅ | ✅ |
| `{permission_path}.delete` | ✅ | ✅ |

### 5. Generate Postman Tests (if postman_mode)

**If {postman_mode} = true:**

Load `postman-templates.md` and generate 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));"] }
        }
      ]
    }
  ]
}
```

---

## OUTPUT FORMAT:

```
Permissions Synchronized:

| File | Changes |
|------|---------|
| Permissions.cs | Added {module} class with 4 constants |
| PermissionConfiguration.cs | Added 4 permission seeds |
| Postman Collection | Added {test_count} tests |

⚠️ MIGRATION REQUIRED:
Run: /efcore:migration Add{module}Permissions

-> Validating build...
```

---

## NEXT STEP:

After permissions synced, proceed to `./step-05-validate.md`
