Are there any hooks for user modification events in google apps? - google-apps-script

Currently the bane of my existence is dealing with users email signatures at work, changing names, titles, departments, new users...it's all annoying. Currently I manage it with GAM and a semi templated HTML file to push changes, which works okay, but it's still a manual process. What I'm looking to do is create a small app script or app engine project that can...
detect a new or changed user
pull the fields needed to fill in their signature template
push the changes to their account
2 & 3 are no problem at all, it's #1 that I cannot find a reasonable solution to.
I had thought about using the google apps audit settings to email a specific mailbox when a new user is created, but that will only catch new users, not changes in titles and such. My only apparent option is something that runs periodically checking all the users signatures against what my script would generate and updating if needed, but that's hardly efficient and creates a potential timelapse in the waiting period meaning when people want things 'done now' (which is of course, every request), it will mean I manually trigger the job; effectively bringing me back to my original solution.
Is there any kind of user feed that contains changes available in google apps? Maybe google has a POST hook that hits a predefined URL on changes?

You can probably use push notifications for this https://developers.google.com/drive/web/push using the users.watch method https://developers.google.com/admin-sdk/directory/v1/reference/users/watch

Related

Create a dynamic ICS file that users can subscribe to

We have a website that users login to, and can then book on to courses. These courses and the bookings are stored in our SQL database against the user's UserID. On the course page the user is able to add the course to their Outlook calendar via a simple ICS file that is generated when the user clicks on the button to add it by submitted the required data into the ICS file within the URL that calls it and then using <%=Request("CourseName")%> in the ICS file itself.
We are now looking to create a new ICS file that a user can subscribe to that will update their Outlook calendar with all of the courses they have signed up for, and will automatically update if/when a course has a change applied to it or if the user signs up to a new course then this will also automatically be added to their calendar. I can work out how to generate an ICS file that will hold all of this data using a similar setup to what I have done for the individual courses above, but I cannot work out how to create an ICS file that automatically updates with new information.
I don't know if I need to;
1. Have a hardcoded ICS file stored on the server for each individual user that is then updated as and when a change is made (I would prefer to avoid this as we have a lot of users)
2. If there is a way I can include a SQL statement within an ICS file that will then get the latest course data for the user on the fly (this is preferred, but testing this option so far has always resulted in errors)
3. Something else I have not thought of yet
Any help would be appreciated on this!
Here is the approach we are using to solve a similar problem:
Every time an admin changes an event or a user changes their subscription, we trigger an API call to do two things: (1) notify the relevant users of the changes using an auto-generated iCalendar event (.ics), and (2) update the database with the changes.
We opted to give the users and the administrators the power to trigger event-changes, rather than have a timer that checks and sends out updates, because we wanted to avoid the lag.
As to your question about auto-generating, this requires you to create an event_id, which you re-use in the .ics file, along with a METHOD:REQUEST, which notifies the user's email that you are sending a: (a) new event, or (b) change to a prior event. If you build a dynamic iCalendar script, this is possible. You must capture the "changes" and flow them through to a new .ics request.

How to reload gmail add-on through background process using app-script

May i get some help on the below points where i am using app-script to develop a gmail add-on:
How can we refresh gmail add-on with back ground process?
=> Here is my case, I need to display card with multiple sections which is the process of hitting multiple apis to fetch data and to display the card. For this initially we will show a card with minimal information to the user once i get information from api, i need to update the basic cards with complete information.
How can we trigger a function on every mail thread open?
=> Currently it works once for a mail, here as explained above point need to refresh a card once we fetch the data. If not, user will be seeing same basic information card every time he opens the mail.
From above mentioned issues for point one we are trying to get solution where we can hit service for certain interval of time to check data availability and if data exists then fetch data and update cards, i mean to say need a setTimeout function kind of thing, unfortunately we did'nt found this in app script and We found sleep/waitLock functions in app-script, but my services may take little time to fetch data as it connects though multiple services so we cant make the user to wait until the whole process is to be completed. So that we will show a card with basic information required then after need to auto refresh the cards once we fetch the data. we tried of keeping refresh button for the user to click and fetch the updated data but here we are losing user experience, trying for auto refresh with out user interference to get updated information.
Need a process / solution where we can auto refresh the card with out user interference after the data available at our end instead of making user to wait until the process to be completed.
Earliest reply will be more helpful for us.
Thanks.
If a data status on a third-party backend changes as the result of a user interaction with your add-on UI, it is recommended that the add-on set a 'state changed' bit to true so that any existing client side cache is cleared. See the ActionResponseBuilder.setStateChanged() method description for additional details.
The card-based interface in Gmail Addons is an Apps Script Service.
You can interlink it with other Apps Script services as well as implement API calls - everything within the same Apps Script file.
Gmail Addons contents automatically update every time the user opens a different e-mail or refreshes his browser.
Within your Apps Script code you can install time-driven triggers to run the data availability check with a customized frequency.
Consider to install for your users an Auto Refresh extension if you do not want them to refresh the card themselves.

