Skip to content

Require and validate source_uid when creating officers#533

Open
TristanGramsch wants to merge 2 commits intocodeforboston:mainfrom
TristanGramsch:fix/507-officer-require-source
Open

Require and validate source_uid when creating officers#533
TristanGramsch wants to merge 2 commits intocodeforboston:mainfrom
TristanGramsch:fix/507-officer-require-source

Conversation

@TristanGramsch
Copy link

Ensure each Officer created via POST has a valid source_uid. Validate source exists, connect it via the existing citation relationship, and add tests for missing/invalid source_uid. Fixes #507.

Ensure each Officer created via POST has a valid source_uid. Validate
source exists, connect it via the existing citation relationship, and add
tests for missing/invalid source_uid.

Fixes: codeforboston#507
Co-authored-by: Cursor <cursoragent@cursor.com>
@TristanGramsch
Copy link
Author

Hey @DMalone87, I saw this issue and took the initiative to solve it. Is it looking good?

officer = Officer.from_dict(body.model_dump())
# except Exception as e:
# abort(400, description=str(e))
source = Source.nodes.get_or_none(uid=body.source_uid)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great. The only other thing is that the current user needs to be a member of the Source organization and have a member role of at least Publisher.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

members = RelationshipFrom(

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice to hear. I see you solved that by adding line 148, correct? Let me know if I can still develop this issue.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I haven't changed anything. Just highlighting the section of code I'm talking about. Sorry I wasn't clear.

You'll need to add some logic that checks to see if the user is a member of the Source indicated by the source_uid. Something like:

    if source.members.is_connected(current_user):
        member_rel = source.members.relationship(current_user)
        if member_rel.may_publish()
          # Prodeed with Creation
        else:
        abort(403, description="No permission.")
    else:
        abort(403, description="No permission.")

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am looking at this! I made new changes, and I just need to run tests.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if I can help

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Darrel, I believe the last change solves the check for membership. I think this is ready for merge.

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.

[BUG] Officer Creation does not require a data source

2 participants