rt 4.2.13 ticket#13852
[freeside.git] / rt / share / html / Articles / Article / PreCreate.html
index 49507d4..fc7ff7f 100644 (file)
@@ -2,7 +2,7 @@
 %#
 %# COPYRIGHT:
 %#
-%# This software is Copyright (c) 1996-2012 Best Practical Solutions, LLC
+%# This software is Copyright (c) 1996-2016 Best Practical Solutions, LLC
 %#                                          <sales@bestpractical.com>
 %#
 %# (Except where explicitly superseded by other copyright notices)
 %#
 %# END BPS TAGGED BLOCK }}}
 <& /Elements/Header, Title => loc('Create an article in class...') &>
-<& /Elements/Tabs, Title => loc('Create an article in class...') &>
+<& /Elements/Tabs &>
+
+% if (not $classes_configured) {
+<& /Articles/Elements/NeedsSetup &>
+% } elsif (not @classes) {
+<i><&|/l&>You don't have permission to create Articles in any Class</&></i>
+% } else {
 <ul>
-% my $Classes = RT::Classes->new($session{'CurrentUser'});
-% $Classes->LimitToEnabled();
-% my $have_classes = 0;
-% while (my $Class = $Classes->Next) {
-% $have_classes++;
+% for my $Class (@classes) {
 % my $qs = $m->comp("/Elements/QueryString", %ARGS, Class=> $Class->Id);
 <li><a href="Edit.html?<% $qs|n %>"><&|/l, $Class->Name &>in class [_1]</&></a></li>
 % }
 </ul>
-% unless ( $have_classes ) {
-<span><&|/l&>Permission Denied</&></span>
 % }
+<%init>
+my $Classes = RT::Classes->new($session{'CurrentUser'});
+$Classes->LimitToEnabled();
+
+# This is a COUNT(), which doesn't apply ACLs; as such, we don't display
+# the warning if there are classes, but the user can't see them.
+my $classes_configured = $Classes->Count;
+
+# ->Next applies SeeClass, but we also want to check CreateArticle
+my @classes;
+while (my $class = $Classes->Next) {
+    push @classes, $class if $class->CurrentUserHasRight("CreateArticle");
+}
+
+# If there is only one, redirect to it
+MaybeRedirectForResults(
+    Path  => "/Articles/Article/Edit.html",
+    Force => 1,
+    Arguments => { Class => $classes[0]->id },
+) if @classes == 1;
+</%init>