예제 #1
0
 def user_delete(self, info: dict):
     t = time.time()
     user_name = info.get('user_name')
     admin_name = info.get('admin_name')
     info_time = info.get('time')
     if not all([user_name, admin_name, info_time]):
         logger.error('incomplete params')
         return update(), 400, {'Content-Type': 'application/json'}
     admin_check = self.user_collection.find_one({
         'user_name': admin_name,
         'activate': 1
     })
     if not admin_check:
         logger.error("admin user:%s didn't exist" % admin_name)
         return "admin user didn't exist", 400, {
             'Content-Type': 'application/json'
         }
     if admin_check['type'] != 'super_admin' and admin_check[
             'type'] != 'yc_admin':
         logger.error("permission denied %s" % admin_name)
         return update(), 423, {'Content-Type': 'application/json'}
     user_check = self.user_collection.find_one({
         'user_name': user_name,
         'activate': 1
     })
     if user_check['type'] == 'super_admin' and admin_check[
             'type'] == 'super_admin':
         logger.error("permission denied %s" % (info["admin_name"]))
         return update(), 423, {'Content-Type': 'application/json'}
     user_check['activate'] = time.time()
     user_check['update_time'] = t
     self.user_collection.replace_one(
         {
             'user_name': user_name,
             'activate': 1
         }, user_check)
     self.user_log_collection.insert_one({
         'id': {
             'user_id': user_check['_id'],
             'admin_id': admin_check['_id']
         },
         'operator':
         admin_name,
         'user_name':
         user_name,
         'time':
         info_time,
         'action':
         "%s delete user %s" % (admin_name, user_name)
     })
     logger.info("user_del_%s" % (info["user_name"]))
     return update(), 200, {'Content-Type': 'application/json'}
예제 #2
0
 def user_add(self, info: dict):
     t = time.time()
     user_name = info.get('user_name')
     user_pw = info.get('user_pw')
     admin_name = info.get('admin_name')
     user_type = info.get('type')
     info_time = info.get('time')
     if not all([user_name, user_pw, admin_name, user_type, info_time]):
         logger.error('incomplete params')
         return update(), 400, {'Content-Type': 'application/json'}
     admin_check = self.user_collection.find_one({
         'user_name': admin_name,
         'activate': 1
     })
     if not admin_check:
         logger.error("admin user:%s didn't exist" % admin_name)
         return "admin user didn't exist", 400, {
             'Content-Type': 'application/json'
         }
     if admin_check['type'] != 'super_admin' and admin_check[
             'type'] != 'yc_admin':
         logger.error("permission denied %s" % admin_name)
         return update(), 423, {'Content-Type': 'application/json'}
     user_check = self.user_collection.find_one({
         'user_name': user_name,
         'activate': 1
     })
     if user_check:
         return 'user exists', 413, {'Content-Type': 'application/json'}
     res = self.user_collection.insert_one({
         "user_name": user_name,
         "user_pw": user_pw,
         "activate": 1,
         "type": user_type,
         "update_time": t
     })
     self.user_log_collection.insert_one({
         'id': {
             'admin_id': admin_check["_id"],
             'user_id': ObjectId(res.inserted_id)
         },
         'operator':
         admin_name,
         'user_name':
         user_name,
         'time':
         info_time,
         'action':
         "%s add user %s" % (admin_name, user_name)
     })
     logger.info("user_add{%s}" % user_name)
     return update(), 200, {'Content-Type': 'application/json'}
