Ejemplo n.º 1
9
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $this->info("Clearing permissions... \n");
     // Delete old data
     $response = Action::deleteAllData();
     null !== $response ? $this->error("\n" . $response . "\n") : null;
     $this->info("Permissions cleared... \n");
     try {
         $routeData = $this->getRouteData();
         $roles = Role::all();
         DB::beginTransaction();
         foreach ($routeData as $action => $uri) {
             $action = new Action(['uri' => $uri, 'action' => $action]);
             $action->save();
             $this->savePermissions($roles, $action);
             $this->comment("Added action " . $action->action . "\n");
         }
         $cache = $this->getCacheInstance(['permissions']);
         $cache->flush();
         DB::commit();
     } catch (\Exception $e) {
         DB::rollBack();
         $this->error("\n" . $e->getMessage() . "\n");
     }
 }
 /**
  * Updates an existing TaskDefined model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $modelDevice = new Device();
     $modelAction = new Action();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         //return $this->redirect(['view', 'id' => $model->id]);
         return $this->redirect(['task/index']);
     } else {
         return $this->render('update', ['model' => $model, 'from_device_ids' => ArrayHelper::map($modelDevice->getDeviceMaster(), 'id', 'name'), 'to_device_ids' => ArrayHelper::map($modelDevice->getDeviceAll(), 'id', 'name'), 'action_ids' => ArrayHelper::map($modelAction->getActionAll(), 'id', 'name')]);
     }
 }
Ejemplo n.º 3
0
 /**
  * Gets all existing database records for permissions and add them
  * in array, according to the routes array from the getRouteData method
  *
  * @return array
  */
 protected function getAllActions()
 {
     $array = [];
     $permissions = Action::all();
     foreach ($permissions as $permission) {
         $array[$permission->action] = $permission->uri;
     }
     return $array;
 }
Ejemplo n.º 4
0
 public function getAttack($playerHash, $countryIdFrom, $countryIdTo)
 {
     $from = Country::find($countryIdFrom);
     /** @var $from Country */
     $to = Country::find($countryIdTo);
     $player = Player::getByHash($playerHash);
     if ($from->isOwnedBy($player)) {
         Action::attack($from, $to);
     }
 }
 /**
  * Handle search page
  *
  * @param Request $request
  * @return \Illuminate\View\View
  */
 public function getSearch(Request $request)
 {
     $search = $request->input('search');
     $roles = Role::all();
     try {
         $actions = Action::search($this->search($search, ['proximity' => false, 'fuzzy' => 0.1, 'phrase' => false]));
         $data = ['actions' => $actions->get(), 'roles' => $roles, 'search' => $search, 'uri' => 'admin/permissions', 'title' => trans('temp.search_results')];
     } catch (\Exception $e) {
         $data = ['actions' => [], 'roles' => $roles, 'search' => $search, 'uri' => 'admin/permissions', 'title' => trans('temp.search_results')];
     }
     return view('admin.permissions.all', $data);
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Action::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     $query->andFilterWhere(['like', 'data_structure', $this->data_structure]);
     return $dataProvider;
 }
Ejemplo n.º 7
0
 public function search($input)
 {
     $query = Action::query();
     $columns = Schema::getColumnListing('actions');
     $attributes = array();
     foreach ($columns as $attribute) {
         if (isset($input[$attribute]) and !empty($input[$attribute])) {
             $query->where($attribute, $input[$attribute]);
             $attributes[$attribute] = $input[$attribute];
         } else {
             $attributes[$attribute] = null;
         }
     }
     return [$query->get(), $attributes];
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $firstCondition = new Condition(['type' => 'if', 'field' => 'event.type', 'operator' => '==', 'value' => 'push']);
     $firstCondition->save();
     $splitter = new Splitter();
     $splitter->save();
     $firstSplit = new Split();
     $firstSplit->save();
     $secondSplit = new Split();
     $secondSplit->save();
     $secondCondition = new Condition(['type' => 'contains', 'field' => '', 'operator' => '==', 'value' => '']);
     $secondCondition->save();
     $firstAction = new Action(['type' => 'ssh']);
     $host = new Host(['host' => 'ssh', 'port' => '22']);
     $auth = new Auth();
     $accountAuth = new AuthAccount();
     $accountAuth->username = getenv('SSH_USERNAME');
     $accountAuth->password = getenv('SSH_PASSWORD');
     $accountAuth->save();
     try {
         $file = new File();
         $keyAuth = new AuthKey();
         $keyAuth->username = '******';
         $keyAuth->key = $file->get('.docker/builds/ssh/ssh_keys/id_rsa');
         $keyAuth->key_public = $file->get('.docker/builds/ssh/ssh_keys/id_rsa.pub');
         $keyAuth->save();
     } catch (Illuminate\Filesystem\FileNotFoundException $exception) {
         dump("SSH Key Not Found");
     }
     $auth->credentials()->associate($keyAuth);
     $auth->save();
     $host->auth()->associate($auth);
     $host->save();
     $firstAction->host()->associate($host);
     $firstAction->save();
     $firstAction->addCommand('touch testing');
     $firstAction->addCommand('ls');
     $secondAction = new Action();
     $secondAction->save();
     $secondAction->addCommand('composer install');
     $secondCondition->successPipeable()->associate($secondAction)->save();
     $firstSplit->pipeable()->associate($secondCondition);
     $secondSplit->pipeable()->associate($firstAction);
     $splitter->splits()->save($firstSplit);
     $splitter->splits()->save($secondSplit);
     $firstCondition->successPipeable()->associate($splitter)->save();
     $project = new Project();
     $project->name = 'example';
     $project->group = 'exampleGroup';
     $project->url = 'http://localhost/exampleGroup/example';
     $project->project_id = 2;
     $project->save();
     $project->conditions()->save($firstCondition);
 }
