S
Sheba ISP ERPDOCS
Backend Modules

apps.authentication — Identity, RBAC & Resellers

Authentication tokens, staff profiles, multi-tenant RBAC permissions, and reseller commissions.

apps.authentication — Identity, RBAC & Resellers

IMPLEMENTED

  • Location: backend/apps/authentication/
  • Responsibilities: User authentication, token issuance, staff tenant membership, role-based access control, and reseller financial ledgers.

1. Database Models (6 Models)

Model NamePurposeKey FieldsConstraints
StaffProfileLinks Django User to ISP staff detailsuser, phone, designation, is_activeOneToOne with auth.User
PermissionGranular permission definitionscode, name, module, descriptioncode is unique
RoleTenant-scoped bundle of permissionstenant, name, permissions, is_system_defaultUnique (tenant, name)
StaffMembershipAssociates a user to a tenant with a specific roletenant, user, role, is_active, joined_atUnique (tenant, user)
ResellerExternal bandwidth reseller / sub-ISP profiletenant, user, company_name, balance, credit_limitTenant-scoped
ResellerLedgerEntryFinancial transactions for reseller deposits/debitsreseller, amount, entry_type, balance_afterImmutable ledger

2. Authorization & RBAC Workflow

Permissions are defined in apps.authentication.permissions:

class HasPermissionScope(permissions.BasePermission):
    """
    Checks if the authenticated staff member possesses the required permission code
    within the resolved request.tenant.
    """
    def has_permission(self, request, view):
        if not request.user or not request.user.is_authenticated:
            return False
        if request.user.is_superuser:
            return True
        membership = StaffMembership.objects.filter(
            user=request.user,
            tenant=request.tenant,
            is_active=True
        ).select_related('role').first()
        if not membership or not membership.role:
            return False
        required_perm = getattr(view, 'required_permission', None)
        return membership.role.permissions.filter(code=required_perm).exists()

3. Endpoints

  • POST /api/v1/auth/login/: Validates credentials, returns Token and tenant membership.
  • GET /api/v1/auth/me/: Returns current profile, assigned role, and permitted capability flags.
  • GET/POST /api/v1/staff/: Staff CRUD within tenant.
  • GET/POST /api/v1/roles/: Custom role management with permission checkbox assignment.

On this page