예제 #3
0
    def gui_config_modify(self, info: dict):
        t = time.time()
        gui_no = info.get('gui_no')
        admin_name = info.get('admin_name')
        changed_items = info.get('changed_items')
        info_time = info.get('time')
        if not all([gui_no, admin_name, changed_items, info_time]):
            logger.error('incomplete params')
            return update(), 400, {'Content-Type': 'application/json'}
        gui_check = self.gui_setting_collection.find_one({'gui_no': gui_no})
        admin_check = self.user_collection.find_one({"user_name": info["admin_name"], "activate": 1})
        if not gui_check:
            logger.error("gui_no:%s didn't exist" % (info["admin_name"]))
            return update(), 422, {'Content-Type': 'application/json'}
        try:
            if gui_check["update_time"] != changed_items["update_time"]:
                return update(), 422, {'Content-Type': 'application/json'}

            limit = list(self.el_config_collection.aggregate([
                {'$match': {'gui_no': gui_no}},
                {'$group': {'_id': '$gui_no', 'limit': {'$sum': 1}}}
            ]))
            if limit[0]['limit'] > int(changed_items['el_limit']):
                return update(), 412, {'Content-Type': 'application/json'}
            changed_before = dict()
            changed_after = dict()
            for key, value in changed_items.items():
                if (pre_data := gui_check.get(key)) != value:
                    changed_before[key] = pre_data
                    changed_after[key] = value
                    gui_check[key] = value
            gui_check['update_time'] = t
            self.gui_setting_collection.replace_one({"gui_no": gui_no}, gui_check)
            self.user_log_collection.insert_one({
                'id': {
                    'admin_id': admin_check['_id'],
                    'gui_id': gui_check['_id']
                },
                'operator': admin_name,
                'gui_no': gui_no,
                'time': info_time,
                'action': "change gui_config",
                'changed_before': changed_before,
                'changed_after': changed_after
            })
            logger.info('gui_config_modify')
            return update(), 200, {'Content-Type': 'application/json'}
예제 #4
0
 def permission_modify(self, info):  # TODO: oxxx
     """ info
     {
         "time": 1578900329.842,
         "admin_name": "yc_user",
         "changed_items": [
             {"type": "super_admin", "user_mng": 1, "line_mng": 1, "gui_mng": 1, "threshold_mng": 1, "shift_mng": 1,
              "pic_upload": 1, "update_time": 0},
             {"type": "quality_admin", "user_mng": 0, "line_mng": 0, "gui_mng": 1, "threshold_mng": 1,
              "shift_mng": 0,
              "pic_upload": 1, "update_time": 0},
             {"type": "production_admin", "user_mng": 1, "line_mng": 1, "gui_mng": 1, "threshold_mng": 1,
              "shift_mng": 1,
              "pic_upload": 1, "update_time": 0}
         ]
     }
     """
     t = time.time()
     admin_name = info.get('admin_name')
     changed_items = info.get('changed_items')
     info_time = info.get('time')
     if not all([admin_name, changed_items, info_time]):
         logger.error('incomplete params')
         return update(), 400, {'Content-Type': 'application/json'}
     admin_check = self.user_collection.find_one({
         'user_name': admin_name,
         'activate': 1
     })
     if admin_check.get('type') != 'yc_admin':
         return 'permission denied', 423, {
             'Content-Type': 'application/json'
         }
     for i in changed_items:
         try:
             permission_check = self.permission_collection.find_one(
                 {'type': i['type']})
             if permission_check['update_time'] != i['update_time']:
                 return update(), 422, {'Content-Type': 'application/json'}
             changed_before = dict()
             changed_after = dict()
             for key, value in i.items():
                 if (pre_data := permission_check.get(key)) != value:
                     changed_before[key] = pre_data
                     changed_after[key] = value
                     permission_check[key] = value
             permission_check['update_time'] = t
             self.permission_collection.replace_one({'type': i['type']},
                                                    permission_check)
             if changed_after:
                 self.user_log_collection.insert_one({
                     'id': {
                         'admin_id': admin_check['_id']
                     },
                     'operator':
                     admin_name,
                     'type':
                     i['type'],
                     'time':
                     info_time,
                     'action':
                     "change permission config",
                     'changed_before':
                     changed_before,
                     'changed_after':
                     changed_after
                 })
                 logger.info('permission_modify')
         except Exception as e:
             logger.error(str(e))
             return update(), 400, {'Content-Type': 'application/json'}
