Authorize dataset to access another dataset - python-3.x

What I have right now is I am authorizing using views. Now, I want to access all the underlying data inside a dataset.
view_dataset: '***'
view_table: '***'
table_dataset: '***'
view_string = "view={'projectId': '" + view_project + "', 'datasetId': '" + view_dataset + "', 'tableId': '" + view_table + "'}"
view_source = bigquery.Table(view_project + '.' + view_dataset + '.' + view_name)
dataset = client.get_dataset(table_project + '.' + table_dataset)
access_entries = dataset.access_entries
table_source = bigquery.Dataset(table_project + '.' + table_dataset)
access_entries.append(bigquery.AccessEntry(None, "view", view_source.reference.to_api_repr()))
table_source.access_entries = access_entries
table_source = client.update_dataset(table_source, ["access_entries"])
How will I be able to authorize view_dataset to access table_dataset programmatically?

To anyone who wants to authorize programatically, here is how I did it:
Create an entity ID for the dataset:
entity_id = {
'dataset': {
'projectId': table_project,
'datasetId': view_dataset,
},
'target_types': 'VIEWS'
}
Then, instead of view, use dataset:
access_entries.append(bigquery.AccessEntry(None, "dataset", entity_id))
I've managed to do this by reading the AccessEntry class on dataset.py of BigQuery.
If the ``entity_type`` is 'dataset', the ``entity_id`` is a ``dict``
that includes a 'dataset' field with a ``dict`` representing the dataset
and a 'target_types' field with a ``str`` value of the dataset's resource type:
{
'dataset': {
'projectId': string,
'datasetId': string,
},
'target_types: 'VIEWS'
}

Related

I'm sending a generated pdf from my server to the client as a base64 pdf string. I'm trying to print it on the client side using printJS

