Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PM-11162] Assign to Collection Permission Update #4844

Open
wants to merge 29 commits into
base: main
Choose a base branch
from

Conversation

Jingo88
Copy link
Contributor

@Jingo88 Jingo88 commented Oct 2, 2024

🎟️ Tracking

PM-11162

📔 Objective

Users with Can Edit Except Password will not be allowed to assign collections to ciphers.

Updates made to CipherDetails_ReadByIdUserId.sql to get accurate ViewPassword value when user assigns/unassigns collections (This addresses bug PM-14046)

NOTE: EntityFramework update being looked at later on.

📸 Screenshots

⏰ Reminders before review

  • Contributor guidelines followed
  • All formatters and local linters executed and passed
  • Written new unit and / or integration tests where applicable
  • Protected functional changes with optionality (feature flags)
  • Used internationalization (i18n) for all UI strings
  • CI builds passed
  • Communicated to DevOps any deployment requirements
  • Updated any necessary documentation (Confluence, contributing docs) or informed the documentation team

🦮 Reviewer guidelines

  • 👍 (:+1:) or similar for great changes
  • 📝 (:memo:) or ℹ️ (:information_source:) for notes or general info
  • ❓ (:question:) for questions
  • 🤔 (:thinking:) or 💭 (:thought_balloon:) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion
  • 🎨 (:art:) for suggestions / improvements
  • ❌ (:x:) or ⚠️ (:warning:) for more significant problems or concerns needing attention
  • 🌱 (:seedling:) or ♻️ (:recycle:) for future improvements or indications of technical debt
  • ⛏ (:pick:) for minor or nitpick changes

@Jingo88 Jingo88 requested a review from a team as a code owner October 2, 2024 20:27
Copy link
Contributor

github-actions bot commented Oct 2, 2024

Logo
Checkmarx One – Scan Summary & Details026ddcbe-9a42-49ff-bd99-37e0b8459865

Fixed Issues

Severity Issue Source File / Package
MEDIUM CSRF /src/Billing/Controllers/RecoveryController.cs: 38
MEDIUM CSRF /src/Billing/Controllers/StripeController.cs: 164
MEDIUM CSRF /src/Api/Auth/Controllers/AccountsController.cs: 470
MEDIUM CSRF /src/Api/Auth/Controllers/AccountsController.cs: 845
LOW Log_Forging /src/Api/Billing/Controllers/OrganizationBillingController.cs: 256
LOW Log_Forging /src/Api/Billing/Controllers/OrganizationBillingController.cs: 256
LOW Log_Forging /src/Api/Billing/Controllers/OrganizationBillingController.cs: 256
LOW Log_Forging /src/Api/Billing/Controllers/ProviderBillingController.cs: 104
LOW Log_Forging /src/Api/Billing/Controllers/ProviderBillingController.cs: 104
LOW Log_Forging /src/Api/Billing/Controllers/ProviderBillingController.cs: 104
LOW Log_Forging /src/Api/Auth/Controllers/EmergencyAccessController.cs: 159

Copy link
Member

@shane-melton shane-melton left a comment

Choose a reason for hiding this comment

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

Changes look good, but looks like we need to update CipherController tests.

@Jingo88 Jingo88 requested a review from shane-melton October 4, 2024 19:56
Copy link

codecov bot commented Oct 4, 2024

Codecov Report

Attention: Patch coverage is 3.22581% with 30 lines in your changes missing coverage. Please review.

Project coverage is 43.68%. Comparing base (03feb03) to head (effca46).
Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
src/Api/Vault/Controllers/CiphersController.cs 3.33% 29 Missing ⚠️
...ture.Dapper/Vault/Repositories/CipherRepository.cs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4844      +/-   ##
==========================================
- Coverage   43.69%   43.68%   -0.02%     
==========================================
  Files        1469     1472       +3     
  Lines       67898    68022     +124     
  Branches     6156     6170      +14     
==========================================
+ Hits        29670    29713      +43     
- Misses      36934    37012      +78     
- Partials     1294     1297       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

shane-melton
shane-melton previously approved these changes Oct 7, 2024
Copy link
Member

@shane-melton shane-melton left a comment

Choose a reason for hiding this comment

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

Changes look good! Just two small nits on the formatting of the sproc and we'll want to update the migration script date.

[Reprompt],
[Key],
[OrganizationUseTotp]
, MAX ([Edit]) AS [Edit]
Copy link
Member

Choose a reason for hiding this comment

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

⛏️ Can we fix the formatting here so that the , comes at the end of each line (to match the rest)?

[Reprompt],
[Key],
[OrganizationUseTotp]

Copy link
Member

Choose a reason for hiding this comment

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

⛏️ Extra whitespace we can remove

Copy link
Member

Choose a reason for hiding this comment

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

🎨 We'll want to update the date in this migration script to todays date since we already have a few others on main with a more recent date.

@Jingo88 Jingo88 requested a review from shane-melton November 6, 2024 19:05
shane-melton
shane-melton previously approved these changes Nov 6, 2024
Copy link
Member

@shane-melton shane-melton left a comment

Choose a reason for hiding this comment

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

Thanks! Looks good to go!

rkac-bw
rkac-bw previously approved these changes Nov 7, 2024
Copy link
Contributor