예제 #5
0
 def user_modify(self, info: dict):
     t = time.time()
     admin_name = info.get('admin_name')
     user_name = info.get('user_name')
     changed_items: dict = info.get('changed_items')
     info_time = info.get('time')
     cg_user_name = changed_items.get('user_name')
     cg_update_time = changed_items.get('update_time')
     if not all(
         [admin_name, user_name, changed_items, info_time, cg_update_time]):
         logger.error('incomplete params')
         return update(), 400, {'Content-Type': 'application/json'}
     admin_check = self.user_collection.find_one({
         'user_name': admin_name,
         'activate': 1
     })
     if not admin_check:
         logger.error("user:%s didn't exist" % admin_name)
         return update(), 422, {'Content-Type': 'application/json'}
     if admin_check['type'] != 'super_admin' and admin_check[
             'type'] != 'yc_admin':
         logger.error("permission denied %s" % (info["admin_name"]))
         return update(), 423, {'Content-Type': 'application/json'}
     user_check = self.user_collection.find_one({
         'user_name': user_name,
         'activate': 1
     })
     if not user_check:
         logger.error("user:%s didn't exist" % user_name)
         return update(), 422, {'Content-Type': 'application/json'}
     if cg_user_name and self.user_collection.find_one({
             'user_name': cg_user_name,
             'activate': 1
     }):
         # if change name have be used
         return update(), 412, {'Content-Type': 'application/json'}
     changed_before = dict()
     changed_after = dict()
     if user_check['update_time'] == cg_update_time:
         for key, value in changed_items.items():
             if (pre_data := user_check.get(key)) != value:
                 changed_before[key] = pre_data
                 changed_after[key] = value
                 user_check[key] = value
         user_check['update_time'] = t
         self.user_collection.replace_one(
             {
                 "_id": user_check["_id"],
                 "activate": 1
             }, user_check)
         self.user_log_collection.insert_one({
             'id': {
                 'admin_id': admin_check['_id'],
                 'user_id': user_check['_id']
             },
             'operator': admin_name,
             'user_name': user_name,
             'time': info_time,
             'action': "user %s changed" % user_name,
             'changed_before': changed_before,
             'changed_after': changed_after
         })
         logger.info("user modify %s" % user_name)
         return update(), 200, {'Content-Type': 'application/json'}
예제 #6
0
            self.user_log_collection.insert_one({
                'id': {
                    'admin_id': admin_check['_id'],
                    'user_id': user_check['_id']
                },
                'operator': admin_name,
                'user_name': user_name,
                'time': info_time,
                'action': "user %s changed" % user_name,
                'changed_before': changed_before,
                'changed_after': changed_after
            })
            logger.info("user modify %s" % user_name)
            return update(), 200, {'Content-Type': 'application/json'}
        else:
            return update(), 422, {'Content-Type': 'application/json'}

    # def user_password_change(self, info: dict):
    #     admin_name = info.get('admin_name')
    #     user_name = info.get('user_name')
    #     changed_items = info.get('changed_items')
    #     info_time = info.get('time')
    #     user_pw = info.get('user_pw')
    #     cg_update_time = changed_items.get('update_time')
    #     if not all([admin_name, user_name, changed_items, info_time, user_pw, cg_update_time]):
    #         logger.error('incomplete params')
    #         return update(), 400, {'Content-Type': 'application/json'}
    #     admin_check = self.user_collection.find_one({'user_name': admin_name, 'activate': 1})
    #     user_check = self.user_collection.find_one({'user_name': user_name, 'activate': 1})
    #     if not (admin_check and user_check):
    #         return update(), 422, {'Content-Type': 'application/json'}
예제 #7
0
 def el_panel_thresholds_modify(self, info: dict):
     """
     aa = {
         "time": 1578906466.346,
         "admin_name": "super admin",
         "el_no": "PreA1",
         "el_url": "192.168.1.21:8080",
         "changed_items": {
             "el_no": "PreA1",
             "el_url": "192.168.1.21:8080",
             "gui_no": "op0",
             "gui_url": "192.168.1.9:3000",
             "cell_type": "mono",
             "cell_amount": 144,
             "cell_shape": "half",
             "display_mode": 2,
             "busbar": 5,
             "threshold_switch": 1,
             "thresholds": {
                 "ds": {"rules": [], "welding_point": 0},
                 "bb": [],
                 "lsh": [],
                 "ash": [],
                 "sh": {},
                 "vl": [],
                 "cs": {
                     "cell_set": [{
                         "name": "0",
                         "cs_rules": [
                             {"min_cell_per_string": 0,
                              "min_cell_per_panel": 0,
                              "position_2": 99,
                              "area_1": 100,
                              "area_3": 100,
                              "position_1": 1,
                              "result": "NG",
                              "area_2": 70,
                              "gray_scale_level": 0}],
                         "set": [[0, 0], [0, 1], [0, 2], [0, 3], [0, 4],
                                 [0, 5], [0, 6], [0, 7], [0, 8], [0, 9],
                                 [0, 10], [0, 11], [0, 12], [0, 13],
                                 [0, 14],
                                 [0, 15], [0, 16], [0, 17], [0, 18],
                                 [0, 19],
                                 [0, 20], [0, 21], [0, 22], [0, 23],
                                 [1, 0],
                                 [1, 1], [1, 2], [1, 3], [1, 4], [1, 5],
                                 [1, 6], [1, 7], [1, 8], [1, 9], [1, 10],
                                 [1, 11], [1, 12], [1, 13], [1, 14],
                                 [1, 15],
                                 [1, 16], [1, 17], [1, 18], [1, 19],
                                 [1, 20],
                                 [1, 21], [1, 22], [1, 23], [2, 0], [2, 1],
                                 [2, 2], [2, 3], [2, 4], [2, 5], [2, 6],
                                 [2, 7], [2, 8], [2, 9], [2, 10], [2, 11],
                                 [2, 12], [2, 13], [2, 14], [2, 15],
                                 [2, 16],
                                 [2, 17], [2, 18], [2, 19], [2, 20],
                                 [2, 21],
                                 [2, 22], [2, 23], [3, 0], [3, 1], [3, 2],
                                 [3, 3], [3, 4], [3, 5], [3, 6], [3, 7],
                                 [3, 8], [3, 9], [3, 10], [3, 11], [3, 12],
                                 [3, 13], [3, 14], [3, 15], [3, 16],
                                 [3, 17],
                                 [3, 18], [3, 19], [3, 20], [3, 21],
                                 [3, 22],
                                 [3, 23], [4, 0], [4, 1], [4, 2], [4, 3],
                                 [4, 4], [4, 5], [4, 6], [4, 7], [4, 8],
                                 [4, 9], [4, 10], [4, 11], [4, 12],
                                 [4, 13],
                                 [4, 14], [4, 15], [4, 16], [4, 17],
                                 [4, 18],
                                 [4, 19], [4, 20], [4, 21], [4, 22],
                                 [4, 23],
                                 [5, 0], [5, 1], [5, 2], [5, 3], [5, 4],
                                 [5, 5], [5, 6], [5, 7], [5, 8], [5, 9],
                                 [5, 10], [5, 11], [5, 12], [5, 13],
                                 [5, 14],
                                 [5, 15], [5, 16], [5, 17], [5, 18],
                                 [5, 19],
                                 [5, 20], [5, 21], [5, 22], [5, 23]]},
                         {"name": "1", "cs_rules": [], "set": []},
                         {"name": "2", "cs_rules": [], "set": []},
                         {"name": "3", "cs_rules": [], "set": []},
                         {"name": "4", "cs_rules": [], "set": []},
                         {"name": "5", "cs_rules": [], "set": []}],
                     "cc": []},
                 "mr": {
                     "dark": [{"min_cell_per_string": 0, "min_cell_per_panel": 0, "result": "NG", "tolerance": 50}],
                     "bright": [{
                         "min_cell_per_panel": 0,
                         "result": "NG", "tolerance": 70,
                         "min_cell_per_string": 0
                     }]},
                 "cr": {
                     "corner_detection": 0,
                     "cell_set": [
                         {"name": "0", "v_cr": [
                             {"min_dft_per_cell": 0, "min_cell_per_panel": 0, "result": "NG",
                              "min_len": 8, "min_cell_per_string": 0}], "l_cr": [
                             {"min_dft_per_cell": 0, "min_cell_per_panel": 0, "result": "NG",
                              "min_len": 12, "min_cell_per_string": 0}],
                          "set": [[0, 0], [0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8],
                                  [0, 9], [0, 10], [0, 11], [0, 12], [0, 13], [0, 14], [0, 15], [0, 16],
                                  [0, 17], [0, 18], [0, 19], [0, 20], [0, 21], [0, 22], [0, 23], [1, 0],
                                  [1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9],
                                  [1, 10], [1, 11], [1, 12], [1, 13], [1, 14], [1, 15], [1, 16], [1, 17],
                                  [1, 18], [1, 19], [1, 20], [1, 21], [1, 22], [1, 23], [2, 0], [2, 1],
                                  [2, 2], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9],
                                  [2, 10], [2, 11], [2, 12], [2, 13], [2, 14], [2, 15], [2, 16], [2, 17],
                                  [2, 18], [2, 19], [2, 20], [2, 21], [2, 22], [2, 23], [3, 0], [3, 1],
                                  [3, 2], [3, 3], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9],
                                  [3, 10], [3, 11], [3, 12], [3, 13], [3, 14], [3, 15], [3, 16], [3, 17],
                                  [3, 18], [3, 19], [3, 20], [3, 21], [3, 22], [3, 23], [4, 0], [4, 1],
                                  [4, 2], [4, 3], [4, 4], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9],
                                  [4, 10], [4, 11], [4, 12], [4, 13], [4, 14], [4, 15], [4, 16], [4, 17],
                                  [4, 18], [4, 19], [4, 20], [4, 21], [4, 22], [4, 23], [5, 0], [5, 1],
                                  [5, 2], [5, 3], [5, 4], [5, 5], [5, 6], [5, 7], [5, 8], [5, 9],
                                  [5, 10], [5, 11], [5, 12], [5, 13], [5, 14], [5, 15], [5, 16], [5, 17],
                                  [5, 18], [5, 19], [5, 20], [5, 21], [5, 22], [5, 23]], "x_cr": []},
                         {"name": "1", "v_cr": [], "l_cr": [], "set": [], "x_cr": []},
                         {"name": "2", "v_cr": [], "l_cr": [], "set": [], "x_cr": []},
                         {"name": "3", "v_cr": [], "l_cr": [], "set": [], "x_cr": []},
                         {"name": "4", "v_cr": [], "l_cr": [], "set": [], "x_cr": []},
                         {"name": "5", "v_cr": [], "l_cr": [], "set": [], "x_cr": []}],
                     "cc": []
                 },
                 "update_time": 1571117012.98997},
             "cr_module": 1,
             "cs_module": 1,
             "mr_module": 1,
             "bc_module": 1,
             "br_module": 1,
             "bb_module": 0,
             "ds_module": 0,
             "lsh_module": 0,
             "ash_module": 0,
             "vl_module": 0,
             "update_time": 0
         }
     }
     """
     t = time.time()
     el_no = info.get('el_no')
     admin_name = info.get('admin_name')
     changed_items = info.get('changed_items')
     info_time = info.get('time')
     if not all([el_no, admin_name, changed_items, info_time]):
         logger.error('incomplete params')
         return update(), 400, {'Content-Type': 'application/json'}
     el_check = self.el_config_collection.find_one({'el_no': el_no})
     admin_check = self.user_collection.find_one({'user_name': admin_name, 'activate': 1})
     if not el_check:
         logger.error("el_no:%s didn't exist" % admin_name)
         return update(), 422, {'Content-Type': 'application/json'}
     try:
         if el_check['thresholds']['update_time'] == changed_items['thresholds']['update_time']:
             changed_before = dict()
             changed_after = dict()
             for key, value in changed_items.items():
                 if (pre_data := el_check.get(key)) != value:
                     changed_before[key] = pre_data
                     changed_after[key] = value
                     el_check[key] = value
             el_check['thresholds']['update_time'] = t
             self.el_config_collection.replace_one({'el_no': el_no}, el_check)
             self.user_log_collection.insert_one({
                 'id': {
                     'admin_id': admin_check['_id'],
                     'el_id': el_check['_id']
                 },
                 'operator': admin_name,
                 'el_no': el_no,
                 'time': info_time,
                 'action': "change_el config",
                 'changed_before': changed_before,
                 'changed_after': changed_after,
             })
             logger.info('thresholds_modify')
             return update(), 200, {'Content-Type': 'application/json'}
     except Exception as e:
         logger.error(str(e))
         return update(), 422, {'Content-Type': 'application/json'}
예제 #8
0
    def el_panel_config_modify(self, info: dict):
        """
        {
          "admin_name": "dawson",
          "time": 1548056846.8,
          "el_no": "line0",
          "changed_items": {
            "cell_type": "mono",
            "display_mode": 2,
            "update_time": 0
          }
        }
        """
        t = time.time()
        el_no = info.get('el_no')
        admin_name = info.get('admin_name')
        changed_items = info.get('changed_items')

        if not all([el_no, admin_name, changed_items]):
            logger.error('incomplete params')
            return update(), 400, {'Content-Type': 'application/json'}

        el_check = self.el_config_collection.find_one({"el_no": el_no})
        el_check2 = self.el_config_collection.find_one({"el_no": el_no})
        admin_check = self.user_collection.find_one({"user_name": admin_name, "activate": 1})

        if el_check and el_check.get("update_time") == changed_items.get("update_time"):
            limit = list(self.el_config_collection.aggregate([
                {'$match': {'gui_no': changed_items.get("gui_no")}},
                {"$group": {'_id': '$gui_no', 'limit': {"$sum": 1}}}
            ]))
            # print(limit)  # [{'_id': {'_id': 'op0'}, 'limit': 2}]
            gui_limit = self.gui_setting_collection.find_one({"gui_no": changed_items.get("gui_no")})

            if limit and limit[0]['limit'] >= gui_limit['el_limit']:
                return update(), 412, {'Content-Type': 'application/json'}
            changed_before = dict()
            changed_after = dict()
            for key, value in changed_items.items():
                if (pre_data := el_check.get(key)) != value:
                    changed_before[key] = pre_data
                    changed_after[key] = value
                    el_check[key] = value
            if el_check2.get('cell_type') != changed_items.get('cell_type') or el_check2.get('cell_amount') != \
                    changed_items.get('cell_amount') or el_check2.get('cell_shape') != changed_items.get('cell_shape'):
                el_check['thresholds'] = self.__set_set(el_check.get('cell_amount'))
            el_check["update_time"] = t
            self.el_config_collection.replace_one({"el_no": el_no}, el_check)
            self.user_log_collection.insert_one({
                'id': {
                    'admin_id': admin_check['_id'],
                    'el_id': el_check.get('_id'),
                },
                'operator': admin_name,
                'el_no': el_no,
                'time': info['time'],
                'action': "change el_config",
                'changed_before': changed_before,
                'changed_after': changed_after
            })
            logger.info('el_config_modify')
            return update(), 200, {'Content-Type': 'application/json'}