def action(self): import datetime emp = self.object.UserID if emp.isblacklist == 1: raise Exception(_(u'黑名单不能处理离职恢复!')) emp.__class__.can_restore = True emp.isblacklist = None emp.status = STATUS_OK emp.Hiredday = datetime.datetime.now().strftime("%Y-%m-%d") emp.save() emp.__class__.can_restore = False #下载到设备 newObj = self.object.UserID from mysite.iclock.models.dev_comm_operate import sync_set_userinfo, sync_set_user_privilege, sync_set_acc_user_fingerprint #-----2012.02.02 xiaoxiaojun #sync_set_user(newObj.search_device_byuser(), [newObj]) accdev = newObj.search_accdev_byuser() #查询出人员对那些设备具有操作权限 sync_set_userinfo(accdev, [newObj]) #同步人员基本信息到设备 sync_set_acc_user_fingerprint(accdev, [newObj]) #同步人员指纹信息到设备 sync_set_user_privilege(accdev, [newObj]) #下放人员权限到设备 from base.sync_api import SYNC_MODEL if not SYNC_MODEL: # 离职恢复 from mysite.iclock.models.model_cmmdata import adj_user_cmmdata adj_user_cmmdata(newObj, [], newObj.attarea.all()) self.object.delete()
def sync_level_door_edit(dev, session_key=""): clear_progress_cache(dev, session_key) #progress end tol = len(dev) * 10 cur = 0 for d in dev: #cur+=1 sync_total_progress(d.alias, tol, cur, session_key) d.set_fqueue_progress(0, session_key) cur_progress = 0 sync_delete_user_privilege([d], '*') #先删除该设备中的所有人员的权限*代表删除全部 cur += 2 cur_progress += 2 sync_total_progress(d.alias, tol, cur, session_key) #progress d.set_fqueue_progress(20, session_key) emp_list = d.search_accuser_bydevice() cur += 2 cur_progress += 2 sync_total_progress(d.alias, tol, cur, session_key) #progress d.set_fqueue_progress(40, session_key) sync_set_acc_user([d], emp_list, session_key) cur += 3.0 cur_progress += 3.0 sync_total_progress(d.alias, tol, cur, session_key) #progress d.set_fqueue_progress(cur_progress * 10, session_key) sync_set_user_privilege([d], emp_list, session_key) #再同步所有人的新权限 cur += 3.0 cur_progress += 3.0 sync_total_progress(d.alias, tol, cur, session_key) d.set_fqueue_progress(cur_progress * 10, session_key) d.set_fqueue_progress(100, session_key) time.sleep(2) end_sync_userinfo(session_key) #结束progress return
def sync_userinfo(devs, objs, session_key=""): #print "sync_userinfo=", session_key tol = len(devs) * 2 cur = 0 for dev in devs: cur += 1 sync_total_progress(dev.alias, tol, cur, session_key) sync_set_user([dev], objs, session_key) cur += 1 sync_total_progress(dev.alias, tol, cur, session_key) sync_set_user_privilege([dev], objs, session_key) time.sleep(1) end_sync_userinfo(session_key) return 0
def sync_userinfo(devs, objs, session_key=""): #print "sync_userinfo=", session_key tol=len(devs)*2 cur=0 for dev in devs: cur+=1 sync_total_progress(dev.alias, tol, cur, session_key) sync_set_user([dev], objs, session_key) cur+=1 sync_total_progress(dev.alias, tol, cur, session_key) sync_set_user_privilege([dev], objs, session_key) time.sleep(1) end_sync_userinfo(session_key) return 0
def emp_level_op(request): mode = request.GET.get("func", '') #删除某个权限组中某个或某些人员 if mode == "level": level_id = request.GET.get("data", 0) emps = request.GET.get("emps" ,'') emps = emps.split(',') level = AccLevelSet.objects.filter(pk = int(level_id)) level_obj = level and level[0] or None #level_obj实际不为空 if level_obj: for e in emps: level_obj.emp.remove(int(e)) dev=[] level_door=level_obj.door_group.all() for door in level_door: if door.device not in dev: dev.append(door.device) emp_set=Employee.objects.filter(pk__in = emps) sync_delete_user_privilege(dev, emp_set) sync_set_user_privilege(dev, emp_set) return HttpResponse(smart_str({ 'ret': 1 })) else: return HttpResponse(smart_str({ 'ret': 0 })) #删除某个人员中某个或某些权限组 if mode == "emp": emp = request.GET.get("data", 0) levels = request.GET.get("levels", '') levels = levels.split(',') emps = Employee.objects.filter(pk = int(emp)) emp_obj = emps and emps[0] or None #emp_obj实际不为空 #print levels if emp_obj: for level in levels: emp_obj.acclevelset_set.remove(int(level)) level_set=emp_obj.acclevelset_set.filter(pk__in = levels) dev=[] for level in level_set: for door in level.door_group.all(): if door.device not in dev: dev.append(door.device) sync_delete_user_privilege(dev, [emp_obj]) sync_set_user_privilege(dev, [emp_obj])#删除设备权限后需重新同步设备人员权限 return HttpResponse(smart_str({ 'ret': 1 })) else: return HttpResponse(smart_str({ 'ret': 0 }))
def emp_level_op(request): mode = request.GET.get("func", '') #删除某个权限组中某个或某些人员 if mode == "level": level_id = request.GET.get("data", 0) emps = request.GET.get("emps", '') emps = emps.split(',') level = AccLevelSet.objects.filter(pk=int(level_id)) level_obj = level and level[0] or None #level_obj实际不为空 if level_obj: for e in emps: level_obj.emp.remove(int(e)) dev = [] level_door = level_obj.door_group.all() for door in level_door: if door.device not in dev: dev.append(door.device) emp_set = Employee.objects.filter(pk__in=emps) sync_delete_user_privilege(dev, emp_set) sync_set_user_privilege(dev, emp_set) return HttpResponse(smart_str({'ret': 1})) else: return HttpResponse(smart_str({'ret': 0})) #删除某个人员中某个或某些权限组 if mode == "emp": emp = request.GET.get("data", 0) levels = request.GET.get("levels", '') levels = levels.split(',') emps = Employee.objects.filter(pk=int(emp)) emp_obj = emps and emps[0] or None #emp_obj实际不为空 #print levels if emp_obj: for level in levels: emp_obj.acclevelset_set.remove(int(level)) level_set = emp_obj.acclevelset_set.filter(pk__in=levels) dev = [] for level in level_set: for door in level.door_group.all(): if door.device not in dev: dev.append(door.device) sync_delete_user_privilege(dev, [emp_obj]) sync_set_user_privilege(dev, [emp_obj]) #删除设备权限后需重新同步设备人员权限 return HttpResponse(smart_str({'ret': 1})) else: return HttpResponse(smart_str({'ret': 0}))
def sync_level_timeseg_edit(dev, session_key=""): clear_progress_cache(dev, session_key) tol = len(dev) * 2 cur = 0 for d in dev: duser = d.search_accuser_bydevice() cur += 1 sync_total_progress(d.alias, tol, cur, session_key) #progress sync_delete_user_privilege([d], duser) cur += 1 sync_total_progress(d.alias, tol, cur, session_key) #progress sync_set_user_privilege([d], duser, session_key) end_sync_userinfo(session_key) #结束progress return
def sync_level_timeseg_edit(dev, session_key=""): clear_progress_cache(dev, session_key) tol=len(dev)*2 cur=0 for d in dev: duser=d.search_accuser_bydevice() cur+=1 sync_total_progress(d.alias, tol, cur, session_key) #progress sync_delete_user_privilege([d], duser) cur+=1 sync_total_progress(d.alias, tol, cur, session_key) #progress sync_set_user_privilege([d], duser, session_key) end_sync_userinfo(session_key) #结束progress return
def clear_authorize(self): #print self.door_group.all(), self.emp.all() devs = [] if self.emp.all() is not None: for door in self.door_group.all(): if door.device not in devs: devs.append(door.device) #add progress clear_progress_cache(dev) tol = len(devs) * 2 cur = 0 for dev in devs: cur += 1 sync_total_progress(dev.alias, tol, cur) #progress end sync_delete_user_privilege([dev], self.emp.all()) cur += 1 sync_total_progress(d.alias, tol, cur) #progress sync_set_user_privilege([dev], self.emp.all()) end_sync_userinfo()
def clear_authorize(self): #print self.door_group.all(), self.emp.all() devs=[] if self.emp.all() is not None: for door in self.door_group.all(): if door.device not in devs: devs.append(door.device) #add progress clear_progress_cache(dev) tol=len(devs)*2 cur=0 for dev in devs: cur+=1 sync_total_progress(dev.alias,tol, cur) #progress end sync_delete_user_privilege([dev], self.emp.all()) cur+=1 sync_total_progress(d.alias, tol, cur) #progress sync_set_user_privilege([dev], self.emp.all()) end_sync_userinfo()
def sync_level_timeseg_edit(dev, session_key=""): clear_progress_cache(dev, session_key) tol = len(dev) * 4 cur = 0 for d in dev: cur += 1 sync_total_progress(d.alias, tol, cur, session_key) #progress d.set_fqueue_progress(25, session_key) duser = d.search_accuser_bydevice() cur += 1 sync_total_progress(d.alias, tol, cur, session_key) #progress d.set_fqueue_progress(50, session_key) sync_delete_user_privilege([d], duser) cur += 1 sync_total_progress(d.alias, tol, cur, session_key) #progress d.set_fqueue_progress(75, session_key) sync_set_user_privilege([d], duser, session_key) cur += 1 sync_total_progress(d.alias, tol, cur, session_key) #progress d.set_fqueue_progress(100, session_key) time.sleep(2) end_sync_userinfo(session_key) #结束progress return