@rkac-bw rkac-bw left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Member

@shane-melton shane-melton left a comment

Choose a reason for hiding this comment

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

I was looking at this again after I ran into something similar in my current work. I think we may need to tweak another sproc.

shane-melton
shane-melton previously approved these changes Dec 4, 2024
Copy link
Member

@shane-melton shane-melton left a comment

Choose a reason for hiding this comment

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

Looks good!

AND O.[Enabled] = 1
AND OU.[Status] = 2 -- Confirmed
AND (
CU.[ReadOnly] = 0
Copy link
Member

Choose a reason for hiding this comment

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

💭 We should ask QA to test a few scenarios where a cipher has both group and user assignments with mixed ReadOnly and HidePasswords permissions to be sure the users is still allowed to perform the action with the most permissive relationship.

I think this query will still work as expected for those scenarios, but its probably something we should confirm with some additional testing.

Copy link
Contributor

@rkac-bw rkac-bw Dec 10, 2024

Choose a reason for hiding this comment

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

Merge can be problematic with excessive locking, better just update or delete:

`CREATE OR ALTER PROCEDURE [dbo].[CollectionCipher_UpdateCollections]
@cipherid UNIQUEIDENTIFIER,
@userid UNIQUEIDENTIFIER,
@CollectionIds AS [dbo].[GuidIdArray] READONLY
AS
BEGIN
SET NOCOUNT ON

DECLARE @OrgId UNIQUEIDENTIFIER = (
    SELECT TOP 1
        [OrganizationId]
    FROM
        [dbo].[Cipher]
    WHERE
        [Id] = @CipherId
)

-- Common CTE for available collections
WITH [AvailableCollectionsCTE] AS(
    SELECT
        C.[Id]
    FROM
        [dbo].[Collection] C
    INNER JOIN
        [Organization] O ON O.[Id] = C.[OrganizationId]
    INNER JOIN
        [dbo].[OrganizationUser] OU ON OU.[OrganizationId] = O.[Id] AND OU.[UserId] = @UserId
    LEFT JOIN
        [dbo].[CollectionUser] CU ON CU.[CollectionId] = C.[Id] AND CU.[OrganizationUserId] = OU.[Id]
    LEFT JOIN
        [dbo].[GroupUser] GU ON CU.[CollectionId] IS NULL AND GU.[OrganizationUserId] = OU.[Id]
    LEFT JOIN
        [dbo].[Group] G ON G.[Id] = GU.[GroupId]
    LEFT JOIN
        [dbo].[CollectionGroup] CG ON CG.[CollectionId] = C.[Id] AND CG.[GroupId] = GU.[GroupId]
    WHERE
        O.[Id] = @OrgId
        AND O.[Enabled] = 1
        AND OU.[Status] = 2 -- Confirmed
        AND (
            CU.[ReadOnly] = 0
            OR CG.[ReadOnly] = 0
        ) AND (
            CU.[HidePasswords] = 0
            OR CG.[HidePasswords] = 0
        )
)
-- Insert new collection assignments
INSERT INTO [dbo].[CollectionCipher] (
    [CollectionId],
    [CipherId]
)
SELECT 
    [Id],
    @CipherId
FROM @CollectionIds
WHERE [Id] IN (SELECT [Id] FROM [AvailableCollectionsCTE])
AND NOT EXISTS (
    SELECT 1 
    FROM [dbo].[CollectionCipher]
    WHERE [CollectionId] = [@CollectionIds].[Id]
    AND [CipherId] = @CipherId
);

-- Delete removed collection assignments
DELETE CC
FROM [dbo].[CollectionCipher] CC
WHERE CC.[CipherId] = @CipherId
AND CC.[CollectionId] IN (SELECT [Id] FROM [AvailableCollectionsCTE])
AND CC.[CollectionId] NOT IN (SELECT [Id] FROM @CollectionIds);
IF @OrgId IS NOT NULL
BEGIN
    EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @OrgId
END

END
GO`

@Jingo88 Jingo88 requested review from shane-melton and rkac-bw and removed request for rkac-bw December 10, 2024 23:21
shane-melton
shane-melton previously approved these changes Dec 10, 2024
rkac-bw
rkac-bw previously approved these changes Dec 10, 2024
Copy link
Contributor

@rkac-bw rkac-bw left a comment

Choose a reason for hiding this comment

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

lgtm

@Jingo88 Jingo88 dismissed stale reviews from rkac-bw and shane-melton via ced2997 December 11, 2024 20:04
rkac-bw
rkac-bw previously approved these changes Dec 11, 2024
Copy link
Contributor

@rkac-bw rkac-bw left a comment

Choose a reason for hiding this comment

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

lgtm

shane-melton
shane-melton previously approved these changes Dec 11, 2024
@Jingo88 Jingo88 dismissed stale reviews from shane-melton and rkac-bw via c40ce6d December 23, 2024 22:04
@Jingo88
Copy link
Contributor Author

Jingo88 commented Jan 7, 2025

After speaking with product and design we have decided to move away from hiding Can Edit Except Passwords collections from the dropdown. The HidePasswords value is no longer needed.

Copy link
Contributor

@rkac-bw rkac-bw left a comment

Choose a reason for hiding this comment

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

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants