Parse-Server cloud code can't create Role - parse-server

I have a class called Project for which I create a Parse.Role for read/write permissions.
Here's how I create my Role:
var roleName = "hasSound_" + ident;
var projectRole = new Parse.Role(roleName, new Parse.ACL());
projectRole.getUsers().add(creator);
return projectRole.save().then(function(role) {
var acl = new Parse.ACL();
acl.setReadAccess(role, true); //give read access to Role
acl.setWriteAccess(role, true); //give write access to Role
project.setACL(acl);
project.save();
});
And here's the bad request I'm getting when trying to create the Parse.Role:
Mar 04 14:39:32 ancient-lake-41070 heroku/router: at=info method=POST path="/parse/classes/_Role" host=ancient-lake-41070.herokuapp.com request_id=82af3849-842a-406f-8a4b-5f573e08a1e1 fwd="54.145.36.110" dyno=web.1 connect=0ms service=6ms status=400 bytes=578

So apparently I needed to add useMasterKey to all my save functions. In a .save() function it is the second parameter, like so: obj.save(null, {useMasterKey: true})
Once I did that, the Role was created, all my relations are working again, etc.
See here for more info: https://github.com/ParsePlatform/parse-server/issues/37

Related

I want to get recipient_signing_uri from the Docusign API response but it returns null

Here is the code
public function send(Request $request): object
{
$apiClient = new ApiClient();
$apiClient->getOAuth()->setOAuthBasePath(env('DS_AUTH_SERVER'));
try {
$accessToken = $this->getToken($apiClient);
} catch (\Throwable $th) {
return back()->withError($th->getMessage())->withInput();
}
$userInfo = $apiClient->getUserInfo($accessToken);
$accountInfo = $userInfo[0]->getAccounts();
$apiClient->getConfig()->setHost($accountInfo[0]->getBaseUri() . env('DS_ESIGN_URI_SUFFIX'));
$envelopeDefenition = $this->buildEnvelope($request);
try {
$envelopeApi = new EnvelopesApi($apiClient);
$result = $envelopeApi->createEnvelope($accountInfo[0]->getAccountId(), $envelopeDefenition);
dd($result);
} catch (\Throwable $th) {
return back()->withError($th->getMessage())->withInput();
}
return view('backend.response')->with('result', $result);
}
When I print $result variable it returns a response like this
container: array:8 [
"bulk_envelope_status" => null
"envelope_id" => "b634f8c5-96c5-4a18-947f-59418d8c4e03"
"error_details" => null
"recipient_signing_uri" => null
"recipient_signing_uri_error" => null
"status" => "sent"
"status_date_time" => "2023-02-16T07:24:39.1570000Z"
"uri" => "/envelopes/b634f8`your text`c5-96c5-4a18-947f-59418d8c4e03"
]
I want to get the value of recipient signing uri in response but in my case it returns null
How I can achieve this? Will anyone suggests?
createEnvelope creates the envelope. It does not give you an URL for an embedded recipient view (signing ceremony). In order to get that URL, you need to make an additional call to
EnvelopeViews:createRecipient/
See this page for more info.
Also
$apiClient->getConfig()->setHost($accountInfo[0]->getBaseUri() . env('DS_ESIGN_URI_SUFFIX'));
You are using the first entry in the UserInfo returned data's accountInfo array. That's not a good idea. Instead, look for the entry that is the user's default account.
Or if your application is designed to work with a specific eSign account, then make sure the user has access to that account.
It is very common for DocuSign customers to have access to more than one account.

Get roles by name in a 'guildMemberAdd' handler

Since member.guild.roles.get('roleName') no longer works. I'd like to know if there's an alternative to it.
message.guild.roles.cache.find(role => role.name == 'My Role Name') is not an option, since I don't have access to message object inside the 'guildMemberAdd' handler.
My code works fine using the role id, but I'd like to make it usable for other servers.
** updating my question
This is my code:
const role1 = 'the id number here'; ---> this one I'd like to be by name
const role2 = 'the id number here');
if (collected.first().emoji.name === '😎') {
member.roles.add(role1);
} if (collected.first().emoji.name === '🟩'){
member.roles.add(role2);
} else { return}
You can access the guild from GuildMember
client.on('guildMemberAdd', member => {
// member.guild.roles.cache.find(...) - Callback similar to Array#find()
// member.guild.roles.cache.get(...) - string id parameter only
});

how to change the created by <user> in log to OdooBot when creating a record using odoo external API

