Yii2 authorization via php and database? - yii2

Is it possible to split authorization such that items, item children, and rules use yii\rbac\PhpManager but assignments use yii\rbac\DbManager?
The use case for this is that items, item children, and rules (at least in my case) are controlled by the app and are essentially 100% static. The only time they will be updated is if new items are added to existing roles. Assignments, however, are tied to users and are very dynamic.
The idea is to keep the static items out of the database (thus not requiring migrations for updates) but still having dynamic items (assignments) stored in the database.

You can caching queries to items, item children, and rules tables.
In components section of config:
'authManager' => [
'class' => 'yii\rbac\DbManager',
'cache' => 'cache' //Here is your cache
],
'cache' => [
'class' => 'yii\caching\FileCache',
],

Related

Incomplete JSON data on GET request in ASP.NET Core

Why I get not all data from base by link
https://localhost:XXXXX/api/comments
(GET request)
After update page data no longer appears ..
Responce:
[{"id":1,"text":"Comment1","userId":1,"parentCommentId":null,"user":null,"parentComment":null,"childrenComments":null},{"id":2,"text":"Comment2","userId":1,"parentCommentId":1,"user":null,"parentComment":{"id":1,"text":"Comment1","userId":1,"parentCommentId":null,"user":null,"parentComment":null,"childrenComments":[
Does not load subordinate item ..
What am I doing wrong?
// GET: api/Comments
[HttpGet]
public IEnumerable<Comment> GetComments()
{
return _context.Comments;
}
You must load the relationships as well. The two primary ways of doing that are eager-loading via Include or lazy-loading. However, lazy-loading should be avoided in general, and especially so in cases like this. When you're serializing an object, you could end up issuing hundreds or even thousands of queries inadvertently with lazy-loading.
Long and short, add Include clauses for the relationships you care about:
return _context.Comments
.Include(x => x.User)
.Include(x => x.parentComment)
.Include(x => x.childrenComments);
If you want more flexibility, you can employ either OData or GraphQL. Either will allow the client to selectively include the relationships they want/need, meaning you won't necessarily need to join everything every time.

opencart duplicate shipping methods

I've just duplicated the flat and free shipping methods.
I've changed everything in all the files (litteraly everything from flat to flat2 etc)
I've cleared all caches, including the modifications and vqmod cache, but I can't enable the duplicated methods.
When I echo to test when trying to activate I get:
Array(
[shipping_flat_cost] => 19
[shipping_flat_tax_class_id] => 0
[shipping_flat_geo_zone_id] => 6
[shipping_flat_status] => 1
[shipping_flat_sort_order] => )
So it still refers to flat instead of flat2.
Have I missed something?
Thanks!

Kendo suppress DatePicker

We're using Kendo with ASP.NET MVC. I have a Kendo grid with several different columns. Two columns contain times. Though they are DateTime objects, we only display their time components. When users select to filter one of these columns, along with the blank text entry box, they have the DatePicker, which lets them choose a date by month/day. Clearly this makes no sense for a Time of day.
Is there a way to suppress the DatePicker? Ideally they'd have the TimePicker to use, but we could live without it. I've seen several examples that show how to do this with JavaScript, but nothing for MVC. Is it even possible with MVC?
We're doing all the sorting and filtering on the server (SQL server) because we do server-side paging (we dont' want to load 1,000,000 rows, just to display a few). So we're not relying on Kendo for the sorting and filtering, just the UI.
Other things we've tried:
Changing the times to strings. This gets rid of the DatePicker, but then the filter options include operators that make sense for strings, but not necessarily times. And the time operators are missing ("Is before", "Is after", etc.).
Building the filter options ourselves: This was an attept after we changed the DateTimes to strings. This only allows us to add filters that make sense for strings, not DateTimes.
Here's an example of our Razor markup. Pretty standard stuff:
#(Html.Kendo().Grid<FModel>()
.Name("FStuff")
.Columns(c =>
{
c.Bound(m => m.Date);
c.Bound(m => m.Location);
c.Bound(m => m.Name);
c.Bound(m => m.PurchaseOrderID);
c.Bound(m => m.Start); // time column
c.Bound(m => m.End); // time column
})
.Pageable(p => p
.Enabled(true)
.PageSizes(new List<int> { 10, 25, 999 })
.Refresh(true))
... other options ...
Does anyone have an idea of the approach we should take? Is what we want to do possible with Kendo?
On your time columns, configure the .Filter() options like this:
c.Bound(x => x.Start).Filterable(f => f.UI(GridFilterUIRole.TimePicker))
You may also want to consider setting the format with .Format("{0:t}") (or whatever format you prefer)

Change the way CakePHP associate models

I'm trying to split out some JSON strings in order to be parsed by this RestKit's iPhone library, but CakePHP is splitting out an incompatible string. For example, the string below is what it's currently splitting out:
1. {"Question":{"id":"1","content":"Test","player_id":"1","points":"0","votes":"0","created":"0000-00-00 00:00:00"},"Player":{"id":"1","username":"player_test"}}
I need to have something like:
2. {"Question":{"id":"1","content":"Test","player_id":"1","points":"0","votes":"0","created":"0000-00-00 00:00:00","Player":{"id":"1","username":"player_test"}}}
Note that the Player response should be part of Question.
The way the models are setup on Cake is that 'Question' belongs to 'Player' which the latter hasMany 'Question'
I am looking for the proper way of telling Cake to output something like the response #2 above. Any suggestions?
You can use afterFind() callback of your Question model to nest the Player record inside the Question record. Or modify the results array as required after fetching. The various function of Hash class might help you in reformatting the array.
You can add a custom method to your Question model that returns the result in the desired format. This will keep your code clean and keep the data-processing/formatting logic in your Model (where it should be in most cases);
For example, inside your Question model:
public function getQuestionsForPlayer($playerId)
{
$results = $this->find('all', array(
'fields' => array(/* fields */),
'conditions' => array(/* ..... */
/* etc */
));
// Process your result to be in the right format
// Hash::extract() and other Hash:: methods
// may be helpful here as #ADmad mentioned
return $processedResult;
}
As ADmad mentioned, the Hash utility may be helpful. Documentation is located here:
http://book.cakephp.org/2.0/en/core-utility-libraries/hash.html

Real URL configuration with postVarSets

Here is a snippet from my Realurl configuration:
'postVarSets' => array (
'_DEFAULT' => array (
'package' => array (
'0' => array (
'GETvar' => 'packageid',
),
),
What does this code do? Does this retrieve a POST variable called package? And in the array there is a variable packageid?
I'm searching for a path element called package which redirects to a certain page, but I doesn't quite know how this works ..
The whole RealURL configuration is about telling RealURL how to encode/decode URLs. postVarSets is one of the configuration options that uses a keyword to identify a part of the URL.
In your case it tells RealURL that if there's a keyword package in the URL, the first thing that follows this keyword should be set as a GET variable packageid. So URL...
http://www.example.com/page-uid-1/package/123
...should be equivalent to...
http://www.example.com/index.php?id=1&packageid=123