G Suite: add users in child Organizational unit to Group automatically - google-admin-sdk

When I add a new user to a child OU, how can I also add this user to the corresponding group automatically?
My scenario is that I have a Teachers child OU, when I add a new teacher, I also want to add the new teacher to the all_teachers group, so that:
we can send email to all_teachers.
all_teachers group is in the "classroom_teachers" group so that they can create a classroom.
What's the best way to achieve this? Thanks.

On a high level, you could do the following:
Fetch the users of the OU via the Admin Directory service.
Fetch the members of the group.
Compare the two and create an array of users' email address to be added.
Add the members to the group via the Admin Directory service.
There are some script samples that will help you get started at the Apps Script Reference's page on the Admin Directory advanced service.

Related

How do I create a Team Leader/Group Leader in Django?

I'm new(this is my first project) to web development. I'm creating an internal data management for the company i work for. We have different departments(like r&d, product development, etc) which I have instantiated as objects via Django admin. I have created employees as normal Users in django admin. I would like to know how I can create a model/anything which can tell me the department manager.
Django auth user has reference to the group model. So you can create a group called Teamleader in group table(django admin) and while creating a user link the user to the group desired for his role

How to creating Accounts and Contacts programatically?

I want to create an Account programmatically and then create a number of Contacts programmatically and associate them with the Account.
We have a number of vTiger instances that run on the same server and I am building a custom manager to add Accounts and Contacts to targeted vTiger instances.
In the custom manager the workflow is a user can select the target vTiger instance from a select menu, this action fills out some details in the custom manager form. On submitting this form the system navigates to the targeted vTiger instance and creates the account and contact.
I had a look at the Webservice tutorial but with our infrastructure we would prefer to avoid HTTP. I can (folder) navigate to a vTiger instance and invoke a class. I can then pass an array to that class to create the Account or Contact. This way we are reducing security risks by using HTTP and everything is internal.
Could anyone point me in the right direction?
To create an Account you can create a function will contains this:
(You must include all mandatories fields)
global $current_user;
include_once 'modules/Accounts/Accounts.php';
$my_account = new Accounts();
$my_account->column_fields['accountname'] = $accountName;
$my_account->column_fields['accounttype'] = $accountType;
$my_account->column_fields['email1'] = $email;
$my_account->column_fields['assigned_user_id'] = $current_user->id;
$my_account->save('Accounts');
To update an existing Account:
$moduleName = 'Accounts';
$recordModel= Vtiger_Record_Model::getInstanceById($accountId,$moduleName);
$recordModel->set('accountname', $myNewAccountName);
$recordModel->set('mode', 'edit');
$recordModel->save();

Rolling out own permission app or modifying django permission

I am working on a project which needs a separate admin interface. The django admin interface is for the super super user, there will be companies who will sign up for our app and then they will have their own admin interface. Everything is set and done despite the permission. We want model level permission that's what Django provides.
What I did is:
class CompanyGroup(models.Model):
name = models.CharField(max_length=254)
permissions = models.ManyToManyField(Permissions)
Now this list all the permissions of the site itself. So, Should I start working on my own permission app or I can modify django Permissions to provide object level permissions for only some models.
Thanks
Try one of the several existing 'row level' / 'per object' permissions apps for Django:
http://django-guardian.readthedocs.org/en/v1.2/
http://django-object-permissions.readthedocs.org/en/latest/
...there are probably others, those are just the first two in Google
We are using django-guardian in current project at work, seems fine.
I am assuming that you need to control access to sub-sets of each model's objects, depending on which company the current user belongs to (i.e. you don't want people from Company A to see items from Company B). For this reason you need row level permissions.
You probably also need to limit the permissions of all 'company users' to only certain actions:
You do not need to create a CompanyGroup class.
Instead just enable the admin site, log in as super user and create a django.contrib.auth.models.Group which contains the global permissions applicable to company users.
then ensure when you create any new company user logins that they are added to that Group

Django user groups only for permissions?

I'm a bit unsure what to use Django user groups for.
I have an application where every user belongs to a different organisation. The organisations don't have anything to do with read/write permissions. It's just a way to separate groups of users. Every organisation needs some additional fields, like a name, URL, and email address. New organisations will be added to the system over time.
Within every organisation, users can have different permissions for moderation and administration, for which I (also) want to use user groups.
My question: Should I use Django's user groups to define the organisations, or should I just make an 'Organisation' model with a relation to the user?
Nope. User groups are made for different reasons. You CAN use them to define organisations but I think you should think bit further ahead:
will the organisation require more fields than just name?
perhaps you will need permissions in the future to define users roles within organisations?
I'm sure you can come up with more things to think of. But if you answered yes to one of those questions then just create your Organisation model.
1) You need to add group from django admin side under group table.
2) And while creating new user, assign specific group to user using user_obj.groups.add(group_id). Or Let user select group at frontend.
and then user_obj.save()
in Group table, you can create organization
OR
You can create individual organization table and assign assign user to specific organization.

Django auth system: adding user to group via "invites"

I want to use the Django default auth system to manage users and groups. Is there an existing Django app/module that adds users to groups by invites? I.e. some existing user of the group sends an invite with a secret key in a URL, and another user that clicks on the URL joins the group.
I can write one, but figured I ask before doing that.
Thanks.
I am not sure if this will solve all your problems but do take a look at Pinax. They have features to support user invitation and user groups.