예제 #1
0
/**
 * Update a group
 * @return Group instance
 */
function update_group($name, $label, $ns, Userfilter $filter)
{
    $gf = new GroupFilter(new GFC_Name($name));
    $g = $gf->get(true);
    if ($g instanceof Group) {
        echo 'Updating ' . $label . ' (' . $name . ', ' . $g->id() . ') ';
        $g->select(GroupSelect::castes());
    } else {
        echo 'Creating ' . $label . ' (' . $name . ') ';
        $g = new Group();
        $g->insert();
        $g->ns($ns);
        $g->name($name);
        $g->label($label);
    }
    $c = $g->caste(Rights::member());
    $c->select(CasteSelect::base());
    $c->userfilter($filter);
    $c->compute();
    echo '... ' . $c->users()->count() . ' member(s)' . "\n";
    return $g;
}
예제 #2
0
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
 *  GNU General Public License for more details.                           *
 *                                                                         *
 *  You should have received a copy of the GNU General Public License      *
 *  along with this program; if not, write to the Free Software            *
 *  Foundation, Inc.,                                                      *
 *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
 ***************************************************************************/
/*
 * This script creates and updates the groups corresponding to the promos
 */
require_once dirname(__FILE__) . '/../connect.db.inc.php';
$gf = new GroupFilter(new GFC_Name('everybody'));
$g = $gf->get(true);
$g->select(GroupSelect::castes());
$c = $g->caste(Rights::member());
$c->select(CasteSelect::base())->compute();
echo 'Groupe everybody mis à jour' . "\n";
$gf = new GroupFilter(new GFC_Name('public'));
$g = $gf->get(true);
$g->select(GroupSelect::castes());
$c = $g->caste(Rights::member());
$c->select(CasteSelect::base())->compute();
echo 'Groupe visibilité extérieure mis à jour' . "\n";
$gf = new GroupFilter(new GFC_Name('licenses'));
$g = $gf->get(true);
$g->select(GroupSelect::castes());
$c = $g->caste(Rights::member());
$c->select(CasteSelect::base())->compute();
echo 'Groupe licenses mis à jour' . "\n";
예제 #3
0
파일: group.php 프로젝트: netixx/frankiz
 public static function see()
 {
     return new GroupSelect(array('ns', 'score', 'name', 'label', 'description', 'image', 'wikix', 'web', 'mail', 'visible', 'castes', 'leavable', 'external', 'rooms'), array('castes' => CasteSelect::base(), 'rooms' => RoomSelect::premise()));
 }
