GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [apex] ApexCRUDViolation: Recognize User Mode in SOQL + DML · Issue #4146 · pmd/pmd

[apex] ApexCRUDViolation: Recognize User Mode in SOQL + DML #4146

New issue
Copy link
New issue
Copy link
Closed
#4244
Closed
[apex] ApexCRUDViolation: Recognize User Mode in SOQL + DML#4146
#4244
Copy link
Assignees
Tarush-Singh35
Labels
a:false-negativePMD doesn't flag a problematic piece of codean:enhancementAn improvement on existing features / rules
Milestone
6.53.0

Description

@rsoesemann
rsoesemann
opened on Oct 7, 2022
Issue body actions

Affects PMD Version:

Rule: ApexCRUDViolation

Description:
With the upcoming Winter '23 (API Version 56) Salesforce is going to add more native capabilities to enforce CRUD and FLS security in SOQL queries and DML statements as described here https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_enforce_usermode.htm.

Currently, the usage of such new features is ignored by PMD and marked as a CRUD Violation. Therefor the rule needs to be extended to recognize and handle them correctly.

Code Sample demonstrating the issue:

public class UserMode {
	public void coverAllCasesWithTest() {
                // SOQL Queries cases
                
                Contact c;
                // Should be flagged a critical issue
                c = [SELECT Name FROM Contact];
                // Should be ignored
		c = [SELECT Name FROM Contact WITH USER_MODE];
                // Should be at best a warning because it ignores CRUD but explicitly
		c = [SELECT Name FROM Contact WITH SYSTEM_MODE];

                // DML cases

                // Should be flagged a critical issue
               insert contact;

                // Should be ignored
               insert as user contact;

                // Should be at best a warning because it ignores CRUD but explicitly
		insert as system contact;

               // ...and for ALL other occurrences of System.AccessLevel
	}
}

This issue should cover all cases with the optional accessLevel parameter. See Dynamic SOQL.
Database.getQueryLocator methods
Search.query methods
Database DML methods (insert, update, upsert, merge, delete, undelete, and convertLead)
Includes the *Immediate and *Async methods, such as insertImmediate and deleteAsync.

This issuers should be easy to contribute as we can just look at how the related earlier enhancements were done: #2210

Reacted by Thomas Prouvot, Jéferson Chaves, Uriel Zilberberg and Hassan ALAMI

Activity

