hackforla / peopledepot

A project to setup a datastore for people and projects at HackforLA. The link below takes you to the code documentation
https://hackforla.github.io/peopledepot/
GNU General Public License v2.0
5 stars 24 forks source link

Create Table: user permission #22

Open fyliu opened 1 year ago

fyliu commented 1 year ago

Dependency

Overview

We need to create the user permission table so that we can update a shared data store across hackforla.org, vrms, civictechjobs, and tables (onboarding) project.

Details

A table and a model are the same thing

Action Items

Resources/Instructions

Items to document (referenced above)

Description

Data Fields

  1. Copied from spreadsheet and checked off according to ERD. Data fields are bolded and relation fields are not. (unchecked items indicate a mismatch between ERD and spreadsheet, which requires a review)

    • [x] PK - id - int - Record Id
    • [x] FK - user_id - int - Record Id
    • [x] FK - project_id - int - Record Id
    • [x] FK - permission_type_id - int
    • [x] FK - practice_area_id - int - Record Id
    • [x] granted - timestamp
    • [x] ended - timestamp
  2. In ERD only (having items here indicates a mismatch, which requires a review)

    • created_by - int
    • updated_by - int

Associated Tables

  1. Copied from spreadsheet and checked off according to ERD (unchecked items indicate a mismatch between ERD and spreadsheet, which requires a review)

    • [x] permission_type (many-to-one)
    • [x] practice_area (many-to-one)
    • [x] project (many-to-one)
    • [x] practice_area_id (many-to-one)
    • [x] user (many-to-one)
  2. In ERD only (having items here indicates a mismatch, which requires a review)

    • None

Swagger Endpoint Link

-

Neecolaa commented 1 year ago

created_by and updated_by are both foreign keys containing user ids. If a permission isn't what it should be, we can use these values to figure out who to ask. I've just added the fields to the spreadsheet.

fyliu commented 1 year ago

@Neecolaa This table is really a "membership" relationship xref table between user and project, with associated roles and permissions attributes. Should we change the name to "membership" or "member" or similar?

joshuayhwu commented 1 year ago
class Permission(AbstractBaseModel):
    """
    Permission
    """
    id = models.IntegerField(primary_key=True)
    user_id = models.ForeignKey(User, on_delete=models.CASCADE)
    project_Id = models.ForeignKey(Project, on_delete=models.CASCADE)
    permission_type = models.ForeignKey(Project, on_delete=models.CASCADE)
    granted = models.DateTimeField()
    ended = models.DateTimeField()

    def __str__(self): 
        return f"{self.name}" 
fyliu commented 1 year ago

Update for the record: according to @ExperimentsInHonesty during a meeting, this is not a membership junction table between user and project. It's a property relating to user. There's an optional reference to project if it makes sense to have it. Where it doesn't make sense is for a brigade admin role which has permission to all projects under that brigade.

fyliu commented 1 year ago

This issue (or a closely-related new issue) requires some research into the best way to implement permissions in django.

Neecolaa commented 1 year ago

ERD/SS To-do: replace role_id with practice_area_id

remove relationship between role and permission tables

add relationship between practice_area and permission tables

Discussion for these changes happened here: https://github.com/hackforla/peopledepot/discussions/170