예제 #4
0
function check_group(Group $g)
{
    global $available_rights, $formations;
    global $ufc_web, $ufc_kes, $ufc_shalom_ccx_amep, $ufc_licenses;
    $gtext = $g->id() . " (" . $g->name() . ")";
    // For each group, get castes in an array, indexed by rights
    $gc = array();
    $gcid = array();
    $g->castes()->select(CasteSelect::base());
    foreach ($g->castes() as $c) {
        $cright = (string) $c->rights();
        if (!in_array($cright, $available_rights)) {
            echo "Error: caste " . $c->id() . " has invalid rights " . $cright . "\n";
            continue;
        }
        $gcid[$cright] = intval($c->id());
        $gc[$cright] = $c;
    }
    if (!count($gc)) {
        echo "Error: user group " . $gtext . " does not have any caste !\n";
        return;
    }
    // Check userfilters
    if ($g->ns() == 'user') {
        if (!preg_match('/^user_[1-9][0-9]*$/', $g->name())) {
            echo "Warning: user group " . $gtext . " has an invalid name\n";
        }
        if (count($gc) != 2 || !isset($gc['admin']) || !isset($gc['restricted'])) {
            echo "Error: user group " . $gtext . " has invalid castes, " . implode(', ', array_keys($gc)) . "\n";
            return;
        }
        if ($gc['admin']->userfilter() != null) {
            echo "Warning: user group " . $gtext . " has an admin userfilter\n";
        }
        if ($gc['restricted']->userfilter() != null) {
            echo "Warning: user group " . $gtext . " has a restricted userfilter\n";
        }
    } else {
        // Everything else has all rights
        if (count($gc) != count($available_rights)) {
            echo $gtext . " has " . count($gc) . " castes " . implode(', ', array_keys($gc)) . "\n";
        }
        // Check restricted userfilter
        test_userfilters($gtext, 'restricted', $gc['restricted'], new UFC_Caste(array($gcid['admin'], $gcid['member'], $gcid['logic'])));
        // Check everybody userfilter
        test_userfilters($gtext, 'everybody', $gc['everybody'], new UFC_Caste(array($gcid['admin'], $gcid['member'], $gcid['logic'], $gcid['friend'])));
        // Check special group admins
        if (in_array($g->name(), array('on_platal', 'everybody', 'public', 'tol', 'postit', 'temp'))) {
            // Webmasters are automatically admins of some groups
            test_userfilters($gtext, 'admin', $gc['admin'], $ufc_web);
        } elseif ($g->name() == 'formation_x') {
            test_userfilters($gtext, 'admin', $gc['admin'], $ufc_kes);
        } elseif ($g->name() == 'adherents-kes') {
            test_userfilters($gtext, 'admin', $gc['admin'], $ufc_kes);
        } elseif ($g->name() == 'shalom-ccx-amep') {
            test_userfilters($gtext, 'admin', $gc['admin'], $ufc_shalom_ccx_amep);
        } else {
            test_userfilters($gtext, 'admin', $gc['admin']);
        }
        // Check special group members
        if ($g->name() == 'everybody') {
            test_userfilters($gtext, 'member', $gc['member'], new PFC_Not(new UFC_Uid(-1)));
        } elseif ($g->name() == 'public') {
            test_userfilters($gtext, 'member', $gc['member'], new PFC_True());
        } elseif ($g->name() == 'shalom-ccx-amep') {
            test_userfilters($gtext, 'member', $gc['member'], $ufc_shalom_ccx_amep);
        } elseif ($g->name() == 'licenses') {
            test_userfilters($gtext, 'member', $gc['member'], $ufc_licenses);
        } elseif ($g->ns() == 'promo') {
            $matches = array();
            if ($g->name() == 'on_platal') {
                $promos = array();
                if ($gc['member']->userfilter()) {
                    $data = $gc['member']->userfilter()->export();
                    for ($i = 0; isset($data['condition']['children'][$i]['promo']); $i++) {
                        // This only checks logic connectors
                        // TODO: Check years
                        $p = $data['condition']['children'][$i]['promo'];
                        $f = $data['condition']['children'][$i]['formation_id'];
                        array_push($promos, new UFC_Promo($p, '=', $f));
                    }
                }
                test_userfilters($gtext, 'member', $gc['member'], new PFC_Or($promos));
            } elseif (!preg_match('/^promo_([a-z]*)([0-9]{4})$/', $g->name(), $matches)) {
                echo "Warning: promo group " . $gtext . " has an invalid name\n";
            } else {
                $fid = $matches[1] ? (string) $formations[$matches[1]] : 0;
                test_userfilters($gtext, 'member', $gc['member'], new UFC_Promo($matches[2], '=', $fid));
            }
        } elseif ($g->ns() == 'study' || $g->name() == 'formation_fkz') {
            $matches = array();
            if (!preg_match('/^formation_([a-z]+)$/', $g->name(), $matches)) {
                echo "Warning: study group " . $gtext . " has an invalid name\n";
            } elseif (!isset($formations[$matches[1]])) {
                echo "Error: study group " . $gtext . " has an unknown formation\n";
            } else {
                test_userfilters($gtext, 'member', $gc['member'], new UFC_Study((string) $formations[$matches[1]]));
            }
        } else {
            test_userfilters($gtext, 'member', $gc['member']);
        }
        test_userfilters($gtext, 'friend', $gc['friend']);
        // Check name
        if (!$g->ns()) {
            // Empty name means it is a special group
            if (!in_array($g->name(), array('everybody', 'public', 'tol', 'postit', 'temp', 'postit', 'licenses', 'formation_fkz'))) {
                echo "Warning: group " . $gtext . " has an empty namespace\n";
            }
        } elseif ($g->ns() == 'nationality') {
            if (!preg_match('/^nation_[a-z-]+$/', $g->name())) {
                echo "Warning: nationality group " . $gtext . " has an invalid name\n";
            }
        } elseif ($g->ns() == 'course') {
            if (!preg_match('/^pa_[a-z0-9-_]+$/', $g->name()) && !preg_match('/^modal[a-z0-9-_]+$/', $g->name())) {
                echo "Warning: course group " . $gtext . " has an invalid name\n";
            }
        } elseif ($g->ns() == 'sport') {
            if (!preg_match('/^sport_[a-z]+$/', $g->name())) {
                echo "Warning: sport group " . $gtext . " has an invalid name\n";
            }
        } elseif ($g->ns() == 'bde') {
            if ($g->name() != 'adherents-kes') {
                echo "Warning: unknown BDE " . $gtext . "\n";
            }
        } elseif (!in_array($g->ns(), array('study', 'promo', 'binet', 'free'))) {
            echo "Error: Unknown NS " . $g->ns() . " for group " . $gtext . "\n";
        }
    }
}
예제 #5
0
 public static function caste()
 {
     return new self(array('caste'), array('caste' => CasteSelect::base()));
 }