Skip to content

Conversation

Tihitnaabraham
Copy link
Collaborator

@Tihitnaabraham Tihitnaabraham commented Sep 29, 2025

Description

This PR implements key backend components for the mlimizone marketplace including the data models and role-based REST API access control.

Perhaps answering the following questions will help create a good description:

  • What is this?

This is a backend implementation for an mlimizone marketplace system using Django and Django REST Framework. It includes custom data models (users, crops, produce listings, carts, orders, payments, market prices, SMS logs) and a role-based access control system that controls API access and permissions for different user roles such as farmers, wholesalers, and admins.

  • Why this?
    Role-based access control (RBAC) is essential to:

Secure sensitive data by ensuring users only access data relevant to their role.

Enforce business rules, e.g., only farmers can create produce listings, wholesalers manage their carts and orders, and admins control crop and price data.

Avoid unauthorized modifications or deletions of data, such as preventing cart deletions.

  • How are you doing this?
    By defining custom Django models that capture the necessary entities with proper relations.

Implementing Django REST Framework ModelViewSets for each model to provide standard API CRUD operations.

Using custom permission classes that inspect the authenticated user’s role and ownership on each object to control access and edits.

Overriding viewsets’ querysets to filter data based on the requesting user’s role and ownership.

Special permissions for admin users to have full access where appropriate but restricting general users to read-only on sensitive data.

Allowing authentication via both email through a custom user model and authentication backend, increasing flexibility and usability.

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Optimization
  • Improvement
  • Bug fix

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Test A - e.g Manually tested user creation
  • Test B

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@jmwai jmwai merged commit 0aff29b into develop Sep 29, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants