kontenhumas-be/docs/USERS_INFO_APPROVAL_WORKFLO...

6.0 KiB

Users Info API Enhancement - Approval Workflow Information

Overview

This document describes the enhancement made to the users/info API to include approval workflow information, allowing users to know whether their client has set up approval workflows or not.

Changes Made

1. Response Structure Enhancement

File: app/module/users/response/users.response.go

Added new fields to UsersResponse struct:

type UsersResponse struct {
    // ... existing fields ...
    
    // Approval Workflow Info
    ApprovalWorkflowInfo *ApprovalWorkflowInfo `json:"approvalWorkflowInfo,omitempty"`
}

type ApprovalWorkflowInfo struct {
    HasWorkflowSetup     bool   `json:"hasWorkflowSetup"`
    DefaultWorkflowId    *uint  `json:"defaultWorkflowId,omitempty"`
    DefaultWorkflowName  *string `json:"defaultWorkflowName,omitempty"`
    RequiresApproval     *bool  `json:"requiresApproval,omitempty"`
    AutoPublishArticles  *bool  `json:"autoPublishArticles,omitempty"`
    IsApprovalActive     *bool  `json:"isApprovalActive,omitempty"`
}

2. Service Layer Enhancement

File: app/module/users/service/users.service.go

Added Dependencies

  • ApprovalWorkflowsRepository - to access approval workflow data
  • ClientApprovalSettingsRepository - to access client approval settings

Enhanced ShowUserInfo Method

The ShowUserInfo method now:

  1. Retrieves user information as before
  2. Calls getApprovalWorkflowInfo() to get workflow information
  3. Combines both pieces of information in the response

New Method: getApprovalWorkflowInfo

func (_i *usersService) getApprovalWorkflowInfo(clientId *uuid.UUID) (*response.ApprovalWorkflowInfo, error)

This method:

  • Checks if client has approval settings configured
  • Retrieves default workflow information if available
  • Returns comprehensive workflow status information

3. Mapper Enhancement

File: app/module/users/mapper/users.mapper.go

Updated UsersResponseMapper to include a comment indicating that ApprovalWorkflowInfo will be set by the service layer.

API Response Examples

Client with Workflow Setup

{
  "success": true,
  "messages": ["Users successfully retrieve"],
  "data": {
    "id": 1,
    "username": "john.doe",
    "email": "john.doe@example.com",
    "fullname": "John Doe",
    "userLevelId": 2,
    "userLevelGroup": "Editor",
    "isActive": true,
    "approvalWorkflowInfo": {
      "hasWorkflowSetup": true,
      "defaultWorkflowId": 1,
      "defaultWorkflowName": "Standard Article Approval",
      "requiresApproval": true,
      "autoPublishArticles": false,
      "isApprovalActive": true
    }
  }
}

Client without Workflow Setup

{
  "success": true,
  "messages": ["Users successfully retrieve"],
  "data": {
    "id": 1,
    "username": "john.doe",
    "email": "john.doe@example.com",
    "fullname": "John Doe",
    "userLevelId": 2,
    "userLevelGroup": "Editor",
    "isActive": true,
    "approvalWorkflowInfo": {
      "hasWorkflowSetup": false
    }
  }
}

Client with Workflow but No Default Workflow

{
  "success": true,
  "messages": ["Users successfully retrieve"],
  "data": {
    "id": 1,
    "username": "john.doe",
    "email": "john.doe@example.com",
    "fullname": "John Doe",
    "userLevelId": 2,
    "userLevelGroup": "Editor",
    "isActive": true,
    "approvalWorkflowInfo": {
      "hasWorkflowSetup": true,
      "requiresApproval": true,
      "autoPublishArticles": false,
      "isApprovalActive": true
    }
  }
}

Field Descriptions

ApprovalWorkflowInfo Fields

Field Type Description
hasWorkflowSetup bool Indicates whether the client has any approval workflow configuration
defaultWorkflowId *uint ID of the default workflow (if set)
defaultWorkflowName *string Name of the default workflow (if set)
requiresApproval *bool Whether the client requires approval for articles
autoPublishArticles *bool Whether articles are auto-published after creation
isApprovalActive *bool Whether the approval system is active for this client

Error Handling

The implementation includes robust error handling:

  1. Graceful Degradation: If workflow information cannot be retrieved, the API still returns user information without workflow data
  2. Logging: All errors are logged for debugging purposes
  3. Non-blocking: Workflow information retrieval failures don't prevent user information from being returned

Usage Scenarios

1. Frontend Dashboard

The frontend can now check approvalWorkflowInfo.hasWorkflowSetup to:

  • Show/hide approval workflow setup prompts
  • Display workflow status indicators
  • Guide users through workflow configuration

2. Article Creation Flow

Before creating articles, the frontend can check:

  • requiresApproval - to determine if approval is needed
  • autoPublishArticles - to know if articles will be auto-published
  • isApprovalActive - to verify the approval system is active

3. Workflow Management

The frontend can display:

  • Current default workflow name
  • Workflow configuration status
  • Approval system status

Benefits

  1. Single API Call: Users can get both user info and workflow status in one request
  2. Real-time Status: Always shows current workflow configuration status
  3. User Experience: Users immediately know if they need to set up workflows
  4. Frontend Efficiency: Reduces the need for multiple API calls
  5. Backward Compatibility: Existing API consumers continue to work without changes

Implementation Notes

  • The approvalWorkflowInfo field is optional (omitempty) to maintain backward compatibility
  • Error handling ensures the API remains stable even if workflow services are unavailable
  • The implementation follows the existing code patterns and architecture
  • All changes are non-breaking and additive

This enhancement provides users with immediate visibility into their approval workflow setup status, improving the overall user experience and reducing confusion about workflow configuration.