Skip to content

Api v2#94

Merged
michael-pisman merged 35 commits intomainfrom
api_v2
Jul 30, 2025
Merged

Api v2#94
michael-pisman merged 35 commits intomainfrom
api_v2

Conversation

@michael-pisman
Copy link
Member

This pull request introduces several updates across the unipoll_api codebase, focusing on enhancing group and poll management, improving exception handling, and refining dependencies and routing. The most significant changes include adding support for workspace inclusion in group queries, improving poll creation and update workflows, and standardizing exception handling for better error reporting.

Enhancements to Group and Poll Management:

  • Added a new include_workspace parameter to the get_group function, allowing workspace details to be optionally included in the response. Updated the workspace serialization to only include specific fields (id, name, description). ([[1]](https://github.com/csed-ucm/psephos/pull/94/files#diff-dafacf886695f5ded37150101af1be3e3eaefe9562182fb92003050ac4d9ea41R85), [[2]](https://github.com/csed-ucm/psephos/pull/94/files#diff-dafacf886695f5ded37150101af1be3e3eaefe9562182fb92003050ac4d9ea41L92-R96))
  • Enhanced poll creation by adding the user as the owner of the poll and ensuring the poll response includes detailed workspace and policy information. ([[1]](https://github.com/csed-ucm/psephos/pull/94/files#diff-393f0167ffc02c3865cf57eaef625a206bb5582b78f4346360418f2ea85eb9b4R40-R49), [[2]](https://github.com/csed-ucm/psephos/pull/94/files#diff-393f0167ffc02c3865cf57eaef625a206bb5582b78f4346360418f2ea85eb9b4R61-R91))
  • Fixed a bug in update_poll where the workspace turned into a link after updating. Added a workaround to save the workspace before updating the poll and adjusted the response format. ([[1]](https://github.com/csed-ucm/psephos/pull/94/files#diff-393f0167ffc02c3865cf57eaef625a206bb5582b78f4346360418f2ea85eb9b4L104-R128), [[2]](https://github.com/csed-ucm/psephos/pull/94/files#diff-393f0167ffc02c3865cf57eaef625a206bb5582b78f4346360418f2ea85eb9b4L119-R151))

Improvements to Exception Handling:

  • Updated the UserNotAuthorized exception across various modules to provide more detailed error messages, including the resource type and name. ([[1]](https://github.com/csed-ucm/psephos/pull/94/files#diff-1e8b4b8d122438e7353e075faa822301eae17d32f5b0cad06bc0edd42d5540fbL26-R26), [[2]](https://github.com/csed-ucm/psephos/pull/94/files#diff-97c1cbf5172089ef1a5aa111a40e5a58a33ea8f9eac23dae7f6f25303d23cab4L44-R44), [[3]](https://github.com/csed-ucm/psephos/pull/94/files#diff-cd5d188f559d03db25c276cb5c415e1d87bf97884e9be1d57dbcb0e475df8f55L49-R51))
  • Standardized the exception for non-unique resource names to use a 409 Conflict status code instead of 400 Bad Request. ([src/unipoll_api/exceptions/resource.pyL25-R25](https://github.com/csed-ucm/psephos/pull/94/files#diff-cd5d188f559d03db25c276cb5c415e1d87bf97884e9be1d57dbcb0e475df8f55L25-R25))
  • Refined exceptions for group and workspace member removal to use Member instead of Account for better clarity. ([[1]](https://github.com/csed-ucm/psephos/pull/94/files#diff-e03beb28c2b49fefb15a90fa9c708b2e1c508a57afd6a8c2ec6b5ef386f117c5L55-R56), [[2]](https://github.com/csed-ucm/psephos/pull/94/files#diff-97c1cbf5172089ef1a5aa111a40e5a58a33ea8f9eac23dae7f6f25303d23cab4L55-R56))

Dependency and Routing Updates:

  • Added PollRoutes to the main router and simplified dependencies for group and poll routes. ([[1]](https://github.com/csed-ucm/psephos/pull/94/files#diff-6213aa2dc7904bee716b9ca3823c29275ebb5f333e3fe5d33edaa122c807931aR9), [[2]](https://github.com/csed-ucm/psephos/pull/94/files#diff-6213aa2dc7904bee716b9ca3823c29275ebb5f333e3fe5d33edaa122c807931aL25-R28))
  • Introduced new group-related endpoints for listing and creating groups within a workspace. Updated existing group routes to include workspace dependencies. ([src/unipoll_api/routes/v1/group.pyL8-R80](https://github.com/csed-ucm/psephos/pull/94/files#diff-7681ab21657eddc8645d7d308f57b83c727ed507df239491209de5e8ec134603L8-R80))

Other Notable Changes:

  • Replaced the Link type with BackLink for the workspace field in the Poll document to better represent relationships. ([src/unipoll_api/documents.pyL172-L177](https://github.com/csed-ucm/psephos/pull/94/files#diff-9436de0bdd228d52bac6a9e652a53b49bf48b90044ffd098203ef31595faaf42L172-L177))
  • Updated the exception raised when a member is not found in a resource to provide a more specific error message. ([src/unipoll_api/dependencies.pyL49-R52](https://github.com/csed-ucm/psephos/pull/94/files#diff-bfce4882dc04f49a73a81580802630710122d01e4c8c35b2580c7a5bcf73a3eaL49-R52))
  • Corrected the exception type for a missing poll in get_poll to use PollNotFound instead of GroupNotFound. ([src/unipoll_api/dependencies.pyL104-R103](https://github.com/csed-ucm/psephos/pull/94/files#diff-bfce4882dc04f49a73a81580802630710122d01e4c8c35b2580c7a5bcf73a3eaL104-R103))

Added endpoints to get, update, and delete polls
This route returns list of all permissions a member has in a workspace and permissions for each group in the workspace that a member is a part of
Fixed issues with permissions fetching and formatted the output
The validator check that published polls have questions, and that questions' ids are in correct format
Added validators to check if question id is positive, correct options are postitive, unique, and in the possible range
Since polls do not have members there needs to be a condition to get member from workspace insted
When updating poll the response would return backling objet to the workspace instead of the workspace schema, the issue was caused by saving the poll and subsequently replacing mongo document, to resolve the issue the workspace is stored before updating the poll
Added an endpoint to get member permissions in a workspace and a group
When user has no permissions, the function should return empty list
If a user does not have a policy, the function would raise HTTP Exception, so an additional try-excpept block is required
When getting poll policies, we should use workspace for getting member list, since poll does not have members
Raise UserNotAuthorized if user is not a member
User now is able to get polls with get_poll or get_polls(workspace) permission
Added name and description field validation
Copilot AI review requested due to automatic review settings July 30, 2025 06:48
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request introduces API version 2 enhancements to the unipoll API, focusing on improving group and poll management, standardizing exception handling, and adding comprehensive permission management. The changes enhance workspace inclusion capabilities, refine validation logic, and restructure routing for better organization.

  • Improved group and poll management with enhanced query parameters and validation
  • Standardized exception handling with more descriptive error messages and proper HTTP status codes
  • Enhanced permission management system with new member permission endpoints

Reviewed Changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/unipoll_api/utils/permissions.py Enhanced permission checking with better error handling and resource-specific logic
src/unipoll_api/schemas/workspace.py Added field validation constraints for workspace creation and update requests
src/unipoll_api/schemas/question.py Implemented comprehensive validation for question schemas with type constraints
src/unipoll_api/schemas/poll.py Added poll validation logic and workspace field updates
src/unipoll_api/routes/v2/polls.py Fixed parameter initialization bug in poll retrieval
src/unipoll_api/routes/v2/permissions.py Added new member permissions endpoint with comprehensive permission listing
src/unipoll_api/routes/v2/groups.py Extended group query parameters to include workspace information
src/unipoll_api/routes/v1/workspace.py Refactored workspace routes with new permission endpoint
src/unipoll_api/routes/v1/poll.py New poll management routes with workspace-scoped endpoints
src/unipoll_api/routes/v1/group.py Updated group routes with workspace dependencies and new permission endpoints
src/unipoll_api/routes/v1/init.py Added poll routes to main router configuration
src/unipoll_api/exceptions/workspace.py Updated exception handling to use Member instead of Account
src/unipoll_api/exceptions/resource.py Improved exception messages and changed status codes for better clarity
src/unipoll_api/exceptions/poll.py Standardized poll exception handling
src/unipoll_api/exceptions/group.py Updated group exception handling consistency
src/unipoll_api/documents.py Modified Poll document structure with BackLink for workspace relationship
src/unipoll_api/dependencies.py Fixed exception types and improved error handling
src/unipoll_api/actions/poll.py Enhanced poll creation and update logic with better workspace handling
src/unipoll_api/actions/policy.py Added resource-specific member retrieval logic
src/unipoll_api/actions/group.py Added workspace inclusion support for group operations

params = {"include_questions": True,
"include_policies": True}
else:
if "groups" in include:
Copy link

Copilot AI Jul 30, 2025

Choose a reason for hiding this comment

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

The condition checks for "groups" but should check for "questions" based on the context and the parameter assignment on line 58.

Suggested change
if "groups" in include:
if "questions" in include:

Copilot uses AI. Check for mistakes.
Comment on lines +65 to +66
if "workspaces" in include:
params["include_workspaces"] = True
Copy link

Copilot AI Jul 30, 2025

Choose a reason for hiding this comment

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

The condition checks for "workspaces" (plural) but should check for "workspace" (singular) to match the query parameter definition and the parameter assignment on line 66.

Suggested change
if "workspaces" in include:
params["include_workspaces"] = True
if "workspace" in include:
params["include_workspace"] = True

Copilot uses AI. Check for mistakes.
if "policies" in include:
params["include_policies"] = True
if "workspaces" in include:
params["include_workspaces"] = True
Copy link

Copilot AI Jul 30, 2025

Choose a reason for hiding this comment

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

The parameter name should be "include_workspace" (singular) to match the function parameter in the GroupActions.get_group method.

Suggested change
params["include_workspaces"] = True
params["include_workspace"] = True

Copilot uses AI. Check for mistakes.
@michael-pisman michael-pisman merged commit 1472fc7 into main Jul 30, 2025
1 check failed
@michael-pisman michael-pisman deleted the api_v2 branch July 30, 2025 06:52
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.

1 participant