-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
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
models: Add render_format_string
field in RealmFilter
model.
#18914
base: main
Are you sure you want to change the base?
Conversation
@@ -953,6 +953,16 @@ class RealmFilter(models.Model): | |||
realm: Realm = models.ForeignKey(Realm, on_delete=CASCADE) | |||
pattern: str = models.TextField() | |||
url_format_string: str = models.TextField(validators=[URLValidator(), filter_format_validator]) | |||
render_format_string: str = models.TextField( | |||
default="", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I chose the default=""
and not null=True
as this may create some issue when the linkifier data will be used for comparison purpose (@ frontend), or in other cases, this may cause some unexpected problems like errors are thrown (@ frontend).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain the reasoning more, perhaps with an example problem you'd expect with null=True
?
Oh, is the point just that "" is a simpler value to set in a web form?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably need to put some unnecessary check at (when null=True
is used):
zulip/static/js/settings_linkifiers.js
Lines 103 to 104 in 4cff56a
item.pattern.toLowerCase().includes(value) || item.url_format.toLowerCase().includes(value) zulip/static/js/settings_linkifiers.js
Line 30 in 4cff56a
if (x > y) {
Hence I found that empty strings would be much better rather than providing unnecessary checks.
076b833
to
1308749
Compare
I merged the first two commits as the series ending with 4cff56a. |
# Report patterns missing in linkifier pattern. | ||
# | ||
# NOTE: We do not need to report the missing patterns in Render format string | ||
# as some users may or may not want to render every patterns found in linkifer pattern. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think most correctly, we should be changing the existing check to allow fields in the linkifier pattern that are not present in the linkifier but are present in render_format_string, i.e. be merging the two found_group_set
values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To do that we need to change the current error message:
Lines 985 to 987 in 8cd9fc7
raise ValidationError( | |
_("Group %(name)r in URL format string is not present in linkifier pattern."), | |
params={"name": name}, |
to:
Group %(name)r is not present in linkifier pattern.
since in such case we can't tell that the missing name
in linkifier pattern was present in url_format_string
or render_format_string
.
blank=True, | ||
validators=[ | ||
RegexValidator( | ||
regex=r"^([\.\/:\w#?=&;!@~-]*%\(([\w-]+)\)s)*[/\w#?=&;~@-]*$", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How did you select this validator string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since render_format_string
and url_format_string
will have the same format: foo/%(id)s/bar
so I picked the validator string used by url_format_string
:
Line 941 in 8cd9fc7
regex = re.compile(r"^([\.\/:a-zA-Z0-9#_?=&;~-]+%\(([a-zA-Z0-9_-]+)\)s)+[/a-zA-Z0-9#_?=&;~-]*$") |
A slight difference is that I've added !
and @
as the allowed characters. Since GitLab users may want to use it as !1234
and for commits as zulip/zulip@abcdefg
.
And since it is not necessary to use all the detected groups in the linkifier render_format_string
, I've used the *
qualifier rather than the +
qualifier.
1308749
to
3fc91d5
Compare
This is done as a prep commit for the upcoming new changes where this regex will also be used to find matches in `render_format_string`.
Using this field, users can set the rendered text of the linkifier pattern. This is an optional field, if not provided, detected the pattern will be used to set the rendered text. Note: I've not added/removed validation checks in the `pattern` field, so still, this cannot be used as `Link Shortener` (Related issue: zulip#17971). In the future commits, I'll do the same.
If `render_format_string` is present, it will be used to set the rendered text of the detected linkifier pattern in messages and topic names.
… to create linkifer. This will help the users to add the optional field `render_format_string` to the realm linkifiers. New tests are added for the same.
… to update linkifier. This will help the users to update the optional field `render_format_string` of the realm linkifiers. New tests are added for the same.
Added `render_format` as an `optional_keys` in `realm_linkifier_type`. New tests are added and zulip.yaml is updated as well.
3fc91d5
to
cea25f6
Compare
I've extracted @timabbott, please review. |
…ener. This commit only modifies the regex. In the next commit, linkifier priority number will be increased in Markdown processing so that we can use it as link shortener.
…rtener. In this commit, linkifier priority number is increased in Markdown processing so that we can use it as link shortener. This increment in priority number is required to process any link that matches the linkifier pattern before it is processed by `AutoLink`. Fixes zulip#17971.
These new commits: b1d3953, 928fb38 may require some discussion as:
@timabbott, waiting to hear from you before making any new changes for the above two cases. |
Heads up @akshatdalton, we just merged some commits that conflict with the changes your made in this pull request! You can review this repository's recent commits to see where the conflicts occur. Please rebase your feature branch against the |
4ec3636
to
88b200c
Compare
Added some minor fixes following them I've added new changes to add the
render_format_string
field in theRealmFilter
model. Then new changes are done in a series of commits; please do tell me if this needs some changes in the commit structure.The new changes will help the user set the rendered text of the detected linkifier pattern if
render_format_string
is provided; else, the detected pattern text will be used to set the rendered text (like we do now). Please note that this still can't perform the Link Shortener task (Related issue: #17971) as I've not modified the linkifier pattern regex, which is used for validation purpose. I'll do so as part of my next commit, which will help to close the issue #17971.