Authorization::Roles doesn't work in Catalyst app - sql

I've tried use Authorization::Roles in my Catalyst app. Authentication works right but when I use $c->check_user_roles("admin"); it always returns false. What's wrong?
Some config:
store => {
class => 'DBIx::Class',
user_model => 'Mymodel::User',
id_field => 'name',
role_field => 'rolename', # in my table there is the same column
# name undoubtedly
}

If your roles are stored in the users table, use the role_column option. If your roles are stored in a separate table, use the role_relation and role_field options. role_field on its own isn't valid.

Related

How to make a field required for customers but not for administrators in prestashop?

I made a custom field in prestashop.
I would like to know if there is some way to make this field only required on the frontend and not for administrators.
this is my code in Customer class
array('type' => self::TYPE_STRING, 'required' => true, 'size' => 64),
Thanks in advance
Can't think of a quick way to make this possible exactly as you want it, so here are two suggestions:
1 - Remove the 'required' => true from the definition and create some kind of custom validation like if (Tools::getValue('type ') == "") { return false; } in an override of the front office AuthController (Warning: code is completely untested and should definitely be improved, also according to your particular PS version).
2 - Use frontend validation by giving the frontend form field the required attribute (you should do this even if oyu use 1)

Search related data in different data base

I use yii2 to build one app which need to connect some tables. I can join them simply and search for data in related fields. I am doing it by adding the connection like this>
public function getNextTab()
{
return $this->hasOne(NextTab::className(),['id' =>'id_nexttab']);
}
and ask for the data in search model using like this ->
->where ('id'='ok') ->
->joinWith('nextTab')
->joinWith('nextTab.nextTab1')
->joinWith('nextTab.nextTab1.nextTab2');
My problem is when I try to do this with tables from different database. The query is give me error like
SQLSTATE[42S02]: Base table or view not found:
any tips how to pass it? or how to do other way of connection to have the data.
Joining tables from different databases may not be supported by your RDBMS (PostgreSQL for example). But if supported (MSSQL, MySQL) then table names should be prefixed with database name (and schema if needed). You can achieve this in Yii2 using {{%TableName}} syntax in tableName() function.
public static function tableName()
{
return '{{%table_name}}';
}
But be careful with joining tables from different databases if they are located on different servers -- this can be very slow.
If you just want to get related data (joined tables are not used in WHERE) then use with() instead of joinWith(). This will be executed as separate query with IN statement. In most cases this way has a better performance and no problems with different sources (and even different DBMS).
->with('nextTab', 'nextTab.nextTab1', 'nextTab.nextTab1.nextTab2')
Configure your second database component in the application's config.
Override the getDB() function in your ActiveRecord Model to return the second DB component.
This will attach your Model to the secondary DB and allow you to query from the table in secondary DB.
Config sample:
'components' => [
'db2' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=db2',
'username' => 'hello',
'password' => 'world',
],
],
getDB() function override sample:
class Tab extends ActiveRecord
{
public static function getDb()
{
// use the "db2" component
return \Yii::$app->db2;
}
}
Good Luck!

Yii session have prefix

I am maintaining a Yii application, when i am printing Yii session it looks like this:
Array
(
[cb35f057aa124d26e8793014875ce939_id] => 1
[cb35f057aa124d26e8793014875ce939_name] => admin
[cb35f057aa124d26e8793014875ce939__states] => Array()
[cb35f057aa124d26e8793014875ce939email] => webmaster#example.com
[cb35f057aa124d26e8793014875ce939username] => admin
[cb35f057aa124d26e8793014875ce939create_at] => 2013-01-14 07:44:22
[cb35f057aa124d26e8793014875ce939lastvisit_at] => 2013-09-13 06:09:17
[cb35f057aa124d26e8793014875ce939state_id] => 1
)
i don't know where to find this number cb35f057aa124d26e8793014875ce939 so that i can use session data in my method. it is looks like fixed. does anybody know what is it ?
You should use session variables via Yii API which is
Yii::app()->session['var'] = 'something'; //setting a value
echo Yii::app()->session['var']; //reading a value
this is not session ID, this is application specific prefix which can be found by getStateKeyPrefix()
The above numbers are probably set by calling setStateKeyPrefix() function somewhere in the code.
Here is explanation of the function:
setStateKeyPrefix() - Sets a prefix for the name of the session variables storing user session data.
Additionally, you can use getStateKeyPrefix() function to see weather or not prefix is set.
The prefix is the php session id and u can get it by
Yii::app()->session->getSessionID();

Access objects from project in sandbox environment PHP

Is there a way I can access my project under Sandbox? I'm able to use the lookup method, find in order to fetch all the features from a project under the Yahoo! subscription, but how would I be able to do this for projects under Sandbox?
In your PHP code have you used Rally sandbox server URL?
https://sandbox.rallydev.com/
Here is a WebServices URL specific to Sandbox:
https://sandbox.rallydev.com/slm/doc/webservice/
I was able to figure it out. In the query to find specific features, I had to include the query parameter "workspace" to the sandbox reference which is (for 1.43) : "https://rally1.rallydev.com/slm/webservice/1.43/workspace/7189290105.js". I included the reference of the project as well which directly fetched all the features for my project. In addition, if you seek to only fetch features from your specific project and not from the ones on top of it, you have to include the "pageScopeUp" field into the query. You have to set this field to false:
$queryParams = array(
'query' => "",
'fetch' => 'true',
'pagesize' => 100,
'start' => 1,
'workspace' => "https://rally1.rallydev.com/slm/webservice/1.43/workspace/7189290105.js",
'project' => "whatever the project reference is",
'projectScopeUp' => false
);
$results = Connection::rally()->findWithQueryParameters('feature',
$queryParams);

Is it possible to set certain product attributes for a different store view using the Magento API?

We are currently using the Magento API for importing a bunch of products into the store.
But we now run into a problem where some product attributes should be translated into a different language.
And I was wondering if it is possible to do this using the Magento API, because I can't seem to find anything related to that problem.
We currently have 2 store views, 1 for the Dutch version of the site and one for the French version of the site.
Our current import code looks something like this:
$store_id = $soapClient->call($soapSession, 'catalog_product.currentStore', array('nl'));
echo("store_id: $store_id");
$new_product_data = array(
'name' => 'NameInDutch',
'short_description' => 'DescriptionInDutch',
'price' => $price,
'weight' => $weight,
'websites' => array('base'),
'status' => '1'
);
$new_product_id = $soapClient->call($soapSession, 'catalog_product.create', array('simple', 4, $sku, $new_product_data)); // 4 => 'Default' attribute set
$localized_product_data = array(
'name' => 'NameInFrench',
'short_description' => 'DescriptionInFrench'
);
$store_id = $soapClient->call($soapSession, 'catalog_product.currentStore', array('fr'));
echo("store_id: $store_id");
$soapClient->call($soapSession, 'catalog_product.update', array($sku, $localized_product_data ));
Now, the output of the echo statements differs, the first time it's 1 and the second time it's 2, so that doesn't seem to be problem. But apparently it doesn't matter for the API if we set that value.
The result is that on the 'catalog_product.update' call, the name 'NameInFrench' overwrites the default name 'NameInDutch'.
So my question is if something like this is possible using the Magento API, and how one would accomplish this?
Ok, I found the answer, apparently I overlooked a certain line in the Magento API docs, because the solution was right there.
So: you don't need to set the currentStore each time, you just need to append the store id or code to the update array:
$soapClient->call(
$soapSession,
'catalog_product.update',
array($sku, $localized_product_data, 'fr')
);
This works perfectly.