/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = authassignment::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['created_at' => $this->created_at]); $query->andFilterWhere(['like', 'item_name', $this->item_name])->andFilterWhere(['like', 'user_id', $this->user_id]); return $dataProvider; }
/** * Retrieve any Project or Organization affiliations for the logged-in user-- this should filter the user's view to within the boundaries allowed to that group. */ public function getUserAffiliations() { $logger = \Yii::getLogger(); $logger->init(); $logger->flushInterval = 1; $logger->traceLevel = 0; //Get a list of project and/or organizational affiliations for the logged-in user. $this->user_id = (string) strval($this->user_id); //Ensure user_id is in string format $proj_found = $org_found = False; //Proceed with storing other affiliations so that the user can switch later, //by selecting from the list that we will store here in this method. //The logged-in user's affiliations are stored in App Params initialized in params-local.php in /common/config/. if (intval($this->user_id) > 0) { //User ID is non-blank $affils = $this->find()->where(['user_id' => $this->user_id])->all(); if (!empty($affils)) { //A result was returned //Scroll thru the results, which may contain multiple Project and/or Organizational affiliations foreach ($affils as $affil) { //Choose the FIRST project and the FIRST organizational affiliation associated with this user, //as the value that will be used in filtering the content they have permission to access. (Then give them a way to switch to a different affiliation later) if (!empty($affil)) { if (strtolower(substr((string) $affil->group_type, 0, 4)) == "proj" && !$proj_found) { Yii::$app->params["current_affiliation"] = array('type' => 'proj', 'value' => strtolower(strval($affil->group_name))); $proj_found = True; } elseif (strtolower(substr((string) $affil->group_type, 0, 3)) == "org" && !$org_found) { Yii::$app->params["current_affiliation"] = array('type' => 'org', 'value' => strtolower(strval($affil->group_name))); $org_found = True; } } //Debugging only $msg = "gms: getUserAffiliations() for UserId: " . $this->user_id . " -- Next Affiliation: '" . (string) $affil->group_name . "' , '" . (string) $affil->group_type . "'"; $logger->log($msg . " (LG)", 4); //We are storing only the FIRST affiliation of each type (Project and Organization) -- when they are both stored, exit the loop if ($proj_found && $org_found) { break; } } //Store the array of affiliations as an application parameter so that it's available when needed Yii::$app->params["affiliations"] = $affils; } //CH CUSTOM: If this user belongs to 'internal_staff' then allow that to override all other roles //(they can later explicitly opt to use the others) //GMS UPDATE Dec.2015 - "Internal_Staff" role has been divided into the "Internal_Staff_Auth" role //and the "Internal_Staff_Affil" affiliation. //If Internal_Staff, override any affiliations $auth_assign = new authassignment(); $staff_role_found = $auth_assign->find()->where(['user_id' => $this->user_id, 'item_name' => 'internal_staff_auth'])->one(); //$internal_affil_found = $this->find()->where(['user_id' => $this->user_id, 'group_name' => 'internal_staff_affil'])->one(); if (empty($staff_role_found)) { //If Super_Admin, override any affiliations $staff_role_found = $auth_assign->find()->where(['user_id' => $this->user_id, 'item_name' => 'super_admin'])->one(); } if (empty($staff_role_found)) { //This user is NOT in 'internal_staff' -- determine whether they are in 'fulltrust_partner' //If Fulltrust_Partner, override any affiliations $staff_role_found = $auth_assign->find()->where(['user_id' => $this->user_id, 'item_name' => 'fulltrust_partner'])->one(); } //If any of the internal/trusted user affiliations are found, override other affiliations so that the user's views of the data will not be filtered (unless they choose) if (!empty($staff_role_found)) { //This user is (a) Super_Admin; (b) Internal_Staff; or (c) Fulltrust_Partner; - so override other affiliations and mark them as "Internal_Staff" Yii::$app->params["current_affiliation"] = array('type' => 'org', 'value' => 'internal_staff_affil'); } $auth_assign = NULL; //Debugging only $msg = "gms: getUserAffiliations() ... App param for Current_Affiliation (END of getUserAffiliations): " . implode(",", Yii::$app->params["current_affiliation"]); $logger->log($msg . " (LG)", 4); } //DEBUG get errors /* if (! empty( $this->getErrors() ) ){ $errs = $this->getErrors(); foreach ($errs as $err) { foreach ($err as $item){ $msg = "gms: ERR in getUserAffiliations() -- " . $item; $logger->log($msg . " (LG)", 4); } } } */ $logger->flush(); return null; }