hngprojects / hng_boilerplate_java_web

Apache License 2.0
157 stars 42 forks source link

[FEAT]: Send Organisation Invite Via Email #360

Open IgweWisdomJaminel opened 1 month ago

IgweWisdomJaminel commented 1 month ago

Issue Description: Create User Invitation System

Description: Develop a system for inviting users to organizations via email with time-limited invitation links. The system should support sending multiple invitations in a single request and ensure that only authorized users can send invitations.

Authentication and Authorization:

Acceptance Criteria:

Data Validation and Sanitization:

Purpose: To invite users to join an organization by sending secure, time-limited invitation links via email.

Expected Outcome: A fully functional invitation system that allows organization admins to invite new members (single or multiple) to join organizations through secure, time-limited invitation links sent to their email addresses.

API Endpoints:

  1. Send Invitation(s) [POST] /api/v1/organisations/send-invite

    Request Headers:

    • Authorization: Bearer <JWT_TOKEN>

    Request Body:

    {
     "emails": ["user1@example.com", "user2@example.com", "user3@example.com"],
     "org_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
    }

    Success Response (201 Created):

    {
     "message": "Invitation(s) sent successfully",
     "invitations": [
       {
         "email": "user1@example.com",
         "organization": "My Organization",
         "expires_at": "2023-07-23T00:00:00Z"
       },
       {
         "email": "user2@example.com",
         "organization": "My Organization",
         "expires_at": "2023-07-23T00:00:00Z"
       },
       {
         "email": "user3@example.com",
         "organization": "My Organization",
         "expires_at": "2023-07-23T00:00:00Z"
       }
     ]
    }

    Failure Responses:

    • 400 Bad Request:
      {
      "error": "Invalid request",
      "message": "One or more email addresses are not valid"
      }
    • 403 Forbidden:
      {
      "error": "Unauthorized",
      "message": "You do not have admin rights for this organization"
      }
    • 404 Not Found: Organization not found.
    • 413 Payload Too Large: Exceeding emails limit.
    • 429 Too Many Requests: Rate limit exceeded.
    • 401 Unauthorized: Invalid or expired JWT.
    • 500 Internal Server Error: Generic error message.

Error Handling:

Requirements:

  1. Create an API for sending invitations to multiple email addresses.
  2. Implement JWT authentication protection for the API endpoint.
  3. Implement authorization checks for admin actions.
  4. Implement email sending for invitations.
  5. Implement rate limiting for invitation sending to prevent abuse.
  6. Write tests for the invitation system.

Testing:

Olatomiw commented 1 month ago

I HAVE WORKED ON THIS ALREADY