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

Issue with ignore_permission Flag in User Channel Management Hook #912

Closed
yacjne opened this issue May 10, 2024 · 4 comments · Fixed by #914
Closed

Issue with ignore_permission Flag in User Channel Management Hook #912

yacjne opened this issue May 10, 2024 · 4 comments · Fixed by #914
Labels
help wanted Extra attention is needed question Further information is requested

Comments

@yacjne
Copy link

yacjne commented May 10, 2024

Hello,

I am currently using a hook to add and remove users to/from channels. However, I've encountered an issue where the ignore_permission flag does not seem to be functioning as expected.

Could you please help me determine if there is a solution or workaround for this issue?

Thank you! 😊

@maige-app maige-app bot added help wanted Extra attention is needed question Further information is requested 🐞 bug Something isn't working labels May 10, 2024
@nikkothari22
Copy link
Member

Can you share your code for the same?

@nikkothari22 nikkothari22 removed the 🐞 bug Something isn't working label May 10, 2024
@yacjne
Copy link
Author

yacjne commented May 10, 2024

Context

For each ERPNext project, I automatically create a corresponding Raven Channel.

I have implemented a hook that listens to the Project update event. This hook is designed to manage the project's manager (User) association with the channel:

  • When a manager is added or changed in the project: The new manager is added to the corresponding Raven Channel.
  • When a manager is removed or changed from the project: The previous manager is removed from the channel.

Error message is : ""You don't have permission to remove members from this channel""

Code Snippets

def add_user_to_channel(channel, user, is_admin):
    frappe.get_doc(
        {
            "doctype": "Raven Channel Member", 
            "channel_id": channel, 
            "user_id": user,
            "is_admin": is_admin, 
            "last_visit": frappe.utils.now()
        }
    ).insert(ignore_permissions=True)

def remove_user_from_channel(user, channel):

    member_name = frappe.db.get_value('Raven Channel Member', {"user_id": user, "channel_id": channel}, 'name')
    if member_name:
        frappe.delete_doc('Raven Channel Member', member_name, ignore_permissions=True)

@nikkothari22
Copy link
Member

So the error is only thrown when trying to remove members right?

We have a check in our controller to see if the user (from the current session) is a member of the channel or not. We can potentially check for the ignore_permissions flag I believe.

@yacjne
Copy link
Author

yacjne commented May 10, 2024

There is also an error message when I try to add a new user.

NB: this only happens when the channel is private.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants