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
Add support for hidden attachment folders #3181
Conversation
# ### commands auto generated by Alembic ### | ||
op.add_column('folders', sa.Column('is_always_hidden_in_fe', sa.Boolean(), nullable=False, server_default='false'), | ||
schema='attachments') | ||
op.alter_column('folders', 'is_always_hidden_in_fe', server_default=None, schema='attachments') |
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.
Question: Is there something to be done to force the mutual exclusive setting of hide_in_fe and always_visible at the database level?
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic ### |
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.
You can remove the comments from upgrade
and downgrade
functions.
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.
Done
On a side note you don't have to create a separate commit for each fix/change which is a result of a comment. You could easily use either |
@@ -91,6 +91,14 @@ def __table_args__(cls): | |||
default=True | |||
) | |||
|
|||
#: If the folder is never shown in the frontend (even if you can access it) | |||
is_always_hidden_in_fe = db.Column( |
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 kind of dislike this name. It's not very clear without reading the comment, and also too verbose. IMO is_hidden
is a much better name for it. (also, we don't put an empty line between column definitions, and only one empty line between columns and relationships)
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.
Changed to is_hidden_in_fe .
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 the _in_fe
is not very useful either; that's something worth mentioning in the docstring on top of it (like it already does)
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.
Ok, using is_hidden now
indico/modules/attachments/util.py
Outdated
@@ -36,7 +36,7 @@ def get_attached_folders(linked_object, include_empty=True, include_hidden=True, | |||
folders = AttachmentFolder.get_for_linked_object(linked_object, preload_event=preload_event) | |||
|
|||
if not include_hidden: | |||
folders = [f for f in folders if f.can_view(session.user)] | |||
folders = [f for f in folders if (f.can_view(session.user) and not f.is_always_hidden_in_fe)] |
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.
This check can be done in can_view
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.
Done
indico/modules/attachments/forms.py
Outdated
description=_("By default, folders are always visible, even if a user cannot " | ||
"access them. You can disable this behavior here, hiding the folder " | ||
"for anyone who does not have permission to access it.")) | ||
is_always_hidden_in_fe = BooleanField(_("Always Hidden in Frontend"), | ||
[HiddenUnless('is_always_visible', value=False), ], |
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.
no need for the ,
at the end of the list - only single-element tuples need this.
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.
Done
52c3c32
to
b1422b0
Compare
indico/modules/attachments/forms.py
Outdated
description=_("By default, folders are always visible, even if a user cannot " | ||
"access them. You can disable this behavior here, hiding the folder " | ||
"for anyone who does not have permission to access it.")) | ||
is_hidden = BooleanField(_("Always Hidden in 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.
Hi,
I'm not that sure about the wording here. "Frontend" is not a term that a end user will necessarily understand.
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 discussed it briefly with @ThiefMaster, "Hide in event page" or similar could be an option.
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.
Done
@@ -64,6 +64,14 @@ | |||
title="{% trans %}The access to this folder is restricted, regardless of the protection scheme of | |||
the parent.{% endtrans %}"></i> | |||
{% endif %} | |||
{% if folder.is_hidden and management%} |
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.
missing space before %}
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.
Done
@@ -64,6 +64,14 @@ | |||
title="{% trans %}The access to this folder is restricted, regardless of the protection scheme of | |||
the parent.{% endtrans %}"></i> | |||
{% endif %} | |||
{% if folder.is_hidden and management%} | |||
<i class=" icon-eye-blocked" | |||
title="{% trans %}This folder is always hidden in the frontend.{% endtrans %}"></i> |
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.
not enough indentation (attrs should be aligned)
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.
Done
@@ -64,6 +64,14 @@ | |||
title="{% trans %}The access to this folder is restricted, regardless of the protection scheme of | |||
the parent.{% endtrans %}"></i> | |||
{% endif %} | |||
{% if folder.is_hidden and management%} | |||
<i class=" icon-eye-blocked" |
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.
there shouldn't be a space right after the opening quote
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.
Done
{% endif %} | ||
{% if folder.is_always_visible and management%} | ||
<i class=" icon-eye" | ||
title="{% trans %}This folder is always visible in the frontend.{% endtrans %}"></i> |
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.
Maybe this is a bit noisy since it's enabled by default? Explicitly showing the hidden flag makes sense but for this one I'm not sure if there's any benefit
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.
Well, it is only shown in managment views. And for symmetry ( all other flags one can set on a folder are indicated) I think it is helpful.
nullable=False, | ||
default=False | ||
) | ||
|
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.
one linebreak too much (there should be one empty line between this and the the relationships)
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.
Done
op.add_column('folders', sa.Column('is_hidden', sa.Boolean(), nullable=False, server_default='false'), | ||
schema='attachments') | ||
op.alter_column('folders', 'is_hidden', server_default=None, schema='attachments') | ||
op.create_check_constraint('ck_folders_exclusive_is_hidden_is_always_visible', 'folders', |
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.
Not sure if a DB constraint is really important here - there is no harm if both are set for some reason.
Anyway, if you want to keep it, make sure to add it to the model as well!
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.
Added constraint to model as well. I think this is needed, as both switches would get hidden if both flags are set in the db. Then the only way to recover would be to edit values in the database by hand.
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.
Good point indeed!
BTW: This should be validated on the Form level as well; i'll add a snippet to the comment once i'm in the office.
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.
def validate_is_always_visible(self, field):
if self.is_always_visible.data and self.is_hidden.data:
raise ValidationError('These two options cannot be used at the same time')
validate_is_hidden = validate_is_always_visible
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.
Done
700c81a
to
46bb658
Compare
@@ -50,7 +50,7 @@ def __auto_table_args(): | |||
return (db.CheckConstraint(default_inheriting, 'default_inheriting'), | |||
db.CheckConstraint('is_default = (title IS NULL)', 'default_or_title'), | |||
db.CheckConstraint('not (is_default and is_deleted)', 'default_not_deleted'), | |||
{'schema': 'attachments'}) |
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.
what happened to this?!
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.
Lost due to mis-reading braces..., readded
@@ -161,6 +167,8 @@ def can_view(self, user): | |||
""" | |||
if not self.object.can_access(user): | |||
return False | |||
if self.is_hidden: |
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.
do this before the access check; it's much cheaper!
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.
done
46bb658
to
d159639
Compare
d159639
to
b984a98
Compare
Bumped migrations |
b984a98
to
1106aad
Compare
'NOT (is_hidden AND is_always_visible)', schema='attachments') | ||
|
||
|
||
def validate_is_always_visible(self, field): |
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.
this doesn't belong in here
Not all uploaded files need to be shown in the materials listing on the event front page, sometimes it should only be used for links at some place in the event. Allow to always hide folders in the frontend indepently from the access rights. Fixes: indico#3180
If in management mode, indicate forced visibiliy/invisibility using an (striked-out) eye-icon.
1106aad
to
db3666f
Compare
Not all uploaded files need to be shown in the materials listing
on the event front page, sometimes it should only be used for links
at some place in the event. Allow to always hide folders in the
frontend indepently from the access rights.
Fixes: #3180