Exemple #1
0
function includeAllData($pack)
{
    extract($pack);
    $element2query = $element2query == '' ? $s3ql['from'] : $element2query;
    #echo '<pre>';print_r($data);exit;
    $letter = letter($element2query);
    $element = $GLOBALS['s3codes'][$letter];
    if ($user_id != '1') {
        if (count($data) >= 4) {
            if (!ereg('^U|^G', $letter)) {
                $Z = compact('user_id', 'db', 'uidQuery', 'timer', 'WhereInfo', 'shared_with_query');
                $Z['toFind'] = $letter;
                $Z['shared_with_user'] = '******' . $user_id;
                $ids = permissionPropagation($Z);
            }
        }
    }
    if (ereg('^U|^G', $letter) && $WhereInfo) {
        $whereId = array_keys($WhereInfo);
        if (count($whereId) > 1) {
            $array = array();
            return $array;
        } else {
            $whereId = $whereId[0];
            #Tlist provides the list of resources that are shared with the uid of interest, including users & groups
            $Hlist = bottom_up_propagation_list($whereId, $db);
            $Tlist = user_included_bottom_up_propagation_list('U', $whereId, $user_id, $db);
            $resourceUsers = s3dbPercolate($Hlist, $Tlist, $letter);
            if ($_REQUEST['su3d']) {
            }
        }
    }
    ##Remove from data the uids that do not exist in ids
    $str = $GLOBALS['s3ids'][$GLOBALS['s3codes'][$letter]];
    $re_issued = array();
    if (is_array($data)) {
        foreach ($data as $ind => $array) {
            $uid = $letter . $array[$str];
            if ($uid != '') {
                if ($user_id != '1') {
                    if (is_array($ids)) {
                        if (!ereg('^U|^G', $letter)) {
                            if ($ids[$uid] != '') {
                                $array['acl'] = $ids[$uid];
                            } else {
                                $array = array();
                            }
                        } else {
                            if ($resourceUsers) {
                                if (in_array($uid, array_keys($resourceUsers))) {
                                    $array['permissionOnResource'] = $resourceUsers[$uid];
                                } else {
                                    $array = array();
                                }
                            }
                            #else {
                            #	 $array=array();
                            #}
                        }
                    } else {
                        $strictuid = 1;
                        $strictsharedwith = 1;
                        $shared_with = 'U' . $user_id;
                        $P = compact('uid', 'shared_with', 'user_id', 'db', 'strictuid', 'strictsharedwith', 'stream', 'timer');
                        if (!ereg('^U|^G', $letter)) {
                            $array['acl'] = permission4Resource($P);
                            $array['permission_level'] = $array['acl'];
                            $permission2user = permissionModelComp($array['permission_level']);
                            $isOwner = $array['created_by'] == $user_id;
                            $array['view'] = allowed($permission2user, 0, $isOwner);
                            $array['change'] = allowed($permission2user, 1, $isOwner);
                            $array['propagate'] = allowed($permission2user, 2, $isOwner);
                            #create the element "delete", in case it is eventually created...For now it is the same as change
                            $array['delete'] = $array['change'];
                            $array['add_data'] = $array['propagate'];
                            $array['delete_data'] = $array['add_data'];
                        } else {
                            if ($resourceUsers) {
                                if (in_array($uid, array_keys($resourceUsers))) {
                                    $array['permissionOnResource'] = $resourceUsers[$uid];
                                } else {
                                    $array = array();
                                }
                            }
                            #else {
                            #	 $array=array();
                            #}
                        }
                    }
                } else {
                    $array['acl'] = 'yyy';
                    if (ereg('^U|^G', $letter) && $resourceUsers) {
                        if ($resourceUsers) {
                            if (in_array($uid, array_keys($resourceUsers))) {
                                $array['permissionOnResource'] = $resourceUsers[$uid];
                            } else {
                                $array = array();
                            }
                        }
                        #else {
                        #	 $array=array();
                        #}
                    }
                }
            }
            if (!empty($array)) {
                $re_issued[$uid] = $array;
                $element_info = $re_issued[$uid];
                $info = $WhereInfo;
                $C = compact('letter', 'info', 'elements', 'element_info', 'user_id', 'db', 'key', 'timer', 'model');
                $element_info = include_all($C);
                $element_info['uri'] = S3DB_URI_BASE . '/' . $letter . $array[$str];
                #$element_info['uri'] = str_replace('central', 'TCGA', S3DB_URI_BASE.'/'.$letter.$array[$str]);
                $pack['uid'] = $uid;
                $pack['info'] = $element_info;
                $element_info = filterDataForQuery($pack);
                if ($timer) {
                    $timer->setMarker('Filter Data For The Query');
                }
                $re_issued[$uid] = $element_info;
            }
        }
    }
    $data = array_values(array_filter($re_issued));
    return $data;
}
Exemple #2
0
function permissionPropagation($Z)
{
    #NEW NEW
    extract($Z);
    $model = 'nsy';
    ##Seems to be working; requires further testing
    ##This vector is an indication of what propagates from the user
    $X = user_centric_propagation_list($user_id, $db);
    ##If $X includes roles, percolate the user allowed list to those roles
    if (is_array($X)) {
        foreach ($X as $X_uid => $X_pl) {
            if (substr($X_uid, 0, 1) == 'U') {
                $role = substr($X_uid, 1, strlen($X_uid));
                $roles[] = role_propagation_list($role, $db, $X_pl);
            }
        }
    }
    ##Now merge all the roles into X
    if (is_array($roles)) {
        foreach ($roles as $r => $role_X) {
            foreach ($role_X as $uid1 => $pl1) {
                if ($X[$uid1]) {
                    $tmp = s3dbMerge(array($X[$uid1], $pl1));
                    $X[$uid1] = $tmp;
                } else {
                    $X[$uid1] = $pl1;
                }
            }
        }
    }
    ##FIRST: Colect every relation from the permissions table
    #According to the amount of data that needs to be discovered to build the matrix, the bottom up, top-down,or middle point approach will be selected.
    if ($toFind != letter($toFind)) {
        $Hlist = bottom_up_propagation_list($toFind, $db, $X);
    } elseif ($toFind == letter($toFind) && !$shared_with_query) {
        $X = user_centric_propagation_list($user_id, $db);
        #Find the initial propagation list by finding all of the resources in the class of the requested resource
        if (is_array($X)) {
            $starter = array_keys($X);
        }
        $Hlist = top_down_propagation_list($toFind, $starter, $db, $toFindInfo);
    } elseif ($shared_with_query) {
        #when a uid is specified, propagation will only occur form that point onwards
        $Hlist = array();
        foreach ($shared_with_query as $up) {
            $Hlist = bottom_up_propagation_list($up, $db, $X, $Hlist);
        }
        $Hlist = top_down_propagation_list($toFind, $shared_with_query, $db, $Hlist);
    }
    #now find the vector that will be used to propagate the permissions: the one captured from downtream finding permissions the user may have;
    #if(is_array($Hlist))
    if (is_array($X)) {
        #convert pl to the right model
        $model_p = str_split($model);
        foreach ($X as $key_id => $key_pl) {
            $X[$key_id] = str_ireplace(array('0', '1', '2'), $model_p, $key_pl);
        }
        if (is_array($X) && is_array($Hlist)) {
            $result = s3dbPercolate($Hlist, $X, $toFind, $result = array(), $u = 1, $state = 3, $model);
        }
    } else {
        $result = $X;
    }
    if (is_array($result)) {
        if ($model == '012') {
            foreach ($result as $a => $b) {
                $result[$a] = str_ireplace(array('n', 's', 'y'), array('0', '1', '2'), $b);
            }
        } elseif ($model == 'nsy') {
            foreach ($result as $a => $b) {
                $result[$a] = str_ireplace(array('0', '1', '2'), array('n', 's', 'y'), $b);
            }
        }
    }
    if ($timer) {
        $timer->setMarker('Permissions percolated for ' . $toFind);
    }
    #$timer->display();
    return $result;
}