# Implementation Plan

- [x] 1. Implement visibility filter in OrganizationService





  - [x] 1.1 Add GetVisibleUnitIdsAsync method to IOrganizationService interface


    - Add method signature with unitId and userLevel parameters
    - Return IEnumerable<int> of visible unit IDs
    - _Requirements: 3.1_
  - [x] 1.2 Implement GetVisibleUnitIdsAsync in OrganizationService


    - For Battalion/Company level: return own unit + direct children only
    - For Division/Regiment level: return own unit + all subordinates
    - _Requirements: 1.1, 1.2, 1.3, 1.4, 3.2, 3.3_
  - [x] 1.3 Write property test for restricted visibility (Property 1)


    - **Property 1: Restricted visibility for battalion/company level users**
    - **Validates: Requirements 1.1, 1.2, 1.3, 3.1, 3.2**
  - [x] 1.4 Write property test for full visibility (Property 2)


    - **Property 2: Full visibility for division/regiment level users**
    - **Validates: Requirements 1.4, 3.3**

- [x] 2. Update ReportingService to use visibility filter





  - [x] 2.1 Modify GetAggregatedDataAsync to accept userLevel parameter


    - Use GetVisibleUnitIdsAsync instead of GetAllSubordinateIdsAsync for filtering
    - _Requirements: 2.2_
  - [x] 2.2 Modify GetDetailedReportsAsync to accept userLevel parameter


    - Apply visibility filter to returned records
    - _Requirements: 2.1_
  - [x] 2.3 Update CanViewUnitDataAsync to use visibility scope


    - Check if target unit is in user's visible units
    - _Requirements: 2.3_

  - [x] 2.4 Write property test for access control (Property 3)

    - **Property 3: Access control respects visibility scope**
    - **Validates: Requirements 2.3**

- [x] 3. Update ReportsController to pass user level





  - [x] 3.1 Update GetDetailedReports endpoint


    - Pass unitLevel to service method
    - _Requirements: 2.1_
  - [x] 3.2 Update GetAggregatedData endpoint


    - Pass unitLevel to service method
    - _Requirements: 2.2_

  - [x] 3.3 Update GetByTargetUnit endpoint

    - Use updated CanViewUnitDataAsync with visibility check
    - _Requirements: 2.3_

- [x] 4. Checkpoint - Ensure all tests pass





  - Ensure all tests pass, ask the user if questions arise.
