-
Notifications
You must be signed in to change notification settings - Fork 9
Add override view option to see restricted records (#814) #650
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
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -201,6 +201,24 @@ sub _build__view_limit_extra | |
| return; | ||
| } | ||
|
|
||
| has _view_limit_override => ( | ||
| is => 'lazy', | ||
| ); | ||
|
|
||
| sub _build__view_limit_override | ||
| { my $self = shift; | ||
| my $override_id = $self->view_limit_override_id | ||
| or return; | ||
| my $view_override = $self->schema->resultset('View')->find($override_id); | ||
| return GADS::View->new( | ||
| id => $view_override->id, | ||
| schema => $self->schema, | ||
| layout => $self->layout, | ||
| instance_id => $self->layout->instance_id, | ||
| ) if $view_override->instance_id == $self->layout->instance_id | ||
| && $view_override->is_limit_override; | ||
| } | ||
|
|
||
| # Any extra view limits in addition to those applied per-user | ||
| has view_limit_extra_id => ( | ||
| is => 'lazy', | ||
|
|
@@ -212,6 +230,13 @@ sub _build_view_limit_extra_id | |
| $self->layout->default_view_limit_extra_id; | ||
| } | ||
|
|
||
| has view_limit_override_id => ( | ||
| is => 'ro', | ||
| isa => Maybe[Int], | ||
| # Allow empty string from query params | ||
| coerce => sub { $_[0] || undef }, | ||
| ); | ||
|
|
||
| has no_view_limits => ( | ||
| is => 'ro', | ||
| isa => Bool, | ||
|
|
@@ -221,18 +246,21 @@ sub _view_limits_search | |
| { my ($self, %options) = @_; | ||
| my @search; | ||
| return [] if $self->no_view_limits; | ||
| foreach my $view (@{$self->_view_limits}) | ||
| if (!$self->_view_limit_override) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this be an
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks Pawel, see previous comment on other PR :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have done, thank you. :) |
||
| { | ||
| if (my $filter = $view->filter) | ||
| foreach my $view (@{$self->_view_limits}) | ||
| { | ||
| my $decoded = $filter->as_hash; | ||
| if (keys %$decoded) | ||
| if (my $filter = $view->filter) | ||
| { | ||
| # Get the user search criteria. | ||
| # Ignore any permissions on this view, as otherwise an | ||
| # administrator-defined limited view of records may not take | ||
| # effect | ||
| push @search, $self->_search_construct($decoded, %options, ignore_perms => 1); | ||
| my $decoded = $filter->as_hash; | ||
| if (keys %$decoded) | ||
| { | ||
| # Get the user search criteria. | ||
| # Ignore any permissions on this view, as otherwise an | ||
| # administrator-defined limited view of records may not take | ||
| # effect | ||
| push @search, $self->_search_construct($decoded, %options, ignore_perms => 1); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -800,8 +828,12 @@ sub _build__search_all_fields | |
| ); | ||
|
|
||
| my @columns_can_view; | ||
| my $override = $self->_view_limit_override; | ||
| foreach my $col ($self->layout->all(user_can_read => 1)) | ||
| { | ||
| # If in override mode (showing all records) then do not allow a search | ||
| # on fields not contained in the override view | ||
| next if $override && !$override->has_column_id($col->id); | ||
| push @columns_can_view, $col->id; | ||
| push @columns_can_view, @{$col->curval_field_ids} | ||
| if ($col->type eq 'curval'); # Curval type needs all its columns from other layout | ||
|
|
@@ -1933,6 +1965,14 @@ sub _build_columns_render | |
| { my $self = shift; | ||
|
|
||
| my @cols = grep $_->user_can('read'), @{$self->columns_selected}; | ||
|
|
||
| # If an override view is selected, then need to only allow those columns to | ||
| # be viewed | ||
| if (my $override = $self->_view_limit_override) | ||
| { | ||
| @cols = grep $override->has_column_id($_->id), @cols; | ||
| } | ||
|
|
||
| if ($self->view && !@{$self->additional_filters}) | ||
| { | ||
| # If in the normal grouped view, then move the grouped columns first in | ||
|
|
@@ -2457,6 +2497,9 @@ sub rule_to_condition | |
| $column | ||
| or return; | ||
|
|
||
| my $override = $self->_view_limit_override; | ||
| return if $override && !$override->has_column_id($column->id); | ||
|
|
||
| if ($filter->{operator} eq 'changed_after') | ||
| { | ||
| my $value; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,7 @@ use base 'DBIx::Class::Schema'; | |
|
|
||
| __PACKAGE__->load_namespaces; | ||
|
|
||
| our $VERSION = 111; | ||
| our $VERSION = 112; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Multiple PRs are open which have schema updates - the versioning or order of merging would need to be considered when it comes to it. |
||
|
|
||
| our $IGNORE_PERMISSIONS; | ||
| our $IGNORE_PERMISSIONS_SEARCH; | ||
|
|
||
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.
Could this be:
if (my $override = param('view_limit_override'))?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 question - normally, yes. However, in this case a defined but false value means to unset it (https://github.com/ctrlo/GADS/pull/650/changes#diff-88d1585c56a6b278e6f81ddada4991a8d7278f46f85a89e2af503130aaa2a3c9R4)
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.
Makes sense, thanks for clarifying!