Modify

Opened 10 years ago

Closed 10 years ago

Last modified 5 years ago

#11894 closed enhancement (worksforme)

Make (clear that) username policy (is) configurable

Reported by: anonymous Owned by: Steffen Hoffmann
Priority: normal Component: AccountManagerPlugin
Severity: normal Keywords:
Cc: Trac Release:

Description (last modified by Ryan J Ollos)

It seems it is hard coded the username policy. I think it would be nice if it could be configured in the trac.ini file.

Example, I don't want the minimum of 5 chars long user names. I found the code, but I don't know python. register.py:

username_regexp = Option('account-manager', 'username_regexp',
        r'(?i)^[A-Z0-9.\-_]{5,}$',
        doc="A validation regular expression describing new usernames.")

couldn't it be loaded from the ini file like:

 def validate_registration(self, req):
        acctmgr = AccountManager(self.env)

        """ New """
        regexp = req.args.get('username.regexp', '');
        if regexp=""
                username_regexp = Option('account-manager', 'username_regexp',
                        r'(?i)^[A-Z0-9.\-_]{5,}$',
                        doc="A validation regular expression describing new usernames.")
        else:
                username_regexp = Option('account-manager', 'username_regexp',
                        regexp, """ Notice I dont know how to handle the r'...' """
                        doc="A validation regular expression describing new usernames.")

        """ End new

        username = acctmgr.handle_username_casing(
            req.args.get('username', '').strip())
        if self.username_regexp != "" and \
                not re.match(self.username_regexp.strip(), username):
            raise RegistrationError(N_(
                "Username %s doesn't match local naming policy."),
                tag.b(username)
            )

...

Of course cleaning up constants and so on.

Attachments (0)

Change History (16)

comment:1 Changed 10 years ago by luis.robledano.iwes

Actually I (am the same as the reporter, I just registered afterwards) changed manually the could and rebuilt and update the plugin... but still get the error

"Username abc doesn't match local naming policy."

comment:2 Changed 10 years ago by Ryan J Ollos

Description: modified (diff)

comment:3 in reply to:  description Changed 10 years ago by Ryan J Ollos

Resolution: worksforme
Status: newclosed

Replying to anonymous:

Example, I don't want the minimum of 5 chars long user names. I found the code, but I don't know python. register.py:

username_regexp = Option('account-manager', 'username_regexp',
        r'(?i)^[A-Z0-9.\-_]{5,}$',
        doc="A validation regular expression describing new usernames.")

That's an Option, so it can be set from trac.ini. Look on the TracIni page of your installation for more details. AccountManagerPlugin must be enabled to see its documentation on TracIni and we are using it on this site, so you can just look at TracIni#account-manager-section.

Add the following to trac.ini:

[account-manager]
username_regexp = (?i)^[A-Z0-9.\-_]{5,}$

and modify the value on the right-hand side to meet your needs.

comment:4 Changed 10 years ago by luis.robledano.iwes

Thanks rjollos. I actually tried something like that and didn't work out... I might have done it wrong. I will check it out again. BTW, shouldn't the tickets be closed by the one who opened it? (as best-practice I mean).

comment:5 Changed 10 years ago by luis.robledano.iwes

confirmed! it did work! I think I just inserted the "r'" in the past... As a hint, I never saw the documentation you are referencing to, so it is my fault. However I did search (google) and never find it :(

I advise adding more info to the description: "A validation regular expression describing new usernames." (such as description for allow_delete_account "Allow users to delete their own account.")

"Allows the definition of constraints of allowed user names. A validation regular expression describing new usernames." (or something like the first sentence, which defines the purpose: why someone would want to use this parameter beyond how internally it's done). That would help people find. Notice that in the beginning of a search !nobody -beyond insiders- knows that it is through a regular expression or even that it is a parameter in the ini file.

Thanks again for the help. :D

PS. So, IMO, now it would be the time to close the ticket :) solution confirmed by the reporter. :D

comment:6 Changed 10 years ago by Ryan J Ollos

Thanks for the suggestions about improving the documentation for username_regexp. I added that to my todo list and will try to make sure it gets done before the next major release.

comment:7 Changed 10 years ago by luis.robledano.iwes

Thank YOU!

comment:8 in reply to:  description Changed 10 years ago by Steffen Hoffmann

Sorry for responding a bit later, but Ryan already was pretty much helpful - thanks.

Replying to anonymous:

Example, I don't want the minimum of 5 chars long user names.

I'm pretty much sure there are no sensible usernames with 1 or 2 characters. If it doesn't apply to you, this is fine. It is not Python, just a bit of regular expression foo, that many site on the internet offer information upon, but you may even guess to alter the number in brackets to another more suitable value, i.e. {5,} --> {3,}. And super-long names won't be great either, so you could even like an upper limit as well: {3,50}.

comment:9 in reply to:  4 ; Changed 10 years ago by Steffen Hoffmann

Replying to luis.robledano.iwes:

Thanks rjollos. I actually tried something like that and didn't work out... I might have done it wrong. I will check it out again. BTW, shouldn't the tickets be closed by the one who opened it? (as best-practice I mean).

It depends, but because this is a development ticket system, the code author or developer in charge shall rule, no? Personally I prefer user feed-back, but tend to close tickets after confirmation but rarely before availability of the changes in a stable release.

IMHO it's largely a matter of taste, because there are a couple of pros and cons for a great variety of approaches.

comment:10 in reply to:  5 ; Changed 10 years ago by Steffen Hoffmann

Replying to luis.robledano.iwes:

However I did search (google) and never find it :(

Lesson to learn: Trac is so much self-documenting, that it pays of much more to search for it in TracWiki before trying anything else.

I advise adding more info to the description: "A validation regular expression describing new usernames." "Allows the definition of constraints of allowed user names. A validation regular expression describing new usernames." (or something like the first sentence, which defines the purpose: why someone would want to use this parameter beyond how internally it's done).

I see. My take:

A validation regular expression describing new usernames. Define constraints for allowed user names corresponding to local naming policy. - Here you even have the hint keywords 'local naming policy'. Initially I planned to even go for an optional configurable link to a (TracWiki) page describing that policy.

That would help people find. Notice that in the beginning of a search !nobody -beyond insiders- knows that it is through a regular expression or even that it is a parameter in the ini file.

Configuration of Trac is largely done through trac.ini or a bit more point-n-click-friendly through the Trac web admin interface. But by the time you ask questions like the one you did, your bound to learn about TracIni, one way or another.

For what its worth MailingLists are the preferred way for beginners anyway. A great red box above our new ticket form tells just that, but I know, such disclaimers are never clear enough. :-)

comment:11 in reply to:  9 Changed 10 years ago by anonymous

Replying to hasienda:

It depends, but because this is a development ticket system, the code author or developer in charge shall rule, no?

IMHO, no. But that would be for another ticket/discussion ;)

comment:12 in reply to:  10 Changed 10 years ago by luis.robledano.iwes

I see. My take:

A validation regular expression describing new usernames. Define constraints for allowed user names corresponding to local naming policy. - Here you even have the hint keywords 'local naming policy'. Initially I planned to even go for an optional configurable link to a (TracWiki) page describing that policy.

For me perfect. You have a very good point there, use same text as in the error message! :D

PS. It is still luis here, this and previous comment. I´m having problems with login...

comment:13 Changed 10 years ago by Steffen Hoffmann

Summary: User Name policy configurable?Make (clear that) username policy (is) configurable

comment:14 Changed 10 years ago by Steffen Hoffmann

In 14078:

AccountManagerPlugin: Improve doc-strings for regular expression configuration options, refs #11894.

Another description - for email addresses - is extended in the same notion.
Thanks to Luis for suggesting this embedded documentation improvement.

comment:15 Changed 6 years ago by adtc

It would be great if the admin can configure a custom message describing the policy (I'm assuming they can configure the policy too). For a visitor who wants to register, just saying "doesn't match local naming policy" is so unhelpful! At the very least, it should say something like: should be at least 5 characters, not have spaces and only contain these: a-z A-Z 0-9 . - _

comment:16 in reply to:  15 Changed 6 years ago by Ryan J Ollos

Replying to adtc:

It would be great if the admin can configure a custom message describing the policy (I'm assuming they can configure the policy too).

See #12199.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Steffen Hoffmann.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.