Rules - how to check if user has role(s) - drupal-8

In the module Rules, I try to check if a user has role(s).
So, I add a condition "User has role(s)". In the field "Data selector" (in data selection mode), I add node.uid.entity, in the field roles, I add my
roles ("seller, "buyer"), in the field match roles, I add "OR".
I click on save.
I got this error:
"Expected a entity:user data type for context User but got a entity_reference data type instead."
I don't understand what to put in the field "Data selector".

Related

Acumatica - Creating Custom Usr Field on Purchase Orders for Weight Total

I am trying to add a new field through the customization browser to the Purchase Orders screen (PO301000). I created the field through the New Field button and edited the Data Access slightly to provide a default parameter for the field. Here is the code in the Data Access:
[PXDBDecimal]
[PXDefault(TypeCode.Decimal, "0.0")]
[PXUIField(DisplayName="Weight Total")]
This field will be used to calculate the total weight of the purchase order and I would like it to be stored in the database.
I get this error when publishing:
An error while publishing the database item POOrder
with the message:
Nullable object must have a value.
I have tried changing the PXDBDecimal to a PXDBQuantity. This has to be done through the customization browser and not the database itself because this project will be going on a SaaS hosted site where I do not have access to the database. I have also tried creating the field through the DAC only and I receive this error when trying to open the page:
Invalid column name 'UsrWeightTotal'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Invalid column name 'UsrWeightTotal'.
When reviewing the project xml for the POOrder table entry in the customization I found there were some extra/missing attributes required for a column type of decimal.
There was a MaxLength property and no DecimalLength property. I compared it to adding a new field of type decimal and looked at the project xml to come up with the following:
<Table TableName="POOrder">
<Column TableName="POOrder" ColumnName="UsrWeightTotal" ColumnType="decimal" AllowNull="True" DecimalPrecision="6" DecimalLength="19" IsNewColumn="True" IsUnicode="True" />
</Table>
I bet the error was complaining about the missing DecimalLength value (as a result was null but required for the publish process).

show / Hide Checkbox in apex5.0

I have created a PI, :P1_ID defined as checkbox and added a DA to update a field on specific criteria.
On form, have a :P1_REF_NAME which contain the emailAdd of user who has login
e.g app_user = TESTUSER
:P1_REF_NAME = TESTUSER#TESTING.COM
I want to do something like that the checkbox option should be hidden / disable when User who login access his own record.
Any idea, How is it possible to do that pls?
If P1_REF_NAME contains the username then you could put a Condition on the item of type PL/SQL with expression
:P1_REF_NAME != :APP_USER
Then the item will not be rendered for the user's own record.
However, in your case it seems that the item contains a different value, i.e. the email address associated with the user. Presumably this is held in some table. In that case you can use a condition of type "SQL Not Exists" with an expression something like:
select null
from my_user_table
where username = :APP_USER
and email_address = :P1_REF_NAME

How to check status of invitation?

For each User I want to display his invitation status:
"Invitation Sent" or "Invitation Accepted"
Currently I just check if a field encrypted_password in Users table contains anything.
If it is not - then a user did not registered (accepted an invitation) yet but it was sent to him (otherwise this user's record would not exist in DB)
Is there a more elegant way to do it?
Yes you should take a
is_registered:boolean
column in user table which contains default value "false". Now you just have to do is when user get registered that time you just change value to "true".
when ever you want to check is user registered? just do
#user.is_registered? or current_user.is_registered?
this returns true/false

how to set the default permission name created in Django?

I'm using django 1.6
Now when I define a model, it will create three permissions record for it (can_create, can_update, can_delete).
I'm now adding other permissions on the models (which doesn't matter in this question), and want to make a view to let the user assign them all to users and groups.
Now the problem is:
I want to replace the default name displayed for the three default created permissions.
Is there any way to do this?
Yes there is possibility to create custom permission while creating the models/table in django. But this will create the extra custom permission, by default 3 permission will create i.e( add, change, delete). One can create custom permission by following thing.
class Task(models.Model):
...
class Meta:
permissions = (
("view_task", "Can see available tasks"),
("change_task_status", "Can change the status of tasks"),
("close_task", "Can remove a task by setting its status as closed"),
)
The only thing this does is create those extra permissions when you run manage.py migrate (the function that creates permissions is connected to the post_migrate signal). Your code is in charge of checking the value of these permissions when a user is trying to access the functionality provided by the application (viewing tasks, changing the status of tasks, closing tasks.) Continuing the above example, the following checks if a user may view tasks:
user.has_perm('app.view_task')
One can see the django doc here django permission description
Based on this blog post and this Django ticket, I would say it is not possible and also not advisable to change these codenames (since they are used in the admin). It is however possible to change the human readable name (such as 'Can add permission')
I cannot add comment to the answers already there, hence adding a new answer.
I have been looking for a solution and could not find any. So I just make use of default permissions and use permissions to re-create them and use whatever name and codename you want. Django documentation here
class Foo(models.Model):
title = models.CharField(max_length=250)
class Meta:
default_permissions = ()
permissions = (
("add_foo", "Can add foo"),
("change_foo", "Can change foo"),
("delete_foo", "Can delete foo"),
("view_foo", "Can view foo"),
("list_foo", "Can list all foo")
)

CANNOT_UPDATE_CONVERTED_LEAD, cannot reference converted lead: [Lead__c]

I am getting an error message when I try to instert a custom object into an exisiting lead object.
List<Lead> leads =[select Id from Lead where Email =:lead.Email ];
if(leads.size()>0)
{
Lead existing_lead = new Lead(Id = leads[0].id);
social_account.Lead__c = existing_lead.Id; //social_account is a custom object that
//has a child relationship to lead.
//ie lead is a parent of social_accounts.
update existing_lead;
insert social_account; //if there is an existing lead with same same email,
//i'd like to insert new social_account to an exsiting lead.
}
I am getting this error:
554 System.DmlException: Update failed. First exception on row 0 with id 00Q3000000WW3isEAD; first error: CANNOT_UPDATE_CONVERTED_LEAD, cannot reference converted lead: []
Class.ProcessContact.handleInboundEmail: line 81, column 9
External entry point
even if I comment out the 'update existing_lead', i get a similar error message.
554 System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_UPDATE_CONVERTED_LEAD, cannot reference converted lead: [Lead__c]
Class.ProcessContact.handleInboundEmail: line 82, column 9
External entry point
I would appreciate any suggestions.
regards
This error means that the Lead record has been converted to a Contact. Once converted, the Lead record cannot be updated. The Lead object has an IsConverted property that you can check to see if it has been converted. If IsConverted is true, ConvertedContactId will hold the contact ID of the new Contact record.
Lead Object reference
You cannot update converted Lead by default, but after Sprint 16 release, there is possibility, just you need to setup few things.
-From Setup, enter User Interface in the Quick Find box, then select User Interface then select Enable "Set Audit Fields upon Record Creation" and "Update Records with Inactive Owners" User Permissions.
-From Setup, enter Profiles in the Quick Find box, then select Profiles. Select the profile and then select Set Audit Fields upon Record Creation.
Here you can find more information's about this.