Thanks you for sharing an educational segment. As being a self taught dev your video has helped me put together a thought that I think I might just be able to build.
This link ( support.google.com/drive/answer/2494893#zippy= ) Talks about how to share files, give certain permissions, prevent others from sharing the file and schedule access to the file. You can protect sheet tabs and cells as an editor or owner: yagisanatode.com/google-sheets-beginners-protecting-cells-ranges-and-sheet-tabs-23/ To protect a script bound to a Google Sheet you will need to publish it as a Google Editor Add-on.
@@yagisanatode thank you for your answer, me I need to share my sheet to people that will use it, so they need to edit it, but I don't want they copy the formulas or the script... I don't find the way.
Hi, thanks so much for the explanation. I'm a bit confused regarding the actual fileID. Should the fileID be kept hard coded or can we get the fileID of the file from where the doGet() is triggered (for ex., if there is another spreadsheet with a button that triggers the web app URL). If we do the second option (getting the fileID dynamically), would that mean that anybody who has the web app URL would be able to get access to it and be validated?
You could definitely parse a file ID as an event parameter. It a users has the ability to use a menu item or button in your Google Sheet they will have edit access to that sheet. Validation relies on the getEditors() method of the effective user ( The person attempting to access the WebApp). If their Google credentials do not contain the required permission to access the add-on then they will be redirected to the no access page.
HI. Thanks a lot, very useful. Just when I do the call file = DriveApp.getFileById(fileID); in validate function, the returned value is undefined. I'm sure I have access to the document referenced by the id ? an Idea? Thanks
Hi Gianfranco, that is weird. It's difficult to see what is going on without seeing your code. The only thing I suggest for now is that you double check your variables match and the file ID is correct.
i have ran this many times, and i cant get to work with individual emails, when i added groups in validation, then it worked. could you try please? take off groups in sharing and test. thanks
Hi Perry, Retested the code as requested and it's working as expected my end. It's difficult to see what's going on your side without looking your code and your deployment setup. For the time being you can grab the script from the written tutorial: yagisanatode.com/2021/08/18/how-to-validate-specific-users-on-a-web-app-in-google-apps-scripts/ . If you are still stuck feel free to comment in the written tutorial with your code or send me an email using the contact form from my site with a link to a version of your script. When/If I get a chance I will try and take a look at it.
Hi thanks for the video, however Im running through a problem, I tried to debug the code through running 'console.log('file editors',file.getEditors()); ' and its returning 'file editors [ {}, {} ]' array of empty objects. Whats the problem?
Hi Ahmed, check out the full written tutorial, it might help you out a bit more: yagisanatode.com/2021/08/18/how-to-validate-specific-users-on-a-web-app-in-google-apps-scripts/ getEditors() gives you a constructor array of all editors. Each editor in this array has its own methods, one of these is getEmail(). If you say console.log() this: ``` file.getEditors().map(editor => { return editor.getEmail(); }) })(); ``` Then you will get a list of all the editors by email. Hope this helps. Happy coding. ~Yagi
Fabulous video! one question; so, what happens when the file is shared to everyone with no specific email, in that case there is no shared list to, would it recognize the validation for any google account holder?
Yeah, it is a bit of a pain but I get why Google is protecting itself. Your best bet is to embed the Web App in a site. The fastest way would be to create a quick and free Google Site at sites.google.com and use the embed tool there. The warning will disappear.
Hi Subarna, You could use the Javascript Switch method for more than on condition here to allow for two or more correct cases. You would need to return either false if not authorized and then a value for each of your true cases from the validation.
Thanks you for sharing an educational segment. As being a self taught dev your video has helped me put together a thought that I think I might just be able to build.
Hi Michael. That is really heartwarming to hear. Thank you for the kind words.
Hello, do you know how to protect a google sheet with a licence ? Or protect the cells formulas, or protect the script ? Thank you dude.
This link ( support.google.com/drive/answer/2494893#zippy= ) Talks about how to share files, give certain permissions, prevent others from sharing the file and schedule access to the file.
You can protect sheet tabs and cells as an editor or owner: yagisanatode.com/google-sheets-beginners-protecting-cells-ranges-and-sheet-tabs-23/
To protect a script bound to a Google Sheet you will need to publish it as a Google Editor Add-on.
@@yagisanatode thank you for your answer, me I need to share my sheet to people that will use it, so they need to edit it, but I don't want they copy the formulas or the script... I don't find the way.
Hi, thanks so much for the explanation. I'm a bit confused regarding the actual fileID. Should the fileID be kept hard coded or can we get the fileID of the file from where the doGet() is triggered (for ex., if there is another spreadsheet with a button that triggers the web app URL). If we do the second option (getting the fileID dynamically), would that mean that anybody who has the web app URL would be able to get access to it and be validated?
You could definitely parse a file ID as an event parameter. It a users has the ability to use a menu item or button in your Google Sheet they will have edit access to that sheet. Validation relies on the getEditors() method of the effective user ( The person attempting to access the WebApp). If their Google credentials do not contain the required permission to access the add-on then they will be redirected to the no access page.
@@yagisanatode Great! Thanks a lot
is it possible that it doesnt recognize me as an editor cause im the Owner of the file?
Great tutorial, how would you go about calling an webApp restricted to a domain. How do you set up the authorization?
Hi there, you could validate the effective user against the domain in their email.
HI. Thanks a lot, very useful. Just when I do the call file = DriveApp.getFileById(fileID); in validate function, the returned value is undefined. I'm sure I have access to the document referenced by the id ? an Idea? Thanks
Hi Gianfranco, that is weird. It's difficult to see what is going on without seeing your code. The only thing I suggest for now is that you double check your variables match and the file ID is correct.
i have ran this many times, and i cant get to work with individual emails, when i added groups in validation, then it worked. could you try please? take off groups in sharing and test. thanks
Hi Perry, Retested the code as requested and it's working as expected my end. It's difficult to see what's going on your side without looking your code and your deployment setup. For the time being you can grab the script from the written tutorial: yagisanatode.com/2021/08/18/how-to-validate-specific-users-on-a-web-app-in-google-apps-scripts/ . If you are still stuck feel free to comment in the written tutorial with your code or send me an email using the contact form from my site with a link to a version of your script. When/If I get a chance I will try and take a look at it.
@@yagisanatode tyvm for you reply, i will try the link you provided, if i get stuck, i will let you know. Can i email you just in case?
@@perrysantos Sure you can send me a message here: yagisanatode.com/contact/ . Time permitted I will take a look,
@@yagisanatode my bad.. i just realized this works only within Google Workspace organisation.. sorry to caused a confusion...
That's awesome. Thank you!
Hi thanks for the video, however Im running through a problem, I tried to debug the code through running 'console.log('file editors',file.getEditors()); ' and its returning 'file editors [ {}, {} ]' array of empty objects. Whats the problem?
Hi Ahmed, check out the full written tutorial, it might help you out a bit more: yagisanatode.com/2021/08/18/how-to-validate-specific-users-on-a-web-app-in-google-apps-scripts/
getEditors() gives you a constructor array of all editors. Each editor in this array has its own methods, one of these is getEmail(). If you say console.log() this:
```
file.getEditors().map(editor => {
return editor.getEmail();
})
})();
```
Then you will get a list of all the editors by email.
Hope this helps.
Happy coding.
~Yagi
It is amazing Thank you!
Glad you found it useful.
Fabulous video! one question; so, what happens when the file is shared to everyone with no specific email, in that case there is no shared list to, would it recognize the validation for any google account holder?
Emails are still referenced by Google in this case, so if you have a list of users you want approved, you will still be good to go.
Awesome! Nice to know, thanks...
Great Video 🙂
Thanks!
nice ! How do you remove the annoying grey warning bar ?
Yeah, it is a bit of a pain but I get why Google is protecting itself. Your best bet is to embed the Web App in a site. The fastest way would be to create a quick and free Google Site at sites.google.com and use the embed tool there. The warning will disappear.
@@yagisanatode Thanks, I will try that !
@@yagisanatode 5 minutes test and it worked, ty !
How to use two html file if user is correct ?
let htmlfile = (isValid)? 'home' :'NonUser';
HERE !!!
Hi Subarna, You could use the Javascript Switch method for more than on condition here to allow for two or more correct cases. You would need to return either false if not authorized and then a value for each of your true cases from the validation.
@@yagisanatode I tried this and if person;s id is authorized it opens home.html & when home redirects to another page it doesn't how to fix it ?