[Rt-commit] rt branch, 4.4/initial-custom-field, updated. rt-4.4.0rc2-26-g4c6e7f8
Shawn Moore
shawn at bestpractical.com
Wed Apr 20 16:07:22 EDT 2016
The branch, 4.4/initial-custom-field has been updated
via 4c6e7f8f31716274dffd5a486d761a9c4207bb9c (commit)
via c9c6f3534cf190e24824d1104ca6b934e878fbb0 (commit)
via fe7ca40bf2d5bae87b8473b796643467a4a62f58 (commit)
from dd4105f6a7b8d20f8ef57fc6489ea574c1501bfd (commit)
Summary of changes:
lib/RT/Action/CreateTickets.pm | 2 +-
lib/RT/CustomField.pm | 30 +++++++++++++++++++++++++-----
lib/RT/CustomFields.pm | 5 ++++-
lib/RT/Interface/Web.pm | 3 ++-
lib/RT/ObjectCustomFieldValue.pm | 2 +-
lib/RT/Record.pm | 9 +++++++--
lib/RT/Ticket.pm | 2 +-
lib/RT/Transaction.pm | 4 ++--
share/html/Elements/EditCustomFields | 1 +
9 files changed, 44 insertions(+), 14 deletions(-)
- Log -----------------------------------------------------------------
commit fe7ca40bf2d5bae87b8473b796643467a4a62f58
Author: Shawn M Moore <shawn at bestpractical.com>
Date: Wed Apr 20 18:51:26 2016 +0000
Add a $CF->CurrentUserCanSee method and switch to it
This is to prepare for allowing users to see custom fields for which they
do not have SeeCustomField, but for those who should still have access
thanks to SetInitialCustomField
diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
index f0b7521..29780f6 100644
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -611,7 +611,7 @@ sub Values {
my $cf_values = $class->new( $self->CurrentUser );
$cf_values->SetCustomFieldObject( $self );
# if the user has no rights, return an empty object
- if ( $self->id && $self->CurrentUserHasRight( 'SeeCustomField') ) {
+ if ( $self->id && $self->CurrentUserCanSee ) {
$cf_values->LimitToCustomField( $self->Id );
} else {
$cf_values->Limit( FIELD => 'id', VALUE => 0, SUBCLAUSE => 'acl' );
@@ -1050,7 +1050,7 @@ sub _Value {
return undef unless $self->id;
# we need to do the rights check
- unless ( $self->CurrentUserHasRight('SeeCustomField') ) {
+ unless ( $self->CurrentUserCanSee ) {
$RT::Logger->debug(
"Permission denied. User #". $self->CurrentUser->id
." has no SeeCustomField right on CF #". $self->id
@@ -1870,7 +1870,7 @@ sub ValuesForObject {
my $object = shift;
my $values = RT::ObjectCustomFieldValues->new($self->CurrentUser);
- unless ($self->id and $self->CurrentUserHasRight('SeeCustomField')) {
+ unless ($self->id and $self->CurrentUserCanSee) {
# Return an empty object if they have no rights to see
$values->Limit( FIELD => "id", VALUE => 0, SUBCLAUSE => "ACL" );
return ($values);
@@ -1882,6 +1882,16 @@ sub ValuesForObject {
return ($values);
}
+=head2 CurrentUserCanSee
+
+If the user has SeeCustomField they can see this custom field and its details.
++
+=cut
+
+sub CurrentUserCanSee {
+ my $self = shift;
+ return $self->CurrentUserHasRight('SeeCustomField');
+}
=head2 RegisterLookupType LOOKUPTYPE FRIENDLYNAME
@@ -1971,7 +1981,7 @@ sub _URLTemplate {
}
return ( 1, $self->loc('Updated') );
} else {
- unless ( $self->id && $self->CurrentUserHasRight('SeeCustomField') ) {
+ unless ( $self->id && $self->CurrentUserCanSee ) {
return (undef);
}
@@ -1993,7 +2003,7 @@ sub SetBasedOn {
$cf->Load( ref $value ? $value->id : $value );
return (0, "Permission Denied")
- unless $cf->id && $cf->CurrentUserHasRight('SeeCustomField');
+ unless $cf->id && $cf->CurrentUserCanSee;
# XXX: Remove this restriction once we support lists and cascaded selects
if ( $self->RenderType =~ /List/ ) {
diff --git a/lib/RT/CustomFields.pm b/lib/RT/CustomFields.pm
index e95dc7c..1a8054c 100644
--- a/lib/RT/CustomFields.pm
+++ b/lib/RT/CustomFields.pm
@@ -403,7 +403,8 @@ sub AddRecord {
my ($record) = @_;
$record->SetContextObject( $self->ContextObject );
- return unless $record->CurrentUserHasRight('SeeCustomField');
+ return unless $record->CurrentUserCanSee;
+
return $self->SUPER::AddRecord( $record );
}
diff --git a/lib/RT/ObjectCustomFieldValue.pm b/lib/RT/ObjectCustomFieldValue.pm
index 4579a38..4d0ab34 100644
--- a/lib/RT/ObjectCustomFieldValue.pm
+++ b/lib/RT/ObjectCustomFieldValue.pm
@@ -221,7 +221,7 @@ my $re_ip_serialized = qr/$re_ip_sunit(?:\.$re_ip_sunit){3}/;
sub Content {
my $self = shift;
- return undef unless $self->CustomFieldObj->CurrentUserHasRight('SeeCustomField');
+ return undef unless $self->CustomFieldObj->CurrentUserCanSee;
my $content = $self->_Value('Content');
if ( $self->CustomFieldObj->Type eq 'IPAddress'
diff --git a/lib/RT/Transaction.pm b/lib/RT/Transaction.pm
index b01e976..145ca34 100644
--- a/lib/RT/Transaction.pm
+++ b/lib/RT/Transaction.pm
@@ -1423,7 +1423,7 @@ sub CurrentUserCanSee {
my $cf = RT::CustomField->new( $self->CurrentUser );
$cf->SetContextObject( $self->Object );
$cf->Load( $cf_id );
- return 0 unless $cf->CurrentUserHasRight('SeeCustomField');
+ return 0 unless $cf->CurrentUserCanSee;
}
# Transactions that might have changed the ->Object's visibility to
commit c9c6f3534cf190e24824d1104ca6b934e878fbb0
Author: Shawn M Moore <shawn at bestpractical.com>
Date: Wed Apr 20 19:57:29 2016 +0000
Support passing the CF directly to CustomFieldValueIsEmpty
No reason to reload it if we already have the object
diff --git a/lib/RT/Action/CreateTickets.pm b/lib/RT/Action/CreateTickets.pm
index d19f152..824c1ab 100644
--- a/lib/RT/Action/CreateTickets.pm
+++ b/lib/RT/Action/CreateTickets.pm
@@ -1140,7 +1140,7 @@ sub UpdateCustomFields {
foreach my $value (@values) {
next if $ticket->CustomFieldValueIsEmpty(
- Field => $cf,
+ Field => $CustomFieldObj,
Value => $value,
);
my ( $val, $msg ) = $ticket->AddCustomFieldValue(
diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index ab13a43..266ba6e 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -3211,7 +3211,7 @@ sub _ProcessObjectCustomFieldUpdates {
if ( $arg eq 'AddValue' || $arg eq 'Value' ) {
foreach my $value (@values) {
next if $args{'Object'}->CustomFieldValueIsEmpty(
- Field => $cf->id,
+ Field => $cf,
Value => $value,
);
my ( $val, $msg ) = $args{'Object'}->AddCustomFieldValue(
diff --git a/lib/RT/Record.pm b/lib/RT/Record.pm
index de03b30..8947a91 100644
--- a/lib/RT/Record.pm
+++ b/lib/RT/Record.pm
@@ -2124,7 +2124,7 @@ sub AddCustomFieldDefaultValues {
my $values = $cf->DefaultValues( Object => $on || RT->System );
foreach my $value ( UNIVERSAL::isa( $values => 'ARRAY' ) ? @$values : $values ) {
next if $self->CustomFieldValueIsEmpty(
- Field => $cf->id,
+ Field => $cf,
Value => $value,
);
@@ -2161,7 +2161,10 @@ sub CustomFieldValueIsEmpty {
my $value = $args{Value};
return 1 unless defined $value && length $value;
- my $cf = $self->LoadCustomFieldByIdentifier( $args{'Field'} );
+ my $cf = ref($args{'Field'})
+ ? $args{'Field'}
+ : $self->LoadCustomFieldByIdentifier( $args{'Field'} );
+
if ($cf) {
if ( $cf->Type =~ /^Date(?:Time)?$/ ) {
my $DateObj = RT::Date->new( $self->CurrentUser );
diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
index 48728a2..b65aae4 100644
--- a/lib/RT/Ticket.pm
+++ b/lib/RT/Ticket.pm
@@ -490,7 +490,7 @@ sub Create {
UNIVERSAL::isa( $args{$arg} => 'ARRAY' ) ? @{ $args{$arg} } : ( $args{$arg} ) )
{
next if $self->CustomFieldValueIsEmpty(
- Field => $cfid,
+ Field => $cf,
Value => $value,
);
diff --git a/lib/RT/Transaction.pm b/lib/RT/Transaction.pm
index 145ca34..9d1b009 100644
--- a/lib/RT/Transaction.pm
+++ b/lib/RT/Transaction.pm
@@ -1539,7 +1539,7 @@ sub UpdateCustomFields {
my $value ( UNIVERSAL::isa( $values, 'ARRAY' ) ? @$values : $values )
{
next if $self->CustomFieldValueIsEmpty(
- Field => $cfid,
+ Field => $cf,
Value => $value,
);
$self->_AddCustomFieldValue(
commit 4c6e7f8f31716274dffd5a486d761a9c4207bb9c
Author: Shawn M Moore <shawn at bestpractical.com>
Date: Wed Apr 20 20:04:02 2016 +0000
Allow SetInitialCustomFieldValue without SeeCustomField
This allows you to set up permissions such that users can set custom
fields on initial ticket create but not see them on ticket display,
nor edit them on ticket modify.
We have to propagate "this is for creation so
SetInitialCustomFieldValue is enough to see the CF" from the web
interface down through to custom field rights checking.
diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
index 29780f6..af2da9f 100644
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -1885,12 +1885,22 @@ sub ValuesForObject {
=head2 CurrentUserCanSee
If the user has SeeCustomField they can see this custom field and its details.
-+
+
+Otherwise, if the user has SetInitialCustomField and this is being used in a
+"create" context, then they can see this custom field and its details. This
+allows you to set up custom fields that are only visible on create pages and
+are then inaccessible.
+
=cut
sub CurrentUserCanSee {
my $self = shift;
- return $self->CurrentUserHasRight('SeeCustomField');
+ return 1 if $self->CurrentUserHasRight('SeeCustomField');
+
+ return 1 if $self->{include_set_initial}
+ && $self->CurrentUserHasRight('SetInitialCustomField');
+
+ return 0;
}
=head2 RegisterLookupType LOOKUPTYPE FRIENDLYNAME
diff --git a/lib/RT/CustomFields.pm b/lib/RT/CustomFields.pm
index 1a8054c..4cc5961 100644
--- a/lib/RT/CustomFields.pm
+++ b/lib/RT/CustomFields.pm
@@ -403,6 +403,8 @@ sub AddRecord {
my ($record) = @_;
$record->SetContextObject( $self->ContextObject );
+ $record->{include_set_initial} = $self->{include_set_initial};
+
return unless $record->CurrentUserCanSee;
return $self->SUPER::AddRecord( $record );
diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index 266ba6e..563b09e 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -3306,6 +3306,7 @@ sub ProcessObjectCustomFieldUpdatesForCreate {
# we're only interested in new objects, so only look at $id == 0
for my $cfid (keys %{ $custom_fields{$class}{0} || {} }) {
my $cf = RT::CustomField->new( $session{'CurrentUser'} );
+ $cf->{include_set_initial} = 1;
if ($context) {
my $system_cf = RT::CustomField->new( RT->SystemUser );
$system_cf->LoadById($cfid);
diff --git a/lib/RT/Record.pm b/lib/RT/Record.pm
index 8947a91..cb33589 100644
--- a/lib/RT/Record.pm
+++ b/lib/RT/Record.pm
@@ -1942,6 +1942,8 @@ sub _AddCustomFieldValue {
);
my $cf = $self->LoadCustomFieldByIdentifier($args{'Field'});
+ $cf->{include_set_initial} = 1 if $args{'ForCreation'};
+
unless ( $cf->Id ) {
return ( 0, $self->loc( "Custom field [_1] not found", $args{'Field'} ) );
}
diff --git a/share/html/Elements/EditCustomFields b/share/html/Elements/EditCustomFields
index 7e21d31..7349ac2 100644
--- a/share/html/Elements/EditCustomFields
+++ b/share/html/Elements/EditCustomFields
@@ -99,6 +99,7 @@
% Grouping => $Grouping, ARGSRef => \%ARGS );
<%INIT>
$CustomFields ||= $Object->CustomFields;
+$CustomFields->{include_set_initial} = 1 if $ForCreation;
$CustomFields->LimitToGrouping( $Object => $Grouping ) if defined $Grouping;
-----------------------------------------------------------------------
More information about the rt-commit
mailing list