Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/bestpractical/rt.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShawn M Moore <shawn@bestpractical.com>2017-04-18 17:32:30 +0300
committersunnavy <sunnavy@bestpractical.com>2022-10-19 00:25:59 +0300
commit0a63ccef9372234e1b3d6f731bc4c31dbe52dd5f (patch)
treed2931efe92c1b3d2eda9fcc01705092dbd2e1984
parent712515e60e874f7f9b34affb909461d702582d04 (diff)
Add CustomRoleObj method for loading by GroupType
With this we can easily go from the output of ->Roles to an RT::CustomRole object.
-rw-r--r--lib/RT/Record/Role/Roles.pm26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/RT/Record/Role/Roles.pm b/lib/RT/Record/Role/Roles.pm
index ffcfa5240d..25179a8fc6 100644
--- a/lib/RT/Record/Role/Roles.pm
+++ b/lib/RT/Record/Role/Roles.pm
@@ -851,4 +851,30 @@ you see faster create times.
=cut
+=head2 CustomRoleObj
+
+Returns the L<RT::CustomRole> object for this role if and only if it's
+backed by a custom role. If it's a core role (e.g. Ticket Requestors),
+returns C<undef>.
+
+=cut
+
+sub CustomRoleObj {
+ my $self = shift;
+ my $name = shift;
+
+ if (my ($id) = $name =~ /^RT::CustomRole-(\d+)$/) {
+ my $role = RT::CustomRole->new($self->CurrentUser);
+ my ( $ret, $msg ) = $role->Load($id);
+ if ( $ret ) {
+ return $role;
+ }
+ else {
+ RT->Logger->warning("Couldn't load custom role #$id: $msg");
+ }
+ }
+
+ return undef;
+}
+
1;