Ejemplo n.º 9
0
 public static function getAllowedAction($controllerId, $role_id)
 {
     //TODO: Using cache to speed process
     $output = [];
     foreach (Action::find()->where(["controller_id" => $controllerId])->all() as $action) {
         //bypass for super admin
         if ($role_id == 1) {
             $output[] = $action->action_id;
         } else {
             $roleAction = RoleAction::find()->where(["action_id" => $action->id, "role_id" => $role_id])->one();
             if ($roleAction) {
                 $output[] = $action->action_id;
             }
         }
     }
     return $output;
 }
Ejemplo n.º 10
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = \Faker\Factory::create();
     $maxLat = 34.9456;
     $minLat = 31.2746;
     $maxLng = -85.1266;
     $minLng = -83.2246;
     $actions = ['check_in', 'query', 'comment', 'post'];
     for ($i = 0; $i < 200; $i++) {
         $lat = $faker->randomFloat(4, $minLat, $maxLat);
         $lng = $faker->randomFloat(4, $minLng, $maxLng);
         $created_at = $faker->dateTimeBetween("-1 years", "now");
         $data = ['action' => $actions[$faker->numberBetween(0, 3)]];
         \App\Models\Action::insert(['location' => \DB::raw("ST_SetSRID(ST_PointFromText('POINT(" . $lng . ' ' . $lat . ")'), 4326)"), 'data' => json_encode($data)]);
         $geojson = new \stdClass();
         $geojson->type = "Point";
         $geojson->coordinates = [$lng, $lat];
         $geojsonAction = new \App\Models\GeojsonAction();
         $geojsonAction->location = $geojson;
         $geojsonAction->data = $data;
         $geojsonAction->save();
     }
 }
Ejemplo n.º 11
0
 public function getActionsAll()
 {
     return ArrayHelper::map(Action::find()->all(), 'id', 'name');
 }
Ejemplo n.º 12
0
 public function behaviors()
 {
     //apply role_action table for privilege (doesn't apply to super admin)
     return \app\models\Action::getAccess($this->id);
 }
Ejemplo n.º 13
0
 public function behaviors()
 {
     //NodeLogger::sendLog(Action::getAccess($this->id));
     //apply role_action table for privilege (doesn't apply to super admin)
     return Action::getAccess($this->id);
 }
Ejemplo n.º 14
0
 public function getActionAll()
 {
     // get all the actions
     return Action::find()->asArray()->all();
 }
 /**
  * Finds the Action model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Action the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Action::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Ejemplo n.º 16
0
function getAllChild($role_id, $parent_id = NULL, $level = 0)
{
    foreach (\app\models\Menu::find()->where(["parent_id" => $parent_id])->all() as $menu) {
        ?>
                    <div class="form-group" style="padding-left: <?php 
        echo $level * 20;
        ?>
px">
                        <label>
                            <input type="checkbox" name="menu[]" value="<?php 
        echo $menu->id;
        ?>
" class="minimal" <?php 
        echo isChecked($role_id, $menu->id) ? "checked" : "";
        ?>
>
                        </label>
                        <label style="padding-left: 10px"> <?php 
        echo $menu->name;
        ?>
</label>
                    </div>
                <?php 
        //Show All Actions
        $camelName = Inflector::id2camel($menu->controller);
        $fullControllerName = "app\\controllers\\" . $camelName . "Controller";
        if (class_exists($fullControllerName)) {
            $reflection = new ReflectionClass($fullControllerName);
            $methods = $reflection->getMethods();
            echo "<div class=\"form-group\" style=\"padding-left: " . ($level * 20 + 10) . "px;\">";
            echo "<label><input type=\"checkbox\" class=\"minimal select-all\" ></label><label style=\"padding: 0px 20px 0px 5px\"> Select All</label>";
            foreach ($methods as $method) {
                if (substr($method->name, 0, 6) == "action" && $method->name != "actions") {
                    $camelAction = substr($method->name, 6);
                    $id = Inflector::camel2id($camelAction);
                    $name = Inflector::camel2words($camelAction);
                    $action = \app\models\Action::find()->where(["action_id" => $id, "controller_id" => $menu->controller])->one();
                    if ($action == NULL) {
                        //If the action not in database, save it !
                        $action = new \app\models\Action();
                        $action->action_id = $id;
                        $action->controller_id = $menu->controller;
                        $action->name = $name;
                        $action->save();
                    }
                    showCheckbox("action[]", $action->id, $name, hasAccessToAction($role_id, $action->id));
                }
            }
            echo "</div>";
        }
        getAllChild($role_id, $menu->id, $level + 1);
    }
}
Ejemplo n.º 17
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAction()
 {
     return $this->hasOne(\app\models\Action::className(), ['id' => 'action_id']);
 }