Merge branch 'master' into WebGUI8
This commit is contained in:
commit
e4e27d6e96
23 changed files with 555 additions and 260 deletions
|
|
@ -119,10 +119,19 @@ A hash reference of optional parameters. None at this time.
|
|||
|
||||
sub applyConstraints {
|
||||
my $self = shift;
|
||||
$self->getStorageLocation->setPrivileges($self->ownerUserId, $self->groupIdView, $self->groupIdEdit);
|
||||
$self->setPrivileges;
|
||||
$self->setSize;
|
||||
}
|
||||
|
||||
sub setPrivileges {
|
||||
my $self = shift;
|
||||
$self->getStorageLocation->setPrivileges(
|
||||
$self->ownerUserId,
|
||||
$self->groupIdView,
|
||||
$self->groupIdEdit,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
|
|
|
|||
|
|
@ -1178,5 +1178,10 @@ sub www_view {
|
|||
return "chunked";
|
||||
}
|
||||
|
||||
sub setPrivileges {
|
||||
my $self = shift;
|
||||
$self->getStorageLocation->setPrivileges($self);
|
||||
}
|
||||
|
||||
|
||||
1; # Who knew the truth would be so obvious?
|
||||
|
|
|
|||
|
|
@ -230,13 +230,17 @@ Get the common template vars for this asset
|
|||
|
||||
sub getTemplateVars {
|
||||
my ( $self ) = @_;
|
||||
my $i18n = WebGUI::International->new($self->session, "Asset_WikiPage");
|
||||
my $wiki = $self->getWiki;
|
||||
my $owner = WebGUI::User->new( $self->session, $self->ownerUserId );
|
||||
my $keywords = WebGUI::Keyword->new($self->session)->getKeywordsForAsset({
|
||||
my $session = $self->session;
|
||||
my $i18n = WebGUI::International->new($session, "Asset_WikiPage");
|
||||
my $wiki = $self->getWiki;
|
||||
my $owner = WebGUI::User->new( $session, $self->ownerUserId );
|
||||
my $keyObj = WebGUI::Keyword->new($session);
|
||||
|
||||
my $keywords = $keyObj->getKeywordsForAsset({
|
||||
asset => $self,
|
||||
asArrayRef => 1,
|
||||
});
|
||||
|
||||
my @keywordsLoop = ();
|
||||
foreach my $word (@{$keywords}) {
|
||||
push @keywordsLoop, {
|
||||
|
|
@ -270,11 +274,35 @@ sub getTemplateVars {
|
|||
$self->scrubContent,
|
||||
{skipTitles => [$self->title]},
|
||||
),
|
||||
isKeywordPage => $self->isKeywordPage,
|
||||
isSubscribed => $self->isSubscribed,
|
||||
subscribeUrl => $self->getSubscribeUrl,
|
||||
unsubscribeUrl => $self->getUnsubscribeUrl,
|
||||
owner => $owner->get('alias'),
|
||||
};
|
||||
my @keyword_pages = ();
|
||||
if ($var->{isKeywordPage}) {
|
||||
my $paginator = $keyObj->getMatchingAssets({
|
||||
startAsset => $self->getWiki,
|
||||
keyword => $self->get('title'),
|
||||
usePaginator => 1,
|
||||
});
|
||||
PAGE: foreach my $assetId (@{ $paginator->getPageData }) {
|
||||
next PAGE if $assetId->{assetId} eq $self->getId;
|
||||
my $asset = WebGUI::Asset->newByDynamicClass($session, $assetId->{assetId});
|
||||
next PAGE unless $asset;
|
||||
push @keyword_pages, {
|
||||
title => $asset->getTitle,
|
||||
url => $asset->getUrl,
|
||||
};
|
||||
}
|
||||
$paginator->appendTemplateVars($var);
|
||||
@keyword_pages = map { $_->[1] }
|
||||
sort
|
||||
map { [ lc $_->{title}, $_ ] }
|
||||
@keyword_pages;
|
||||
}
|
||||
$var->{keyword_page_loop} = \@keyword_pages;
|
||||
return $var;
|
||||
}
|
||||
|
||||
|
|
@ -312,6 +340,24 @@ around indexContent => sub {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 isKeywordPage
|
||||
|
||||
Returns a boolean indicating whether or not the name of this WikiPage matches any keyword in the Wiki that
|
||||
contains it.
|
||||
|
||||
=cut
|
||||
|
||||
sub isKeywordPage {
|
||||
my $self = shift;
|
||||
my $keywords = WebGUI::Keyword->new($self->session)->getMatchingAssets({
|
||||
asset => $self->getWiki,
|
||||
keyword => $self->get('title'),
|
||||
});
|
||||
return scalar @{ $keywords };
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 preparePageTemplate
|
||||
|
||||
This is essentially prepareView, but is smart and will only do the template
|
||||
|
|
|
|||
|
|
@ -48,6 +48,9 @@ our $HELP = {
|
|||
{ tag => 'wiki page asset template variables',
|
||||
namespace => 'Asset_WikiPage'
|
||||
},
|
||||
{ tag => 'pagination template variables',
|
||||
namespace => 'WebGUI'
|
||||
},
|
||||
],
|
||||
variables => [
|
||||
{ name => 'viewLabel',
|
||||
|
|
@ -78,6 +81,16 @@ our $HELP = {
|
|||
},
|
||||
{ 'name' => 'editContent', },
|
||||
{ 'name' => 'content', },
|
||||
{ 'name' => 'keywordsLoop',
|
||||
'variables' => [
|
||||
{ 'name' => 'keyword',
|
||||
'description' => 'keyword title',
|
||||
},
|
||||
{ 'name' => 'url',
|
||||
'description' => 'keyword url',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name => 'isSubscribed',
|
||||
description => 'help isSubscribed',
|
||||
|
|
@ -94,6 +107,17 @@ our $HELP = {
|
|||
name => 'owner',
|
||||
description => 'help owner',
|
||||
},
|
||||
{ 'name' => 'isKeywordPage', },
|
||||
{ 'name' => 'keyword_page_loop',
|
||||
'variables' => [
|
||||
{ 'name' => 'title',
|
||||
'description' => 'keyword page title',
|
||||
},
|
||||
{ 'name' => 'url',
|
||||
'description' => 'keyword page url',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
related => [],
|
||||
},
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ use Path::Class::Dir;
|
|||
use Storable ();
|
||||
use WebGUI::Utility qw(isIn);
|
||||
use WebGUI::Paths;
|
||||
use JSON ();
|
||||
|
||||
|
||||
=head1 NAME
|
||||
|
|
@ -1666,10 +1667,42 @@ The groupId that is allowed to edit the files in this storage location.
|
|||
=cut
|
||||
|
||||
sub setPrivileges {
|
||||
my $self = shift;
|
||||
my $owner = shift;
|
||||
my $viewGroup = shift;
|
||||
my $editGroup = shift;
|
||||
my $self = shift;
|
||||
my %privs = (
|
||||
users => [],
|
||||
groups => [],
|
||||
assets => [],
|
||||
);
|
||||
if (@_ == 3 && !ref $_[0] && !ref $_[1] && !ref $_[0]) {
|
||||
push @{ $privs{users} }, $_[0];
|
||||
push @{ $privs{groups} }, @_[1,2];
|
||||
}
|
||||
else {
|
||||
for my $object (@_) {
|
||||
if ($object->isa('WebGUI::User')) {
|
||||
push @{ $privs{users} }, $object->getId;
|
||||
}
|
||||
elsif ($object->isa('WebGUI::Group')) {
|
||||
push @{ $privs{groups} }, $object->getId;
|
||||
}
|
||||
elsif ($object->isa('WebGUI::Asset')) {
|
||||
push @{ $privs{assets} }, $object->getId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
my $public;
|
||||
for my $user (@{ $privs{users} }) {
|
||||
if ($user eq '1') {
|
||||
$public = 1;
|
||||
}
|
||||
}
|
||||
for my $group (@{ $privs{groups} }) {
|
||||
if ($group eq '1' || $group eq '7') {
|
||||
$public = 1;
|
||||
}
|
||||
}
|
||||
my $accessFile = JSON->new->encode( \%privs );
|
||||
|
||||
my $dirObj = $self->getPathClassDir();
|
||||
return undef if ! defined $dirObj;
|
||||
|
|
@ -1679,11 +1712,11 @@ sub setPrivileges {
|
|||
return unless $obj->is_dir;
|
||||
my $rel = $obj->relative($dirObj);
|
||||
|
||||
if ($owner eq '1' || $viewGroup eq '1' || $viewGroup eq '7' || $editGroup eq '1' || $editGroup eq '7') {
|
||||
if ($public) {
|
||||
$self->deleteFile($rel->file('.wgaccess')->stringify);
|
||||
}
|
||||
else {
|
||||
$self->addFileFromScalar($rel->file('.wgaccess')->stringify,$owner."\n".$viewGroup."\n".$editGroup);
|
||||
$self->addFileFromScalar($rel->file('.wgaccess')->stringify, $accessFile);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
|
|||
|
|
@ -47,38 +47,57 @@ The Apache request handler for this package.
|
|||
|
||||
sub handler {
|
||||
my ($request, $server, $config) = @_;
|
||||
$request->push_handlers(PerlAccessHandler => sub {
|
||||
if (-e $request->filename) {
|
||||
my $path = $request->filename;
|
||||
$path =~ s/^(\/.*\/).*$/$1/;
|
||||
if (-e $path.".wgaccess") {
|
||||
my $fileContents;
|
||||
open(my $FILE, "<" ,$path.".wgaccess");
|
||||
while (my $line = <$FILE>) {
|
||||
$fileContents .= $line;
|
||||
}
|
||||
close($FILE);
|
||||
my @privs = split("\n", $fileContents);
|
||||
unless ($privs[1] eq "7" || $privs[1] eq "1") {
|
||||
my $session = $request->pnotes('wgSession');
|
||||
unless (defined $session) {
|
||||
$session = WebGUI::Session->open($config->getFilename, $request, $server);
|
||||
}
|
||||
my $hasPrivs = ($session->var->get("userId") eq $privs[0] || $session->user->isInGroup($privs[1]) || $session->user->isInGroup($privs[2]));
|
||||
$session->close();
|
||||
if ($hasPrivs) {
|
||||
return Apache2::Const::OK;
|
||||
}
|
||||
else {
|
||||
return Apache2::Const::AUTH_REQUIRED;
|
||||
}
|
||||
}
|
||||
}
|
||||
return Apache2::Const::OK;
|
||||
}
|
||||
$request->push_handlers(PerlAccessHandler => sub {
|
||||
my $path = $request->filename;
|
||||
return Apache2::Const::NOT_FOUND
|
||||
unless -e $path;
|
||||
$path =~ s{[^/]*$}{};
|
||||
return Apache2::Const::OK
|
||||
unless -e $path . '.wgaccess';
|
||||
|
||||
open my $FILE, '<' , $path . '.wgaccess';
|
||||
my $fileContents = do { local $/; <$FILE> };
|
||||
close($FILE);
|
||||
my @users;
|
||||
my @groups;
|
||||
my @assets;
|
||||
if ($fileContents =~ /\A(?:\d+|[A-Za-z0-9_-]{22})\n(?:\d+|[A-Za-z0-9_-]{22})\n(?:\d+|[A-Za-z0-9_-]{22})/) {
|
||||
my @privs = split("\n", $fileContents);
|
||||
push @users, $privs[0];
|
||||
push @groups, @privs[1,2];
|
||||
}
|
||||
else {
|
||||
return Apache2::Const::NOT_FOUND;
|
||||
}
|
||||
my $privs = JSON->new->decode($fileContents);
|
||||
@users = @{ $privs->{users} };
|
||||
@groups = @{ $privs->{groups} };
|
||||
@assets = @{ $privs->{assets} };
|
||||
}
|
||||
|
||||
return Apache2::Const::OK
|
||||
if grep { $_ eq '1' } @users;
|
||||
|
||||
return Apache2::Const::OK
|
||||
if grep { $_ eq '1' || $_ eq '7' } @groups;
|
||||
|
||||
my $session = $request->pnotes('wgSession');
|
||||
unless (defined $session) {
|
||||
$session = WebGUI::Session->open($config->getFilename, $request, $server);
|
||||
}
|
||||
|
||||
my $userId = $session->var->get('userId');
|
||||
|
||||
return Apache2::Const::OK
|
||||
if grep { $_ eq $userId } @users;
|
||||
|
||||
my $user = $session->user;
|
||||
|
||||
return Apache2::Const::OK
|
||||
if grep { $user->isInGroup($_) } @groups;
|
||||
|
||||
return Apache2::Const::OK
|
||||
if grep { WebGUI::Asset->new($session, $_)->canView } @assets;
|
||||
|
||||
return Apache2::Const::AUTH_REQUIRED;
|
||||
} );
|
||||
return Apache2::Const::OK;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -486,15 +486,15 @@ sub getWorking {
|
|||
#First see if there is already a version tag
|
||||
$tag = $stow->get(q{versionTag});
|
||||
|
||||
return $tag if $tag;
|
||||
return $tag if ($tag && !$tag->isLocked);
|
||||
|
||||
$tagId = $session->scratch()->get(q{versionTag});
|
||||
if ($tagId) {
|
||||
$tag = $class->new($session, $tagId);
|
||||
|
||||
$stow->set(q{versionTag}, $tag);
|
||||
|
||||
return $tag;
|
||||
unless ($tag->isLocked) {
|
||||
$stow->set(q{versionTag}, $tag);
|
||||
return $tag;
|
||||
}
|
||||
}
|
||||
|
||||
#No tag found. Create or reclaim one?
|
||||
|
|
@ -523,10 +523,10 @@ sub getWorking {
|
|||
# For now, we only reclaim if 1 tag open.
|
||||
if (scalar @openTags == 1) {
|
||||
$tag = $openTags[0];
|
||||
|
||||
$tag->setWorking();
|
||||
|
||||
return $tag;
|
||||
unless ($tag->isLocked) {
|
||||
$tag->setWorking();
|
||||
return $tag;
|
||||
}
|
||||
}
|
||||
}
|
||||
elsif ($mode eq q{siteWide}) {
|
||||
|
|
@ -534,7 +534,7 @@ sub getWorking {
|
|||
|
||||
OPENTAG:
|
||||
foreach my $openTag (@{WebGUI::VersionTag->getOpenTags($session)}) {
|
||||
if ($openTag->get(q{isSiteWide})) {
|
||||
if ($openTag->get(q{isSiteWide}) && !$openTag->isLocked) {
|
||||
|
||||
$tag = $openTag;
|
||||
|
||||
|
|
@ -563,6 +563,16 @@ sub getWorking {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 isLocked ( )
|
||||
|
||||
Returns boolean value indicating whether tag is locked
|
||||
|
||||
=cut
|
||||
|
||||
sub isLocked { $_[0]{_data}{isLocked} }
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 leaveTag ( )
|
||||
|
||||
Make the user leave their current tag.
|
||||
|
|
@ -782,6 +792,7 @@ Sets this tag as the working tag for the current user.
|
|||
|
||||
sub setWorking {
|
||||
my $self = shift;
|
||||
return if $self->isLocked;
|
||||
$self->session->scratch->set("versionTag",$self->getId);
|
||||
$self->session->stow->set("versionTag", $self);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -291,6 +291,24 @@ our $I18N =
|
|||
context => q{Help for template variable},
|
||||
},
|
||||
|
||||
'keywordsLoop' => {
|
||||
message => q{A loop containing all keywords for this page is tagged with.},
|
||||
lastUpdated => 0,
|
||||
context => q{Help for template variable},
|
||||
},
|
||||
|
||||
'keyword title' => {
|
||||
message => q{The name of this keyword.},
|
||||
lastUpdated => 0,
|
||||
context => q{Help for template variable},
|
||||
},
|
||||
|
||||
'keyword url' => {
|
||||
message => q{The URL to view all pages tagged with this keyword. The URL will have the gateway URL prepended to it.},
|
||||
lastUpdated => 0,
|
||||
context => q{Help for template variable},
|
||||
},
|
||||
|
||||
'help owner' => {
|
||||
message => q{The username of the owner of the page},
|
||||
lastUpdated => 0,
|
||||
|
|
@ -309,12 +327,36 @@ our $I18N =
|
|||
context => 'Body text for help page',
|
||||
},
|
||||
|
||||
|
||||
'isFeatured label' => {
|
||||
message => q{Feature this on the front page},
|
||||
lastUpdated => 0,
|
||||
context => 'Label for asset property',
|
||||
},
|
||||
|
||||
'isKeywordPage' => {
|
||||
message => q{A boolean that is true if this page is a keyword page.},
|
||||
lastUpdated => 0,
|
||||
context => 'template variable help',
|
||||
},
|
||||
|
||||
'keyword_page_loop' => {
|
||||
message => q{If this page is a keyword page, then this loop will contain a list of all pages tagged with this page's keyword. The pagination variables will apply to the list of pages in this loop. If this page is not a keyword page, the loop will be blank, and the pagination variables will not be present.},
|
||||
lastUpdated => 0,
|
||||
context => 'template variable help',
|
||||
},
|
||||
|
||||
'keyword page title' => {
|
||||
message => q{The title of a page that has this keyword.},
|
||||
lastUpdated => 0,
|
||||
context => 'template variable help',
|
||||
},
|
||||
|
||||
'keyword page url' => {
|
||||
message => q{The URL to a page that has this keyword. The URL will have the gateway URL prepended to it.},
|
||||
lastUpdated => 0,
|
||||
context => 'template variable help',
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue