def init(): manager = LibraryManager(True) for key in lib_to_user: manager.add_link(key, lib_to_user[key]) users = UserGroup('pknu', True) for user_data in user_pknu: sid, pw, name = user_data users.add_user(sid, pw, name) pklib = Library('대연/중앙도서관', True) for section_id in data_pklib: qr_codes = data_pklib[section_id] pklib.add_section(section_id, qr_codes)
def new_from_json(cls, ugm_json, correlation_id): """ Full process of creating validating and persisting new membership record. Creates new object as specified by JSON, checks that user and group exist and that membership does not currently exist in database :param ugm_json: MUST contain: user_id, user_group_id, may OPTIONALLY include: id, created, modified :param correlation_id: :return: new ugm object, will raise errors for invalid data """ if ("user_group_id" not in ugm_json) and ("url_code" in ugm_json): url_code = ugm_json["url_code"] user_group = UserGroup.get_by_url_code(url_code, correlation_id) if user_group is not None: ugm_json["user_group_id"] = user_group.id if (user_group.testing is False) and user_group.sister_testing_group_id: tasks_statuses = [x["status"] for x in user_group.tasks] if tasks_statuses == ["testing"] * len( tasks_statuses ): # if all statuses are testing ugm_json["user_group_id"] = user_group.sister_testing_group_id else: # url_code not found errorjson = { "url_code": url_code, "correlation_id": str(correlation_id), } raise utils.ObjectDoesNotExistError( "user group url_code does not exist", errorjson ) try: ugm = UserGroupMembership.from_json(ugm_json, correlation_id) ugm.validate(correlation_id) ugm.insert_to_db(correlation_id) return ugm except Exception as err: raise err
def __init__(self, match_expr): self._type, self.expr = match_expr.split(':') if self._type == 'u': self.is_match = lambda user: self.expr == user elif self._type == 'r': self.is_match = lambda user: not re.match(self.expr, user) is None elif self._type == 'g': self.is_match = lambda user: UserGroup.ismember(user, self.expr) else: raise (Exception('match_expr type error'))
def sign_in(campus, uid, pw): ug = UserGroup(campus)
def get_user_group(self, ug_id): if not (ug_id in self.user_groups.keys()): self.user_groups[ug_id] = UserGroup(ug_id) return self.user_groups[ug_id]
def get_groups(user, user_name): if user != 'admin': return 'this requires admin privileges!' return UserGroup.getGroups(user_name)
def del_group(user, group_name): if user != 'admin': return 'this requires admin privileges!' return UserGroup.delGroup(group_name)
def del_user(user, user_name): if user != 'admin': return 'this requires admin privileges!' return UserGroup.delUser(user_name)
def auth_user(user, passwd): return UserGroup.auth(user, passwd)
def add_user(user, user_name, groups: [str], passwd): if user != 'admin': return 'this requires admin privileges!' return UserGroup.addUser(user_name, groups, passwd)
def is_member(user, user_name, group_name): # IS MEMBER EKLEDIM ~makca if user != 'admin': return 'this requires admin privileges!' return UserGroup.ismember(user_name, group_name)
def set_passwd(user, passwd): return UserGroup.setPassword(user, passwd)
def get_users(user, group_name): if user != 'admin': return 'this requires admin privileges!' return UserGroup.getUsers(group_name)