コード例 #1
0
def createNewCustomer(data):
    admin_group = Group(name=data['admin_group'])
    admin_group.save_without_permissions()
    all_employees_group = Group(name=data['all_employees_group'])
    all_employees_group.save_without_permissions()
    company = Company(name=data['name'], admin_group=admin_group, all_employees_group=all_employees_group)

    #Set up email for receiving tickets
    company.email_support  = data['email_support']
    company.email_archive = data['email_archive']

    company.save()

    #Create the admin user
    user = User(first_name=data['adminuser_name'], username=data['adminuser_username'])
    user.set_password(data['adminuser_password'])
    user.company = company
    user.save()

    #Manually give permission to the admin group
    admin_group.grant_role("Admin", admin_group)
    admin_group.grant_role("Admin", all_employees_group)
    admin_group.grant_permissions("ALL", user)

    #Add admin user to admin group
    admin_group.add_member(user)
    admin_group.grant_role("Admin", user)

    #Set the company fields on groups
    admin_group.company = company
    admin_group.save()
    all_employees_group.company = company
    all_employees_group.save()

    #Set permssion for admin_group on company
    admin_group.grant_permissions("EDIT", company)

    #Give admin group all permissions on classes
    admin_group.grant_role("Admin", Project)
    admin_group.grant_role("Admin", Customer)
    admin_group.grant_role("Admin", Contact)
    admin_group.grant_role("Admin", Order)
    admin_group.grant_role("Admin", Invoice)
    admin_group.grant_role("Admin", Offer)
    admin_group.grant_role("Admin", HourRegistration)
    admin_group.grant_role("Admin", Announcement)
    admin_group.grant_role("Admin", Log)
    admin_group.grant_role("Admin", Product)
    admin_group.grant_role("Admin", Notification)
    admin_group.grant_role("Admin", User)
    admin_group.grant_role("Admin", Ticket)
    admin_group.grant_role("Admin", Group)

    #Give employee group some permissions on classes
    all_employees_group.grant_role("Member", Project)
    all_employees_group.grant_role("Member", Customer)
    all_employees_group.grant_role("Member", Contact)
    all_employees_group.grant_role("Member", HourRegistration)
    all_employees_group.grant_role("Member", Product)
    all_employees_group.grant_role("Member", Offer)
    all_employees_group.grant_role("Member", Invoice)
    all_employees_group.grant_role("Member", Order)
    all_employees_group.grant_role("Member", Announcement)
    all_employees_group.grant_role("Member", Log)
    all_employees_group.grant_role("Member", Ticket)
    all_employees_group.grant_role("Member", Notification)

    #Manually give som other permissions
    all_employees_group.grant_permissions("CREATE", HourRegistration)
    all_employees_group.grant_permissions("CREATE", Contact)

    return company, user
コード例 #2
0
ファイル: seed.py プロジェクト: frecar/focus
def createNewCustomer(admin_group, adminuser_name, adminuser_password, adminuser_username, all_employees_group, name):
    admin_group = Group(name=admin_group)
    admin_group.save_without_permissions()
    all_employees_group = Group(name=all_employees_group)
    all_employees_group.save_without_permissions()
    company = Company(name=name, admin_group=admin_group, all_employees_group=all_employees_group)
    company.save()

    # Create the admin user
    user = User(first_name=adminuser_name, username=adminuser_username)
    user.set_password(adminuser_password)
    user.company = company
    user.save()

    # Manually give permission to the admin group
    admin_group.grant_permissions("ALL", admin_group)
    admin_group.grant_permissions("ALL", all_employees_group)
    admin_group.grant_permissions("ALL", user)

    # Add admin user to admin group
    admin_group.add_member(user)

    # Set the company fields on groups
    admin_group.company = company
    admin_group.save()
    all_employees_group.company = company
    all_employees_group.save()

    # Give admin group all permissions on classes
    admin_group.grant_role("Admin", Project)
    admin_group.grant_role("Admin", Project)
    admin_group.grant_role("Admin", Customer)
    admin_group.grant_role("Admin", Contact)
    admin_group.grant_role("Admin", Offer)
    admin_group.grant_role("Admin", Invoice)
    admin_group.grant_role("Admin", Order)
    admin_group.grant_role("Admin", get_class("hourregistrations", "hourregistration"))
    admin_group.grant_role("Admin", get_class("hourregistrations", "hourregistrationtype"))
    admin_group.grant_role("Admin", get_class("announcements", "announcement"))
    admin_group.grant_role("Admin", Product)
    admin_group.grant_role("Admin", Log)
    admin_group.grant_role("Admin", Supplier)
    admin_group.grant_role("Admin", Notification)
    admin_group.grant_role("Admin", User)
    admin_group.grant_role("Admin", Group)
    admin_group.grant_role("Admin", Ticket)
    admin_group.grant_permissions("CONFIGURE", Company)

    # Give employee group some permissions on classes
    all_employees_group.grant_role("Member", Project)
    all_employees_group.grant_role("Member", Customer)
    all_employees_group.grant_role("Member", Contact)
    all_employees_group.grant_role("Member", Order)
    all_employees_group.grant_role("Member", Invoice)
    all_employees_group.grant_role("Member", Offer)
    all_employees_group.grant_role("Member", get_class("hourregistrations", "hourregistration"))
    all_employees_group.grant_role("Member", get_class("announcements", "announcement"))
    all_employees_group.grant_role("Member", Product)
    all_employees_group.grant_role("Member", Log)
    all_employees_group.grant_role("Member", Supplier)
    all_employees_group.grant_role("Member", Ticket)
    all_employees_group.grant_role("Member", Notification)

    return company, user
