# Copyright (c) 2005 bivio Software, Inc. All Rights Reserved. # # Visit http://www.bivio.biz for more info. # # This library is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of the # License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; If not, you may get a copy from: # http://www.opensource.org/licenses/lgpl-license.html # # $Id: ForumForm.bunit,v 1.18 2010/01/28 17:45:47 nagler Exp $ FormModel({ comparator => 'nested_contains', }); req()->set_realm_and_user(undef, 'root'); my($mode) = sub { my($m) = @_; return ( sub { Bivio::Type->get_instance('FormMode')->$m()->execute(req(), 1); return 1; } => 1, ); }; my($realm) = sub { my($r) = @_; return ( sub { req()->set_realm($r); return 1; } => 1, ); }; my($check_perms) = sub { my($case, $expect) = @_; my($id) = req()->get_nested(qw(auth_realm id)); req()->set_realm(undef); req()->set_user(undef); # Clear cache req()->set_realm($id); $case->actual_return([ req()->get('auth_realm')->does_user_have_permissions( ['MAIL_SEND'], req())]); req()->set_user('demo'); return [$expect]; }; [ # Starting deviance tests $mode->('CREATE'), error_case({ 'RealmOwner.display_name' => 'Deviance', 'RealmOwner.name' => 't1', feature_blog => 1, feature_calendar => 1, feature_mail => 1, feature_motion => 1, feature_tuple => 1, }, { 'RealmOwner.name' => 'TOO_SHORT', }), error_case({ 'RealmOwner.display_name' => 'Deviance', 'RealmOwner.name' => 'nosuchtop-subforum', mail_send_access => MailSendAccess()->ALL_MEMBERS, }, { 'RealmOwner.name' => 'TOP_FORUM_NAME', }), # Conformance must be in one "non-rolled back" section [{ 'RealmOwner.display_name' => 'Top One', 'RealmOwner.name' => 'ff1', mail_send_access => MailSendAccess()->ALL_MEMBERS, mail_want_reply_to => 1, feature_blog => 1, feature_calendar => 1, feature_mail => 1, feature_motion => 1, feature_tuple => 1, }] => [{ 'Model.Forum' => { parent_realm_id => Bivio::Auth::Realm->get_general->get('id'), forum_id => var('parent'), }, auth_realm => { owner_name => 'ff1', }, 'Model.RealmUser' => { user_id => req()->get('auth_user_id'), # Last role found for forum admin user role => Bivio::Auth::Role->FILE_WRITER, realm_id => sub { return req()->get_nested('Model.Forum', 'forum_id'); }, }, }], $realm->('ff1'), $mode->('EDIT'), empty_case({ 'RealmOwner.display_name' => 'Top One', 'RealmOwner.name' => 'ff1', mail_want_reply_to => 1, mail_send_access => MailSendAccess()->ALL_MEMBERS, feature_blog => 1, feature_calendar => 1, feature_mail => 1, feature_motion => 1, feature_tuple => 1, }), [{ 'RealmOwner.display_name' => 'Top One', 'RealmOwner.name' => 'ff1', mail_send_access => MailSendAccess()->EVERYBODY, }] => sub { return $check_perms->(shift(@_), 1); }, [{ 'RealmOwner.display_name' => 'Top One', 'RealmOwner.name' => 'ff1', mail_send_access => MailSendAccess()->ALL_MEMBERS, }] => sub { return $check_perms->(shift(@_), 0); }, $mode->('CREATE'), empty_case({ 'RealmOwner.display_name' => 'Top One ', 'RealmOwner.name' => 'ff1-', mail_send_access => MailSendAccess()->ALL_MEMBERS, }), $realm->('ff1'), [{ 'RealmOwner.display_name' => 'Sub One', 'RealmOwner.name' => 'ff1-s1', mail_send_access => MailSendAccess()->ALL_MEMBERS, }] => [{ 'Model.Forum' => { parent_realm_id => var('parent'), }, auth_realm => { owner_name => 'ff1-s1', }, }], $realm->('ff1'), $mode->('CREATE'), # Trailing deviance tests error_case({ 'RealmOwner.display_name' => 'Deviance', 'RealmOwner.name' => 'ff1_s1', mail_send_access => MailSendAccess()->ALL_MEMBERS, }, { 'RealmOwner.name' => 'TOP_FORUM_NAME_CHANGE', }), ];