I'm generating a report using fluentreports on my server and sending the base64 pdf string to the client on the callback. On the client once he/she receives the base64 string, I am required to print out this pdf string as a pdf which I am trying to accomplish using printJS. I also tried pdfMake but neither one wanted to work. If I console.log the base64 string and click on it, the pdf opens beautifully in the next tab but once I try to print it using printJS or pdfMake it opens a new tab and automatically closes it without doing anything. Is there any other way I could accomplish this? I've tried a lot of things already from reading up on other peoples' issues online and haven't gotten anywhere. Is there any library out there that can create a PDF document using a base64 pdf string so that I can use printJS to print out the document?
Function on the client that sends info to the server and receives back the pdf string:
submit: function () {
this.$Socket.emit('addrepair', {
CustomerID: this.$route.params.Customer.CustomerID,
Problem: this.problem,
BrandID: this.brand,
TypeID: this.type,
Model: this.model,
ColorID: this.color,
Warranty: this.convertbool(this.warranty),
Purchased: this.convertbool(this.purchase),
RushService: this.convertbool(this.rush),
DateReceived: this.datereceived,
UserID: this.UserID
}, (data) => {
if(data.authenticated==true)
{
//window.open(data.pdf)
//pdfMake.createPdf(this.convertDataURIToBinary(data.pdf)).print()
console.log(data.pdf)
printJS({printable: data.pdf, type: 'pdf'})
this.jobdialog=true
}
})
Function on the server that serves the pdf base64 string:
socket.on('addrepair', (data, callbackfn) => {
let query="INSERT INTO repair(CustomerID, Problem, BrandID, Model, ColorID, Warranty, Purchased, RushService, DateReceived, TypeID, UserID) VALUES (" + data.CustomerID + ", \'" + data.Problem + "\', " + data.BrandID + ", \'" + data.Model + "\', " + data.ColorID + ", " + data.Warranty + ", " + data.Purchased + ", " + data.RushService + ", \'" + data.DateReceived + "\', " + data.TypeID + ", " + data.UserID + ");"
con.query(query, function(err) {
if(err) {
throw err
}
else
{
query="SELECT RepairID, FirstName, LastName, Address, PhoneNumber, RushService, Purchased, DateReceived, Problem, Model, (SELECT Type from types WHERE repair.TypeID=types.TypeID) as Type, (SELECT Color from colors WHERE repair.ColorID=colors.ColorID) as Color, (SELECT Brand from brands WHERE repair.BrandID=brands.BrandID) as Brand, Warranty from repair INNER JOIN customer ON repair.CustomerID=customer.CustomerID WHERE repair.RepairID=(SELECT LAST_INSERT_ID())"
con.query(query, function(err, rows) {
if(err) {
throw err
}
else
{
var options = {
data: rows
}
//var myreport = new Report("buffer", options)
var myreport=new Report.Report("buffer", options)
.data(rows)
.pageHeader(repairheaderFunction)
.detail(repairdetailFunction)
.pageFooter(repairfooterFunction)
myreport.render(function (err, data) {
callbackfn({authenticated: true, pdf: 'data:application/pdf;base64,' + data.toString('base64')})
})
//callbackfn({authenticated: true, data: rows})
}
})
}
})
})
var repairheaderFunction = function(Report, data) {
};
var repairdetailFunction = function(Report, data) {
Report.print("#" + data.RepairID, {fontSize: 22, bold: true, underline:true, align: "center"});
Report.newLine(2);
Report.print('First Name: ' + data.FirstName + "\n")
Report.print('Last Name: ' + data.LastName + "\n")
Report.print('Address: ' + data.Address + "\n")
Report.print('Phone Number: ' + data.PhoneNumber + "\n")
Report.print('Brand: ' + data.Brand + "\n")
Report.print('Model: ' + data.Model + "\n")
Report.print('Color: ' + data.Color + "\n")
Report.print('Problem: ' + data.Problem + "\n")
Report.print('Date Received: ' + data.DateReceived.slice(15) + "\n")
/*.text('Last Name: [LastName]\n')
.text('Address: [Address]\n')
.text('Phone Number: [PhoneNumber]\n')
.text('Brand: [Brand]\n')
.text('Model: [Model]\n')
.text('Color: [Color]\n')
.text('Problem: [Problem]\n')
.text('Date Received: [DateReceived]', 1.75, 0, 1, 0.25, {
pattern: 'M/D/YY'
})*/
};
var repairfooterFunction = function(Report) {
Report.line(Report.currentX(), Report.maxY()-18, Report.maxX(), Report.maxY()-18);
Report.pageNumber({text: "Page {0} of {1}", footer: true, align: "right"});
Report.print("Printed: "+(new Date().toLocaleDateString()), {y: Report.maxY()-14, align: "left"});
};
Print.js is now supporting base64 PDF print.
Try this:
printJS({
printable: your_base64_data_string,
type: 'pdf'
base64: true
})
The documentation has been updated with an example printing a base64 PDF document.
http://printjs.crabbly.com#pdf
Was able to get this to work after a lot of playing around with the code and thinking of possible solutions. Generates the iframe, pulls up the print dialog using the autoprint property of the report and then deletes the iframe once the focus is on the document again using the 'mousemove' event
The code is below:
printIframe: function(url) {
var proxyIframe = document.createElement('iframe');
var body = document.getElementsByTagName('body')[0];
body.appendChild(proxyIframe);
proxyIframe.style.width = '100%';
proxyIframe.style.height = '100%';
proxyIframe.id='iframe'
proxyIframe.style.display = 'none';
var contentWindow = proxyIframe.contentWindow;
contentWindow.document.open();
// Set dimensions according to your needs.
// You may need to calculate the dynamically after the content has loaded
contentWindow.document.write('<iframe src="' + url + '" width="1000" height="1800" frameborder="0" marginheight="0" marginwidth="0">');
contentWindow.document.close();
var x=0
var func=function (event) {
if(x===0)
{
body.removeChild(proxyIframe)
++x
}
else
{
document.removeEventListener('mousemove', func)
}
}
contentWindow.document.body.onload=() => {
contentWindow.document.body.focus()
setTimeout(()=>{
document.addEventListener('mousemove', func)
}, 5000)
}
},

getting name of steam user from id

I'm using npm package steam-user
I'm stuck on getting steam name from steam id, I tried this:
var name;
client.getPersonas([sid], function(personas) {
var persona = personas[sid];
name = persona ? persona.player_name : ("[" + sid + "]");
});
console.log(config.console_userMessageReceived + "(" + name + " | " + sid + "): " + message);
However when the variable name is printed in console, its printed as undefined. Any help how to solve this, and print the actual steam name?
Seems like you have asynchronous call. Try this:
var name;
client.getPersonas([sid], function(personas) {
var persona = personas[sid];
name = persona ? persona.player_name : ("[" + sid + "]");
console.log(config.console_userMessageReceived + "(" + name + " | " + sid + "): " + message);
});

SharePoint List UserCustomAction, In whole sitecollection

I'm getting this to work if I choose a specific list to add the action to. Is there an easy way to enable this custom action on all document libraries in the whole sitecollection?
Code sample:
function createUserCustomActionList() {
var cmd = "<CommandUIExtension><CommandUIDefinitions><CommandUIDefinition Location=\"Ribbon.Documents.Manage.Controls._children\">" +
"<Button Id=\"DiaryAction.Button\" TemplateAlias=\"o1\" Command=\"DiaryCommand\" CommandType=\"General\" LabelText=\"Dela flera\" Image32by32=\"https://eolusvind.sharepoint.com/sites/intranet/_layouts/15/1033/Images/formatmap32x32.png?rev=23\"" +
" Image32by32Top=\"-271\" Image32by32Left=\"-109\" />" +
"</CommandUIDefinition></CommandUIDefinitions><CommandUIHandlers>" +
"<CommandUIHandler Command =\"DiaryCommand\" CommandAction=\"javascript:alert('Hej');\" EnabledScript=\"javascript:SP.ListOperation.Selection.getSelectedItems().length > 1;\" />" +
"</CommandUIHandlers></CommandUIExtension>";
var ctx = new SP.ClientContext.get_current();
var list = ctx.get_web().get_lists().getByTitle('Dokument');
var uca = list.get_userCustomActions();
var oUserCustomAction = uca.add();
oUserCustomAction.set_location('CommandUI.Ribbon.ListView');
oUserCustomAction.set_commandUIExtension(cmd);
oUserCustomAction.set_sequence(100);
oUserCustomAction.set_title('Dela flera');
oUserCustomAction.update();
ctx.load(list, 'Title' ,'UserCustomActions');
ctx.executeQueryAsync(function () {
alert('Custom action created for ' + list.get_title())
}, function (sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
});
}
I would suggest the following approach for registering custom button in Documents libraries across site collection:
use RegistrationType set to 2(ContentType) and RegistrationId set to 0x0101 (for Document content type) to register custom action via content type
use site scope user custom action to apply changes across all site
collection
Example
var cmd = "<CommandUIExtension>" +
"<CommandUIDefinitions>" +
"<CommandUIDefinition Location=\"Ribbon.Documents.Manage.Controls._children\">" +
"<Button Id=\"ClickAction.Button\" TemplateAlias=\"o1\" Command=\"ViewCustomPropertiesCommand\" CommandType=\"General\" LabelText=\"View Custom Properties\" Image32by32=\"/_layouts/15/1033/Images/formatmap32x32.png?rev=23\" Image32by32Top=\"-1\" Image32by32Left=\"-171\" />" +
"</CommandUIDefinition></CommandUIDefinitions><CommandUIHandlers>" +
"<CommandUIHandler Command =\"ViewCustomPropertiesCommand\" CommandAction=\"javascript:console.log('View Custom Properties');\" EnabledScript=\"javascript:SP.ListOperation.Selection.getSelectedItems().length > 0;\" />" +
"</CommandUIHandlers>" +
"</CommandUIExtension>";
var ctx = new SP.ClientContext.get_current();
var customAction = ctx.get_site().get_userCustomActions().add(); //1. apply via site scope user custom action
customAction.set_location('CommandUI.Ribbon.ListView');
customAction.set_commandUIExtension(cmd);
customAction.set_sequence(112);
customAction.set_registrationType(2); //2.set to ContentType
customAction.set_registrationId("0x0101"); //2.set Document content type
//customAction.set_title('Document custom button');
customAction.update();
ctx.executeQueryAsync(function () {
console.log('Button has been registered');
}, function (sender, args) {
console.log('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
});

How to leave from group chat using node-xmpp

This doesn't work. Here cl is xmpp-client object of who wants to leave from group.
cl.on('online', function (userData) {
var userJid = userData.jid.user + '#' + userData.jid.domain + "/" + userData.jid.resource,
roomJid = params.typeId + params.service + userData.jid.domain + '/' + params.userName;
pres = new xmpp.Element('presence', {
from : userJid,
to : roomJid, //54d213e000e9e50c4e8e5a2b#conference.domain/nickName
type : 'unavailable',
xmlns : 'jabber:client'
});
status = cl.send(pres);
});

SailsJS How to apply sort by on an instance method and instance method which is populated from another model?

Hi consider this example
// surname_and_name: function(){
// return (this.name_last==null ? '' : this.name_last + ' ') +
// (this.name_middle==null ? '': this.name_middle + ' ') +
// (this.name_first==null ? '' : this.name_first + ' ') +
// (this.name_prefix==null ? '' : this.name_prefix + ' ') +
// (this.name_suffix==null ? '' : this.name_suffix);
// },
toJSON: function() {
var obj = this.toObject();
obj.surname_and_name = (obj.name_last==null ? '' : obj.name_last + ' ') +
(obj.name_middle==null ? '': obj.name_middle + ' ') +
(obj.name_first==null ? '' : obj.name_first + ' ') +
(obj.name_prefix==null ? '' : obj.name_prefix + ' ') +
(obj.name_suffix==null ? '' : obj.name_suffix);
return obj;
}
i am trying to query and sort it by "surname_and_name" computed field.
i tried commented code as well, i get this error, for method
co_user.find(sort : {surname_and_name: 'asc' }).exec(error,res)
Error: ER_BAD_FIELD_ERROR: Unknown column 'co_user.surname_and_name' in 'order clause'
The toJSON method is called when sending model data back from the server, not during queries. Therefore, the surname_and_name property is not available during queries; only real model attributes can be used as query parameters. If this kind of sort is important to you, I'd recommend making an actual surname_and_name attribute for your model which gets automatically calculated every time the model is saved, using the model class's afterCreate() and afterUpdate() lifecycle callbacks.

Resources