I'm trying to create a new lead from external landing page
The code work as expected so far on Odoo 13.0+e-20200524
url = ODOO_URL
db = ODOO_DB
username = ODOO_USERNAME
password = ODOO_PASSWORD
kwargs = {
'name': 'hello world',
}
common = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(url))
uid = common.authenticate(db, username, password, {})
print(uid)
models = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url))
id = models.execute_kw(db, uid, password, 'crm.lead', 'create', [{
'name': kwargs.get('name'),
'user_id': 1,
}])
print(id)
But the log of the lead showing that my user created that lead (which is properly right)
Change the created user to OdooBot in the view - screenshot
My question is:
How can I change the created user to OdooBot instead of my user?
PS: I already searched around and tried bellow parameters without luck:
'user_login': "OdooBot",
'create_uid': [1],
'write_uid': [1],
uid represent a key role of User to create a record using xmlrpc.
You can change uid and it will log with that User.

get user role by user id in moodle

I want to get user role from user id. I am using loop in my code where i want to show all user except admin. i used below code but its not working.
$context = get_context_instance (CONTEXT_SYSTEM);
$roles = get_user_roles($context, $USER->id, false);
$role = key($roles);
$roleid = $roles[$role]->roleid;
Its provide me blank array as like screenshot. Also below my all code.
https://prnt.sc/gq8p12
$allUsers = $DB->get_records('user');
$SQL = "SELECT * FROM `".$CFG->prefix."config` WHERE `name` LIKE 'siteadmins'";
$getSiteAdmins = $DB->get_record_sql($SQL);
$explodeAdminIds = explode(',', $getSiteAdmins->value);
$context = get_context_instance (CONTEXT_SYSTEM);
if(!empty($allUsers))
{
foreach ($allUsers as $allUser)
{
if(!in_array($allUser->id, $explodeAdminIds))
{
$roles = get_user_roles($context, $allUser->id, false);
$role = key($roles);
$roleid = $roles[$role]->roleid;
echo 'USER ID -- '.$allUser->id.' >>> ';
print_r($roles); echo '<br>';
$name = ''.$allUser->id.'_'.$allUser->firstname.' '.$allUser->lastname.'';
$confirmed = ($allUser->confirmed == 1) ? 'Active' : 'In-active';
$table->data[] = array(
$i,
$name,
'Team Name',
$allUser->email,
$allUser->phone1,
'Role',
$confirmed,
//empty($coachusrarr)?'--':implode(',',$coachusrarr),
//empty($tmpleaderarr)?'--':implode(',',$tmpleaderarr),
//$coach,
);
$i++;
}
}
}
The basic problem is that get_user_roles($context, $userid) will only get you a list of roles assigned at that particular context level. Very few users have roles assigned at the system context, it is much more usual for roles to be assigned at a course level. This allows users to have different roles in different courses (a teacher on one course, might be enrolled as a student on another course).
If you want to get all the roles for a user, then you're going to need to do something like this:
$roleassignments = $DB->get_records('role_assignments', ['userid' => $user->id]);
You can then loop through all the $roleassignments and extract the 'roleid' from them (alternatively, you could use the $DB->get_fieldset command, to extract the roleids directly).
Note also that you should be using context_system::instance() instead of the old get_context_instance(CONTEXT_SYSTEM) (unless you are using a very old and insecure version of Moodle).
For getting the site admins, use get_admins() (or, if you really want to access the config value, use $CFG->siteadmins).
If you want to get a user role for a course by user id then this script will help you.
$context = context_course::instance($COURSE->id);
$roles = get_user_roles($context, $USER->id, true);
$role = key($roles);
$rolename = $roles[$role]->shortname;

How to serialise ember date?

I'm new to ember and I want to post a new record, So I did something like:
App.AdminController = Em.Controller.extend
submit: ->
post = App.Post.createRecord()
post.set('author', $('#author').val())
post.set('title', $('#title').val())
post.set('intro', $('#intro').val())
post.set('description', $('#description').val())
post.set('publishedAt', new Date())
post.get('store').commit()
Everything works like a charm, except the publisedAt attribute e in post request json file is null
I think the problem is due to that I may not serialise it correctly, any idea?
update the model:
App.Post = DS.Model.extend
title: DS.attr('string')
author: DS.attr('string')
intro: DS.attr('string')
description: DS.attr('string')
publishedat:DS.attr('date')
Try using JSON.stringify on the Date object:
post.set('publishedAt', JSON.stringify(new Date()))
For some reason, you can't invoke new Date() inside the .set method. This should work:
var d = new Date();
post.set('publishedAt', d);