Skip to content

CV2-6749: Treat inactive workspaces like deleted ones in permission checks - #2464

Merged
melsawy merged 13 commits into
developfrom
CV2-6749-treat-inactive-workspaces-like-deleted-ones-in-permission-checks
Nov 13, 2026
Merged

melsawy merged 13 commits into
developfrom
CV2-6749-treat-inactive-workspaces-like-deleted-ones-in-permission-checks

Conversation

@melsawy

@melsawy melsawy commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Description

Verify that the team is active before checking permissions.

References: CV2-6749

How to test?

  • Re-run tests
  • Verify permissions via curl

Checklist

  • I have performed a self-review of my code and ensured that it is safe and runnable, that code coverage has not decreased, and that there are no new Code Climate issues. I have also followed Meedan's internal coding guidelines.

@melsawy melsawy changed the title CV2-6749: verify permissions against inactive workspaces CV2-6749: Treat inactive workspaces like deleted ones in permission checks Oct 28, 2026
@melsawy
melsawy marked this pull request as ready for review October 29, 2026 06:40
@melsawy
melsawy requested a review from caiosba October 29, 2026 06:40

@caiosba caiosba left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @melsawy, the approach looks right. Requesting changes:

  1. @context_team = nil in Ability can raise via Team's after_find
  2. API key auth should reject keys of inactive teams
  3. cached_teams and current_team still include inactive teams
  4. Would be good to add a few basic tests

@melsawy
melsawy requested a review from caiosba November 3, 2026 10:54

@caiosba caiosba left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, the Ability crash and current_team are fixed. Still requesting changes:

  1. Regarding api_key_perms: the conditional cannot blocks stop applying when the team is inactive, so broader can rules win (e.g. can :create, User)... maybe keep them unconditional and add cannot :manage, :all if @api_key.team.inactive? or reject the key at auth?
  2. cached_teams is only filtered when a membership is added... existing members of a workspace deactivated later keep it, members added while inactive lose access after reactivation... Suggest filtering on read, or updating on activate/deactivate
  3. Would be good to add some tests for User#role/load_context_team with an inactive team, a user in both an active and an inactive workspace, and bulk mutations

Comment thread app/models/ability.rb Resolved
Comment thread app/models/team_user.rb Resolved
Comment thread test/models/ability_test.rb Resolved
@melsawy

melsawy commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, the Ability crash and current_team are fixed. Still requesting changes:

  1. Regarding api_key_perms: the conditional cannot blocks stop applying when the team is inactive, so broader can rules win (e.g. can :create, User)... maybe keep them unconditional and add cannot :manage, :all if @api_key.team.inactive? or reject the key at auth?
  2. cached_teams is only filtered when a membership is added... existing members of a workspace deactivated later keep it, members added while inactive lose access after reactivation... Suggest filtering on read, or updating on activate/deactivate
  3. Would be good to add some tests for User#role/load_context_team with an inactive team, a user in both an active and an inactive workspace, and bulk mutations

Done

@vasconsaurus vasconsaurus left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think there are still some issues, could you please confirm:

  • I think Caio's second point still breaks, I think team_user.rb:67-69 deletes inactive teams from the stored list, and skips adding anyone to an inactive team, so members lose access after reactivation.
  • I think bot_permissions ignores inactive (ability.rb:177-196), so an admin of an inactive team can still update or destroy its bots and bot installations.
  • If we shouldn't read anything from an inactive team, we probably should do something about check_basic_abilities.rb:80-88: it checks whether the team is private but not whether it's inactive, and creators can still read their own items.

I added some tests temporarily and they all failed:

  • test/models/team_user_test.rb (at the end of the file)
    • test "should restore access for member added while team was inactive after reactivation" do
    • test "should keep inactive team in cached teams when another membership changes" do
  • test/models/ability_test.rb
    • test "should not read items of public inactive team" do (after "read ability for user in private team with member status")
    • test "should not read own items in inactive team" do (same place)
    • test "admin of inactive team should not manage its bots or bot installations" do (after "permissions for team bot installation")

If you want, I can push my tests to this branch.

@melsawy

melsawy commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

If you want, I can push my tests to this branch.

Yes @vasconsaurus please push your tests

@melsawy
melsawy requested a review from vasconsaurus November 13, 2026 06:21
@melsawy

melsawy commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, @vasconsaurus , for adding the unit tests. They were very helpful.
I also added the cannot :manage, :all permission for inactive teams.

@vasconsaurus

Copy link
Copy Markdown
Contributor

@melsawy, glad it helped! Will re-review today

is_owner_of_bot_team ignored team status, so inactive-team admins could still manage its bots, installations and API keys.

@vasconsaurus vasconsaurus left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@melsawy, I found what I think was a last small gap, I added a couple of tests to confirm, and updated the is_owner_of_bot_team check to filter out inactive teams. Please do rollback if you think this doesn't make sense.

Otherwise everything else looks good to me

@melsawy
melsawy merged commit f51d760 into develop Nov 13, 2026
10 checks passed
@melsawy
melsawy deleted the CV2-6749-treat-inactive-workspaces-like-deleted-ones-in-permission-checks branch November 13, 2026 21:41
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.

3 participants