Security of GAS for G-sites?

I want to create a script that runs on a Google site. The script would perform a specialized calculation for a given user and then display the answer for the user. The script would depend upon user input, but the code itself should not be viewable by the user. I want the code to exist in a "black box" so that the calculation formula can be kept secret. Is this possible?
I searched the documentation, but only found this, which does not address this question:
https://developers.google.com/apps-script/guides/services/authorization#permissions_and_types_of_scripts
Whether your App script is embedded in a site or written as a standalone script does not change a lot of things... the only difference will be the way you include it on a page as a gadget.
If it is embedded it will be available from a list of scripts in the page editing, if not you'll have to use the .exec url of the deployed webapp.
Anyway, that does not change the way people will have access to the app.
You can define these parameter when you deploy the app (which is mandatory in both cases), allowing for anonymous access or requiring to be logged in.
If I understood you correctly, you would like to restrict the access to some people but not share the code.
Depending on how you defined the access mode above and wether you are using a Google Apps inside a domain or not, you will be able to do it using 2 ways :
in a domain you can get the logged user identity and use that to accept/deny showing the app.
in a "normal" gmail account you will have to implement some sort of logging feature to request a user name and password to give access to the active part of the app.
In both case you never need to share the script itself, this sharing parameter is independent from the webapp access.
I hope I understood your question correctly... if not, feel free to comment.
You might check out the Private Functions section of the following page.....the example is similar to what you're referring to, I think.
https://developers.google.com/apps-script/guides/html/communication?hl=ru
I don't fully understand how they work and haven't used them myself, but I bookmarked it to figure out later. Maybe another user who understands Private Functions better can explain...

How to give write permissions only to UI app to write data to a Spreadsheet

I have developed a web application using Google scripts UIApp class which will collect the data of work done by each associate and writes data to my spreadsheet.
Problem I'm facing is I have to share my spreadsheet to all the associates with write permission where it enables them to see others data. I want to hide this sheet from all but they should also be able write data using the web application I shared.
Please let me know for more details or any code snippets
Note: I have Not used Google Form because I need change the list values dynamically based on the selection and the type of user.
You can deploy the app you have built with UiApp to be executed as "you" and allow access to anyone. The spreadsheet won't need to be shared anymore but as it is anyone (even anonymous if you are not in a domain) will be able to use it...
You'll have to implement an access control yourself, again this will be different in a domain or in a "normal" gmail account (in a domain you can get the user email, in a gmail account you can't)
(since apparently I can't comment.. but to follow up on this question.)
Is there a best practice for running as something other than really-yourself?
Say a team is managing it, or your a contractor who won't stay with the company, and so you're account and access is likely to go away.
I assume it results in creating a shared account, or perhaps a groups or something? You start getting into all sorts of ACL issues. And a simple ``run as yourself'' doesn't seem like a good long term solution.

When does Google require re-authentication?

I am using a script that sends an email whenever a user submits a form. Since the script is using my Google account to send the emails, I have to authorize it and that makes sense. However, my scripts eventually stop working (seemingly)randomly and requires re-authentication. The most recent occurrence happened today, one of my scripts requires authentication even though it states that the last edit happened 4 days ago.
Basically, I understand why I have to authenticate, but what makes me have to re-authenticate?
Scripts that use more sensitive apis like Gmail will force a reauth on every code change. Otherwise, you shouldn't need a reauth unless you use a new api, or if you start writing when in the past you were only reading (basically, if you do something beyond the scope of what was previously authorized).
Changes to the script will require you to re-authorize. And something as simple as adding a space to your code counts as a change. Many times these are inadvertent.