def add_accessPolicy2Proxy(policyResource, policyProxy_id, policyProxy_type, precedence, policyStartDate=None, policyEndDate=None): """add an access policy to a role/group, policyGroup, or tariff. There must be only 1 AccessPolicy per policyResource-policyProxy combination, for a particular period (no overlapping periods). """ policyProxy = obj_of_type(policyProxy_type, policyProxy_id) location = policyProxy.place if policyResource.place != location: raise ValueError("access_policies can only arbitrate access to resources that are in the same location as the PolicyProxy which confers it") kwargs = {'policy_resource':policyResource.id, 'location':location.id, 'precedence':precedence} kwargs['policyStartDate'] = policyStartDate and policyStartDate or date.min kwargs['policyEndDate'] = policyEndDate and policyEndDate or date.max if isinstance(policyProxy, Group): proxy_attr = 'group' elif isinstance(policyProxy, PolicyGroup): proxy_attr = 'policygroup' elif isinstance(policyProxy, Resource) and policyProxy.type == 'tariff': proxy_attr = 'tariff' else: raise ValueError("policy proxy is not of type ['Group, PolicyGroup', 'Resource'] OR it is a resource which is not of type 'tariff'. It is a "+ `type(policyProxy)`) kwargs[proxy_attr] = policyProxy.id conflict = AccessPolicy.select(AND(AccessPolicy.q.policy_resourceID == kwargs['policy_resource'], AccessPolicy.q.__getattr__(proxy_attr+'ID') == policyProxy.id)) if conflict.count(): raise ConflictingPolicy return create_object('AccessPolicy', **kwargs)
def create_openTime(pol_id, openTimeDay, openTimeStartDate, openTimeDate, openTimeStart, openTimeEnd): """create a new open time object """ if not check_time_data(openTimeDay, openTimeStartDate, openTimeDate, openTimeStart, openTimeEnd): raise "not good openTime data" if openTimeDay is not None and not openTimeStartDate: openTimeStartDate = datetime.date.min return create_object('Open', policy=pol_id, openTimeStartDate=openTimeStartDate, openTimeDay=openTimeDay, openTimeDate=openTimeDate, openTimeStart=openTimeStart, openTimeEnd=openTimeEnd)
def update_locations(): from hubspace.utilities.object import create_object from hubspace.openTimes import create_default_open_times, add_accessPolicy2Proxy from hubspace.model import Location, Group for location in Location.select(): cal = create_object('Resource', type='calendar', time_based=1, active=0, place=location.id, name='calendar', description='calendar') location.calendar = cal.id for level in ['member', 'host', 'director']: group = Group.select(AND(Group.q.level == level, Group.q.placeID == location.id))[0] access_policy = add_accessPolicy2Proxy(cal, group.id, 'Group', 5, None, None) create_default_open_times(access_policy)
def addUser2Group(user=None, group=None, book=True): if user not in group.users: kwargs = {'user':user, 'group':group} create_object('UserGroup', **kwargs) return 'ok'
def new_group(**kwargs): group = create_object('Group', **kwargs) group_name = group.group_name print 'Created ', group_name create_permissions_for_group(group) return group
def add_policy_group(name, description, location): policy_group = create_object('PolicyGroup', **{'name':name, 'description':description, 'place':location}) return policy_group