コード例 #3
0
ファイル: seed.py プロジェクト: bopopescu/focus
def createNewCustomer(admin_group, adminuser_name, adminuser_password,
                      adminuser_username, all_employees_group, name):
    admin_group = Group(name=admin_group)
    admin_group.save_without_permissions()
    all_employees_group = Group(name=all_employees_group)
    all_employees_group.save_without_permissions()
    company = Company(name=name,
                      admin_group=admin_group,
                      all_employees_group=all_employees_group)
    company.save()

    #Create the admin user
    user = User(first_name=adminuser_name, username=adminuser_username)
    user.set_password(adminuser_password)
    user.company = company
    user.save()

    #Manually give permission to the admin group
    admin_group.grant_permissions("ALL", admin_group)
    admin_group.grant_permissions("ALL", all_employees_group)
    admin_group.grant_permissions("ALL", user)

    #Add admin user to admin group
    admin_group.add_member(user)

    #Set the company fields on groups
    admin_group.company = company
    admin_group.save()
    all_employees_group.company = company
    all_employees_group.save()

    #Give admin group all permissions on classes
    admin_group.grant_role("Admin", Project)
    admin_group.grant_role("Admin", Project)
    admin_group.grant_role("Admin", Customer)
    admin_group.grant_role("Admin", Contact)
    admin_group.grant_role("Admin", Offer)
    admin_group.grant_role("Admin", Invoice)
    admin_group.grant_role("Admin", Order)
    admin_group.grant_role("Admin",
                           get_class("hourregistrations", "hourregistration"))
    admin_group.grant_role(
        "Admin", get_class("hourregistrations", "hourregistrationtype"))
    admin_group.grant_role("Admin", get_class("announcements", "announcement"))
    admin_group.grant_role("Admin", Product)
    admin_group.grant_role("Admin", Log)
    admin_group.grant_role("Admin", Supplier)
    admin_group.grant_role("Admin", Notification)
    admin_group.grant_role("Admin", User)
    admin_group.grant_role("Admin", Group)
    admin_group.grant_role("Admin", Ticket)
    admin_group.grant_permissions("CONFIGURE", Company)

    #Give employee group some permissions on classes
    all_employees_group.grant_role("Member", Project)
    all_employees_group.grant_role("Member", Customer)
    all_employees_group.grant_role("Member", Contact)
    all_employees_group.grant_role("Member", Order)
    all_employees_group.grant_role("Member", Invoice)
    all_employees_group.grant_role("Member", Offer)
    all_employees_group.grant_role(
        "Member", get_class("hourregistrations", "hourregistration"))
    all_employees_group.grant_role("Member",
                                   get_class("announcements", "announcement"))
    all_employees_group.grant_role("Member", Product)
    all_employees_group.grant_role("Member", Log)
    all_employees_group.grant_role("Member", Supplier)
    all_employees_group.grant_role("Member", Ticket)
    all_employees_group.grant_role("Member", Notification)

    return company, user