Skip to content

WIP: User LDAP setter/getter methods for each config key#22

Closed
danil-topchiy wants to merge 2 commits intoEnterpriseyIntranet:masterfrom
danil-topchiy:user_ldap_refactor
Closed

WIP: User LDAP setter/getter methods for each config key#22
danil-topchiy wants to merge 2 commits intoEnterpriseyIntranet:masterfrom
danil-topchiy:user_ldap_refactor

Conversation

@danil-topchiy
Copy link

@danil-topchiy danil-topchiy commented Jan 27, 2019

As was discussed in #17

Copy link

@matejak matejak left a comment

Choose a reason for hiding this comment

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

Hello, thank you for addressing this! As I mention in the comment, I am not in favor of the exec way how to do this, but the other aspect of the solution you chose are great.

NextCloud.py Outdated

# create and add getter method
getter_name = "get_ldap_{}".format(key_name)
exec(
Copy link

@matejak matejak Jan 28, 2019

Choose a reason for hiding this comment

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

I don't like the exec here. I propose to do something else - you probably want to have a generic (maybe private) getter/setter that accepts the key as well, and you somehow just stuff the class/instance with wrappers that behave in a way that e.g. get_ldap_user_filter calls _get_ldap_property("user_filter").
You can use lambda to do the wrap, and you can even add those methods to the class itself (i.e. in the module-level code, not in the class constructor). However, watch out for closures when working with lambda.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for suggestions! Yes, using exec was bad idea. I refactored it: moved to module level and attaching methods to class and rewritten exec to functions. Although, I used def functions, not lambdas for explicity, is that ok ?
Also, I left get_ldap_config, edit_ldap_config not private and open for user in case if somebody will need to see full config view and make bulk update of keys. As well use them in config keys setters/getters.

@scrutinizer-notifier
Copy link

The inspection completed: 3 updated code elements

@danil-topchiy
Copy link
Author

Rebased in #25

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