Next
  1. rsoesemann
    added
    a:false-negativePMD doesn't flag a problematic piece of code
    an:enhancementAn improvement on existing features / rules
    on Oct 7, 2022
  2. rsoesemann
    changed the title [-][apex] ApexCRUDViolation: Support SOQL and DML User Mode (GA in Winter '23)[/-] [+][apex] ApexCRUDViolation: Recognize User Mode in SOQL + DML[/+] on Oct 7, 2022
  3. Tarush-Singh35 commented on Oct 20, 2022

    @Tarush-Singh35
    Tarush-Singh35
    on Oct 20, 2022
    Contributor
    More actions

    @rsoesemann I would like to contribute to this issue can you assign this issue to me?

  4. adangel
    assigned
    Tarush-Singh35
    on Oct 20, 2022
  5. rsoesemann commented on Oct 21, 2022

    @rsoesemann
    rsoesemann
    on Oct 21, 2022
    MemberAuthor
    More actions

    @adangel was faster ;-)

    Welcome @Tarush-Singh35. Thanks for your willingness to contribute to this very relevant change request.
    Maybe you can join force with @rbklaassen from within Salesforce who also wanted to take this.

  6. Tarush-Singh35 commented on Oct 21, 2022

    @Tarush-Singh35
    Tarush-Singh35
    on Oct 21, 2022
    Contributor
    More actions

    yeah sure, I am getting started @rsoesemann we can work something out together. how can we connect @rbklaassen please let me know

  7. Tarush-Singh35 commented on Oct 24, 2022

    @Tarush-Singh35
    Tarush-Singh35
    on Oct 24, 2022
    Contributor
    More actions

    @rbklaassen I am getting started with the issue if you want to join do ping me.

    Thanks & Regards

    Reacted by Robert Sösemann
  8. rbklaassen commented on Oct 25, 2022

    @rbklaassen
    rbklaassen
    on Oct 25, 2022
    More actions

    Hi @Tarush-Singh35 , go ahead and start on this. I've been quite busy last week and preparing a go-live at customer this week, so I don't think I can help out this or next week. I'll check in after that!

  9. rbklaassen commented on Oct 25, 2022

    @rbklaassen
    rbklaassen
    on Oct 25, 2022
    More actions

    Also, how do you prefer to connect @Tarush-Singh35 ?

  10. Tarush-Singh35 commented on Oct 27, 2022

    @Tarush-Singh35
    Tarush-Singh35
    on Oct 27, 2022
    Contributor
    More actions

    @rbklaassen through slack would be great

  11. rbklaassen commented on Oct 31, 2022

    @rbklaassen
    rbklaassen
    on Oct 31, 2022
    More actions

    I'm on slack with [email protected] @Tarush-Singh35

  12. Tarush-Singh35 commented on Nov 1, 2022

    @Tarush-Singh35
    Tarush-Singh35
    on Nov 1, 2022
    Contributor
    More actions

    I'm on slack with [email protected] @Tarush-Singh35

    yeah will connect with you through slack

  13. rsoesemann commented on Nov 9, 2022

    @rsoesemann
    rsoesemann
    on Nov 9, 2022
    MemberAuthor
    More actions

    Any progress here,guys?

  14. rbklaassen commented on Nov 9, 2022

    @rbklaassen
    rbklaassen
    on Nov 9, 2022
    More actions

    Sorry, not yet. Have had COVID and a pretty busy schedule at customer.

  15. 3 remaining items

  16. rbklaassen commented on Nov 17, 2022

    @rbklaassen
    rbklaassen
    on Nov 17, 2022
    More actions

    Yes, I can do some work on this tomorrow. Do you want to collaborate tomorrow @Tarush-Singh35 ?

  17. Tarush-Singh35 commented on Nov 18, 2022

    @Tarush-Singh35
    Tarush-Singh35
    on Nov 18, 2022
    Contributor
    More actions

    Yeah @rbklaassen lets do this

  18. rbklaassen commented on Nov 18, 2022

    @rbklaassen
    rbklaassen
    on Nov 18, 2022
    More actions

    You need to connect with me through slack, I don't have enough details to connect to you @Tarush-Singh35

  19. Tarush-Singh35 commented on Nov 18, 2022

    @Tarush-Singh35
    Tarush-Singh35
    on Nov 18, 2022
    Contributor
    More actions

    You need to connect with me through slack, I don't have enough details to connect to you @Tarush-Singh35

    I will create a workspace and I will ask you to join it

  20. Tarush-Singh35 commented on Nov 19, 2022

    @Tarush-Singh35
    Tarush-Singh35
    on Nov 19, 2022
    Contributor
    More actions

    Added you @rbklaassen in Slack

    Reacted by Robert Sösemann
  21. rsoesemann commented on Nov 27, 2022

    @rsoesemann
    rsoesemann
    on Nov 27, 2022
    MemberAuthor
    More actions

    @rbklaassen and @Tarush-Singh35 any progress here? Or do you have any blockers I can help with?

  22. rbklaassen commented on Nov 28, 2022

    @rbklaassen
    rbklaassen
    on Nov 28, 2022
    More actions

    Hi @rsoesemann, today we had a meeting together and discussed the way forward. I came to the conclusion that I miss the Java knowledge to really work on the code, but I can be the support-desk for @Tarush-Singh35 as I know Apex very good. Also I will be able to test his solution when needed on a local project for instance.

    Reacted by Robert Sösemann
  23. Tarush-Singh35 commented on Nov 29, 2022

    @Tarush-Singh35
    Tarush-Singh35
    on Nov 29, 2022
    Contributor
    More actions

    Yeah I am formulating a solution I think so I will be able to make a pull request soon @rsoesemann and @rbklaassen are mentoring me in the apex

    Reacted by Robert Sösemann
  24. adangel
    linked a pull request that will close this issue[apex] ApexCRUDViolation: user mode and system mode with test cases added #4244on Dec 1, 2022
  25. Tarush-Singh35 commented on Dec 12, 2022

    @Tarush-Singh35
    Tarush-Singh35
    on Dec 12, 2022
    Contributor
    More actions

    @rsoesemann @rbklaassen i need help to understand the issue in my PR can you guys help me out

  26. rsoesemann commented on Dec 13, 2022

    @rsoesemann
    rsoesemann
    on Dec 13, 2022
    MemberAuthor
    More actions

    @Tarush-Singh35 I see two comments from @adangel which both make sense to me:

    1. Explicit SYSTEM Mode should not detect an Issue. It's ok bahviour
    2. Your code https://github.com/pmd/pmd/pull/4244/files#diff-32e0573a4d25115d3334e8f69cd4db0628e035eaa3831a90fc5f00a0e4e272f1R668 changes the logic also for other cases that relate to SECURITY ENFORCED. That's most probably the reason why existing test fail. Please run all tests before you submit a PR.
  27. adangel commented on Dec 16, 2022

    @adangel
    adangel
    on Dec 16, 2022
    Member
    More actions

    @rsoesemann Be aware, that the rule currently doesn't support query: see #2628 - so I didn't add this either.

    Also, the currently available Jorje library (last updated in Feb. 2022) doesn't support the syntax insert as user new Contact(LastName='foo'). It fails with the following exception:

    Caused by: apex.jorje.services.exception.ParseException: Syntax(error = UnexpectedToken(loc = (10, 16, 53, 55), token = 'as'))
    

    There doesn't seem to be a new version available yet: https://github.com/forcedotcom/salesforcedx-vscode/commits/develop/packages/salesforcedx-vscode-apex/out/apex-jorje-lsp.jar

    Apart from these two points, the PR #4244 fixes this issues.

  28. adangel
    added 2 commits that reference this issue on Dec 19, 2022

    [doc] Update release notes (#4146, #4244)

    03db706

    Merge pull request #4244 from Tarush-Singh35:#4146

    a76603b
  29. adangel
    closed this as completedin #4244on Dec 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @Tarush-Singh35
    Tarush-Singh35

Labels

a:false-negativePMD doesn't flag a problematic piece of codean:enhancementAn improvement on existing features / rules

Type

No type

Projects

No projects

    Milestone

    • 6.53.0

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.