Add rule templates for reusable access control rules 🚀 #1103

Closed
opened 2026-04-05 18:17:52 +02:00 by MrUnknownDE · 0 comments
Owner

Originally created by @adrianeastles on 8/7/2025

Community Contribution License Agreement

By creating this pull request, I grant the project maintainers an unlimited,
perpetual license to use, modify, and redistribute these contributions under any terms they
choose, including both the AGPLv3 and the Fossorial Commercial license terms. I
represent that I have the right to grant this license for all contributed content.

Description

This PR adds a new rule templates feature that allows users to create reusable sets of access control rules that can be assigned to multiple resources. This provides a more efficient way to manage consistent access control across multiple resources.

Key Features

  • Rule Templates Management: Create, edit, and delete rule templates
  • Template Assignment: Assign templates to resources, automatically creating resource rules from template rules
  • Automatic Propagation: Changes to template rules automatically propagate to all assigned resources
  • Template Rule Protection: Rules created from templates are protected from editing (except priority) on resource pages
  • Visual Indicators: Clear badges distinguish between template-managed and manual rules

Technical Implementation

  • New database tables: ruleTemplates, templateRules, resourceTemplates
  • Added templateRuleId field to resourceRules for tracking template origins

Database Changes

  • Migration script 1.10.0 adds new tables and templateRuleId column

How to test?

1. Create a Rule Template

  1. Navigate to http://localhost:3002/org/settings/rule-templates
  2. Click "Create Template" and fill in name/description
  3. Verify template appears in the list

2. Add Rules to Template

  1. Click on a template to edit it
  2. Go to the "Rules" tab (default)
  3. Add rules with different match types (IP, IP Range, Path)
  4. Verify rules appear in the table and can be edited/deleted

3. Assign Template to Resource

  1. Go to a resource's rules page: http://localhost:3002/org/settings/resources/{resourceId}/rules
  2. Enable rules if not already enabled
  3. In the "Rule templates" section, assign a template
  4. Verify template rules appear in the resource rules table with "Template" badges

4. Test Template Rule Protection

  1. On the resource rules page, try to edit a template-managed rule
  2. Verify only priority can be changed, other fields are disabled
  3. Verify delete button is disabled for template rules

5. Test Template Rule Propagation

  1. Edit a rule in the template
  2. Verify the change propagates to all assigned resources
  3. Verify the resource rules show the updated values

6. Test Template Unassignment

  1. Unassign a template from a resource
  2. Verify all template-managed rules are removed from the resource
  3. Verify manual rules remain unchanged

Screenshots

Rule Template Screens

Screenshot 2025-08-07 at 11 10 59 pm Screenshot 2025-08-07 at 11 11 06 pm Screenshot 2025-08-07 at 11 11 19 pm

Resource Rules Screens

Screenshot 2025-08-07 at 11 12 31 pm Screenshot 2025-08-07 at 11 12 39 pm
*Originally created by @adrianeastles on 8/7/2025* ## Community Contribution License Agreement By creating this pull request, I grant the project maintainers an unlimited, perpetual license to use, modify, and redistribute these contributions under any terms they choose, including both the AGPLv3 and the Fossorial Commercial license terms. I represent that I have the right to grant this license for all contributed content. ### Description This PR adds a new rule templates feature that allows users to create reusable sets of access control rules that can be assigned to multiple resources. This provides a more efficient way to manage consistent access control across multiple resources. ### Key Features - **Rule Templates Management**: Create, edit, and delete rule templates - **Template Assignment**: Assign templates to resources, automatically creating resource rules from template rules - **Automatic Propagation**: Changes to template rules automatically propagate to all assigned resources - **Template Rule Protection**: Rules created from templates are protected from editing (except priority) on resource pages - **Visual Indicators**: Clear badges distinguish between template-managed and manual rules ### Technical Implementation - New database tables: `ruleTemplates`, `templateRules`, `resourceTemplates` - Added `templateRuleId` field to `resourceRules` for tracking template origins ### Database Changes - Migration script `1.10.0` adds new tables and `templateRuleId` column ## How to test? ### 1. Create a Rule Template 1. Navigate to `http://localhost:3002/org/settings/rule-templates` 2. Click "Create Template" and fill in name/description 3. Verify template appears in the list ### 2. Add Rules to Template 1. Click on a template to edit it 2. Go to the "Rules" tab (default) 3. Add rules with different match types (IP, IP Range, Path) 4. Verify rules appear in the table and can be edited/deleted ### 3. Assign Template to Resource 1. Go to a resource's rules page: `http://localhost:3002/org/settings/resources/{resourceId}/rules` 2. Enable rules if not already enabled 3. In the "Rule templates" section, assign a template 4. Verify template rules appear in the resource rules table with "Template" badges ### 4. Test Template Rule Protection 1. On the resource rules page, try to edit a template-managed rule 2. Verify only priority can be changed, other fields are disabled 3. Verify delete button is disabled for template rules ### 5. Test Template Rule Propagation 1. Edit a rule in the template 2. Verify the change propagates to all assigned resources 3. Verify the resource rules show the updated values ### 6. Test Template Unassignment 1. Unassign a template from a resource 2. Verify all template-managed rules are removed from the resource 3. Verify manual rules remain unchanged ### Screenshots #### Rule Template Screens <img width="1783" height="613" alt="Screenshot 2025-08-07 at 11 10 59 pm" src="https://github.com/user-attachments/assets/3b6b06eb-a123-46f9-a39e-db23a27c1f8f" /> <img width="1788" height="616" alt="Screenshot 2025-08-07 at 11 11 06 pm" src="https://github.com/user-attachments/assets/091e5022-e577-4f93-89c8-cbfb97394b28" /> <img width="1777" height="681" alt="Screenshot 2025-08-07 at 11 11 19 pm" src="https://github.com/user-attachments/assets/24c6e848-80d7-4b8e-be6a-70edead5d514" /> #### Resource Rules Screens <img width="1785" height="1001" alt="Screenshot 2025-08-07 at 11 12 31 pm" src="https://github.com/user-attachments/assets/777707f0-ba2f-44de-bfa7-a07b8af258b0" /> <img width="1522" height="406" alt="Screenshot 2025-08-07 at 11 12 39 pm" src="https://github.com/user-attachments/assets/e0ffc578-d91f-4a49-af4b-a1e7227d38b6" />
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/pangolin#1103