Skip to content

Fixed bug with empty groups#36

Open
osan0926 wants to merge 1 commit intoFrendsPlatform:mainfrom
osan0926:emptyGroupSupport
Open

Fixed bug with empty groups#36
osan0926 wants to merge 1 commit intoFrendsPlatform:mainfrom
osan0926:emptyGroupSupport

Conversation

@osan0926
Copy link

@osan0926 osan0926 commented Jul 2, 2025

Fixed issue where the member attribute could not be found if the LDAP group was empty, leading to a System.Collections.Generic.KeyNotFoundException. This issue was mentioned by my colleague in this issue.

The fix introduces a conditional check into the UserExistsInGroup function to make sure the "member" attribute is not null before checking if a user is already part of the LDAP group. If the attribute is null, the function assumes no user exists, returns false and the task continues as normal.

This PR was created on behalf of the Municipality of Skövde Kommun. If you have any questions, please contact me at oscar.j.andersson@skovde.se

Summary by CodeRabbit

  • Bug Fixes
    • Improved stability when checking group membership by preventing errors if a group has no members.

Fixed issue where the member attribute could not be found if the group was empty.
@coderabbitai
Copy link

coderabbitai bot commented Jul 2, 2025

Walkthrough

A null check for the "member" attribute was added in the UserExistsInGroup method to prevent errors when the group has no members. Minor whitespace adjustments were also made in the AddUserToGroups method, but no changes to public interfaces or exported entities occurred.

Changes

File(s) Change Summary
Frends.LDAP.AddUserToGroups/AddUserToGroups.cs Added null check for "member" attribute in UserExistsInGroup; minor whitespace adjustments.

Poem

In the warren of code, a fix hops through,
No more nulls to trip up the crew.
Groups with no members? Now handled with care,
The method returns false, no errors to spare.
Whitespace tidied, logic intact,
Another bug gone—code rabbits react! 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 96bee50 and 089d655.

📒 Files selected for processing (1)
  • Frends.LDAP.AddUserToGroups/Frends.LDAP.AddUserToGroups/AddUserToGroups.cs (3 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
`Frends.*/Frends.*/*.cs`: Ensure every public method and class: - Has ...

Frends.*/Frends.*/*.cs: Ensure every public method and class:

  • Has and XML comments
  • If the documentation is very long then it can also use element
  • Follows Microsoft C# code conventions
  • Uses semantic task result documentation (e.g., Success, Error, Data)

⚙️ Source: CodeRabbit Configuration File

List of files the instruction was applied to:

  • Frends.LDAP.AddUserToGroups/Frends.LDAP.AddUserToGroups/AddUserToGroups.cs
`Frends.*/Frends.*/*.cs`: Validate all task result classes include: - Success (b...

Frends.*/Frends.*/*.cs: Validate all task result classes include:

  • Success (bool)
  • Task-specific return value (e.g. Data, FilePaths)
  • Error object with Message and AdditionalInfo
  • Ensure result structure is flat, simple, and avoids 3rd-party types.
    • Use dynamic or JToken only when the structure is unknown.

⚙️ Source: CodeRabbit Configuration File

List of files the instruction was applied to:

  • Frends.LDAP.AddUserToGroups/Frends.LDAP.AddUserToGroups/AddUserToGroups.cs
`Frends.*/**/*.cs`: Code must follow Microsoft C# coding standards, including: -...

Frends.*/**/*.cs: Code must follow Microsoft C# coding standards, including:

  • PascalCase for public members and task parameters
  • Proper naming for abbreviations (Csv, Url, Api)
  • Use of var only when type is obvious
  • Clean structure and no unused code

⚙️ Source: CodeRabbit Configuration File

List of files the instruction was applied to:

  • Frends.LDAP.AddUserToGroups/Frends.LDAP.AddUserToGroups/AddUserToGroups.cs
🔇 Additional comments (2)
Frends.LDAP.AddUserToGroups/Frends.LDAP.AddUserToGroups/AddUserToGroups.cs (2)

46-46: Minor formatting change - acceptable.

The added whitespace improves code readability.


65-65: Minor formatting change - acceptable.

The added whitespace improves code separation between methods.

Comment on lines +93 to 101
//Check that the attribute exists, otherwise an error will be thrown if the group is empty.
if(memberAttr != null)
{
var currentMembers = memberAttr.StringValueArray;
if (currentMembers.Where(e => e == userDn).Any())
return true;
}
return false;
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix the logical flow and code formatting issues.

While the null check addresses the core issue, there are several problems with the current implementation:

  1. Logic error: The return false; on line 100 exits the method immediately when an entry lacks a member attribute, preventing the method from checking other entries that might contain the user.

  2. Code formatting: The formatting doesn't follow Microsoft C# conventions - missing space after if and inconsistent brace placement.

  3. Comment style: The comment should follow standard conventions.

Apply this diff to fix the logical flow and formatting:

-                //Check that the attribute exists, otherwise an error will be thrown if the group is empty.
-                if(memberAttr != null)
-                {
-                    var currentMembers = memberAttr.StringValueArray;
-                    if (currentMembers.Where(e => e == userDn).Any())
-                return true;
-                }
-                return false;
+                // Check that the attribute exists, otherwise an error will be thrown if the group is empty.
+                if (memberAttr != null)
+                {
+                    var currentMembers = memberAttr.StringValueArray;
+                    if (currentMembers.Where(e => e == userDn).Any())
+                        return true;
+                }

The method should continue checking other entries if the current entry doesn't have a member attribute, rather than returning false immediately. The final return false; on line 104 will handle the case where the user is not found in any entry.

🤖 Prompt for AI Agents
In Frends.LDAP.AddUserToGroups/AddUserToGroups.cs around lines 93 to 101, fix
the logical flow by removing the immediate return false inside the loop when
memberAttr is null, allowing the method to continue checking other entries.
Adjust the code formatting to include a space after if and use consistent brace
placement according to Microsoft C# conventions. Update the comment to follow
standard style guidelines. Ensure the final return false is only after all
entries have been checked.

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