-
Notifications
You must be signed in to change notification settings - Fork 2
Private Consortia #112
Copy link
Copy link
Closed
Description
Implement Private Consortia Feature
Overview
Add support for private consortia that are only visible to the owner (leader), members, and admins. Private consortia should be hidden from users who are not part of the consortium. Only the leader can modify the privacy setting of a consortium.
Requirements
1. Database Schema Changes
- Add
isPrivate: Booleanfield to the Consortium model schema- Default value:
false(existing consortia remain public) - Location:
centralApi/src/database/models/Consortium.ts - Update
Consortiuminterface to includeisPrivate: boolean
- Default value:
2. GraphQL Schema Updates
- Add
isPrivate: Boolean!field toConsortiumListItemtype- Location:
centralApi/src/graphql/typeDefs.graphql
- Location:
- Add
isPrivate: Boolean!field toConsortiumDetailstype- Location:
centralApi/src/graphql/typeDefs.graphql
- Location:
- Update
consortiumCreatemutation to accept optionalisPrivate: Booleanparameter- Default to
falseif not provided
- Default to
- Update
consortiumEditmutation to accept optionalisPrivate: Booleanparameter
3. Backend Resolver Changes
getConsortiumList Query
- Filter consortia based on privacy and user access:
- If
isPrivate === false: Include in results (public consortia visible to all) - If
isPrivate === true: Only include if:- Current user is the leader (
consortium.leader.toString() === context.userId), OR - Current user is in the members array (
consortium.members.includes(context.userId)), OR - Current user has admin role (
context.roles?.includes('admin'))
- Current user is the leader (
- If
- Include
isPrivatefield in the returnedConsortiumListItemobjects - Location:
centralApi/src/graphql/resolvers.ts(line ~40)
getConsortiumDetails Query
- Add access control check:
- If
isPrivate === false: Allow access (public consortium) - If
isPrivate === true: Only allow if:- Current user is the leader, OR
- Current user is in the members array, OR
- Current user has admin role (
context.roles?.includes('admin'))
- If access denied, throw error:
"Access denied: This consortium is private"
- If
- Include
isPrivatefield in the returnedConsortiumDetailsobject - Location:
centralApi/src/graphql/resolvers.ts(line ~68)
consortiumCreate Mutation
- Accept optional
isPrivate: Booleanparameter - Set
isPrivatefield when creating new consortium - Default to
falseif not provided - Location:
centralApi/src/graphql/resolvers.ts(line ~750)
consortiumEdit Mutation
- Accept optional
isPrivate: Booleanparameter - Update
isPrivatefield if provided - Only allow leader to modify privacy setting - verify
consortium.leader.toString() === context.userIdbefore allowingisPrivatefield changes - When a consortium is made private, existing members retain access (no action needed)
- Location:
centralApi/src/graphql/resolvers.ts(line ~899)
4. Frontend Updates
GraphQL Query Updates
- Update
GET_CONSORTIUM_LIST_QUERYto includeisPrivatefield- Location:
desktopApp/reactApp/src/apis/centralApi/getConsortiumList.tsx
- Location:
- Update
GET_CONSORTIUM_DETAILSquery to includeisPrivatefield- Location:
desktopApp/reactApp/src/apis/centralApi/getConsortiumDetails.tsx
- Location:
UI Components
- Update consortium creation form to include privacy toggle/checkbox
- Update consortium edit form to include privacy toggle/checkbox (only visible/editable by leader)
- Note: No UI indicators (e.g., lock icons) needed in list view per requirements
5. Type Generation
- Regenerate GraphQL types after schema changes
- Run codegen to update generated types in:
centralApi/src/graphql/generated/graphql.tsdesktopApp/reactApp/src/apis/centralApi/generated/graphql.ts
- Run codegen to update generated types in:
6. Testing Considerations
- Test that public consortia (
isPrivate: false) are visible to all users - Test that private consortia (
isPrivate: true) are only visible to leader, members, and admins - Test that non-members cannot access private consortium details
- Test consortium creation with
isPrivate: trueandisPrivate: false - Test consortium edit to toggle privacy setting
- Test that existing consortia (without
isPrivatefield) default to public behavior - Test edge cases:
- User leaves private consortium (should no longer see it)
- User is removed from private consortium (should no longer see it)
- Leader changes privacy setting (only leader can modify)
- Admin can access private consortia even if not a member
- When consortium is made private, existing members retain access
Implementation Notes
Access Control Logic
The access check should verify:
const hasAccess =
!consortium.isPrivate ||
consortium.leader.toString() === context.userId ||
consortium.members.some(member => member.toString() === context.userId) ||
context.roles?.includes('admin')Privacy Setting Modification:
- Only the leader can change the
isPrivatefield - When a consortium is made private, existing members automatically retain access
Migration Considerations
- Existing consortia without
isPrivatefield should default tofalse(public) - Consider adding a migration script if needed, or rely on Mongoose defaults
Security
- Ensure
context.userIdis always available and validated - Return appropriate error messages for unauthorized access attempts
- Consider logging access attempts to private consortia for security auditing
Acceptance Criteria
- Private consortia are only visible to owner, members, and admins
- Public consortia remain visible to all users
- Backend properly filters consortia based on privacy flag and user access
- Only leader can modify privacy setting
- When a consortium is made private, existing members retain access
- Users can create consortia with privacy settings
- Leader can edit privacy setting in consortium edit form
- All existing functionality continues to work for public consortia
- No breaking changes to existing API contracts (backward compatible)
Related Files
centralApi/src/database/models/Consortium.tscentralApi/src/graphql/typeDefs.graphqlcentralApi/src/graphql/resolvers.tscentralApi/src/graphql/generated/graphql.tsdesktopApp/reactApp/src/apis/centralApi/getConsortiumList.tsxdesktopApp/reactApp/src/apis/centralApi/getConsortiumDetails.tsxdesktopApp/reactApp/src/apis/centralApi/generated/graphql.ts
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels