def _sendMail(to, message_subject, message_body, cc='', reply_to='', is_html=False): # check to if to is None or str(to).strip() == '': logging.error('to is None') return False, 'invalid_to' if not mail.IsEmailValid(to): logging.error('invalid to=' + str(to)) return False, 'invalid_to' # check cc if cc is not None and str(cc).strip() != '': if not mail.IsEmailValid(cc): logging.error('invalid cc=' + str(cc)) return False, 'invalid_cc' # check reply_to if reply_to is not None and str(reply_to) != '': if not mail.IsEmailValid(reply_to): logging.error('invalid reply_to=' + str(reply_to)) return False, 'invalid_reply_to' # calc check_key now = UcfUtil.getNow() # 標準時 check_key = UcfUtil.md5( now.strftime('%Y%m%d%H%M') + MD5_SUFFIX_KEY_MAIL_SERVER + SENDER_ADDON_PROJECT_ID) # post data url = SATERAITO_MAIL_SERVER_URL + '/api/sendmail' values = { 'addon_project_id': SENDER_ADDON_PROJECT_ID, 'sender_email': MESSAGE_SENDER_EMAIL, 'to': to, 'cc': cc, 'reply_to': reply_to, 'message_subject': message_subject, 'message_body': message_body, 'is_html': str(is_html), 'check_key': check_key, } headers = {} response = HttpPostAccess(url, values, headers) logging.info('response=' + str(response)) try: response_dict = json.JSONDecoder().decode(response) if response_dict.get('status') != 'ok': return False, response_dict.get('error_code') except BaseException, e: logging.error('error: class name:' + e.__class__.__name__ + ' message=' + str(e)) return False, 'unexpected_error'
def updateTaskStatus(self, file_vo, file_entry, log_msg, is_error, login_operator_unique_id, login_operator_id, is_after_process=False): # ステータス後処理 datNow = UcfUtil.getLocalTime(UcfUtil.getNow(), self._timezone) if is_error: file_vo['status'] = 'FAILED' elif is_after_process: file_vo['status'] = 'SUCCESS' log_text = file_vo.get('log_text', '') for msg in log_msg: log_text += msg + '\n' file_vo['log_text'] = log_text if is_after_process: file_vo['deal_status'] = 'FIN' file_vo['expire_date'] = UcfUtil.add_months(datNow, 1) # 一ヶ月有効とする file_vo['upload_count'] = '1' file_vo['last_upload_date'] = UcfUtil.nvl(datNow) file_vo['upload_operator_id'] = login_operator_id file_vo['upload_operator_unique_id'] = login_operator_unique_id file_vo['last_upload_operator_id'] = login_operator_id file_vo['last_upload_operator_unique_id'] = login_operator_unique_id FileUtils.editVoForRegist(self, file_vo, UcfConfig.EDIT_TYPE_RENEW) # Voからモデルにマージ file_entry.margeFromVo(file_vo, self._timezone) # 更新 file_entry.updater_name = login_operator_id file_entry.date_changed = UcfUtil.getNow() file_entry.put()
def importOneRecordGroup(self, csv_record, record_cnt, blob_key, data_key, data_kind, login_operator_unique_id, login_operator_id, login_operator_mail_address, login_operator_client_ip, login_operator_entry): titles = GroupUtils.getCsvTitles(self) code = '' row_log_msg = [] entry_vo = None current_belong_members = [] # 編集時に使用。編集前の所属メンバー(今回解除されたメンバーの判定に使用する) deal_type = '' edit_type = '' try: # CSVチェック vc = GroupCsvValidator() vc.validate(self, csv_record) # 入力エラーがあれば if vc.total_count > 0: code = '100' for title in titles: if vc.msg.has_key(title): #row_log_msg.extend(vc.msg[title]) row_log_msg.extend( ['[' + title + ']' + msg for msg in vc.msg[title]]) if code == '': command = UcfUtil.getHashStr(csv_record, 'command') # セールスフォースではグループIDとメールアドレスは別 2015.12.18 #email = UcfUtil.getHashStr(csv_record, 'email') group_id = UcfUtil.getHashStr(csv_record, 'group_id') q = sateraito_db.Group.query() q = q.filter( sateraito_db.Group.group_id_lower == group_id.lower()) key = q.get(keys_only=True) entry = key.get() if key is not None else None # 委託管理者の場合は自分がアクセスできるカテゴリかをチェック if entry is not None and ucffunc.isDelegateOperator( login_operator_entry ) and not ucffunc.isDelegateTargetManagementGroup( entry.management_group, login_operator_entry.delegate_management_groups if login_operator_entry is not None else None): code = '400' row_log_msg.append( UcfMessage.getMessage( self.getMsg( 'MSG_INVALID_ACCESS_BY_DELEGATE_MANAGEMENT_GROUPS' ))) else: vo = {} # 削除処理の場合 if command == 'D': if entry is None: code = '400' row_log_msg.append( self._formatLogRecord( UcfMessage.getMessage( self.getMsg('MSG_NOT_EXIST_DATA')))) else: edit_type = UcfConfig.EDIT_TYPE_DELETE entry_vo = entry.exchangeVo( self._timezone) # 既存データをVoに変換 # 新規登録の場合 elif command == 'I': if entry is not None: code = '400' row_log_msg.append( self._formatLogRecord( UcfMessage.getMessage( self.getMsg('MSG_VC_ALREADY_EXIST')))) else: edit_type = UcfConfig.EDIT_TYPE_NEW GroupUtils.editVoForDefault(self, vo) # csv_dataからマージ GroupUtils.margeVoFromCsvRecord( self, vo, csv_record, login_operator_entry) GroupUtils.editVoForSelectCsvImport( self, vo) # データ加工(取得用) # 編集の場合 elif command == 'U': if entry is None: code = '400' row_log_msg.append( self._formatLogRecord( UcfMessage.getMessage( self.getMsg('MSG_NOT_EXIST_DATA')))) else: edit_type = UcfConfig.EDIT_TYPE_RENEW entry_vo = entry.exchangeVo( self._timezone) # 既存データをVoに変換 GroupUtils.editVoForSelect( self, entry_vo, is_with_parent_group_info=False, is_with_belong_member_info=False) # データ加工(取得用) UcfUtil.margeHash(vo, entry_vo) # 既存データをVoにコピー # csv_dataからマージ GroupUtils.margeVoFromCsvRecord( self, vo, csv_record, login_operator_entry) GroupUtils.editVoForSelectCsvImport( self, vo) # データ加工(取得用) current_belong_members = UcfUtil.csvToList( UcfUtil.getHashStr(entry_vo, 'belong_members')) # 新規 or 編集の場合 elif command == 'IU': if entry is not None: edit_type = UcfConfig.EDIT_TYPE_RENEW entry_vo = entry.exchangeVo( self._timezone) # 既存データをVoに変換 GroupUtils.editVoForSelect( self, entry_vo, is_with_parent_group_info=False, is_with_belong_member_info=False) # データ加工(取得用) UcfUtil.margeHash(vo, entry_vo) # 既存データをVoにコピー else: edit_type = UcfConfig.EDIT_TYPE_NEW # csv_dataからマージ GroupUtils.margeVoFromCsvRecord( self, vo, csv_record, login_operator_entry) GroupUtils.editVoForSelectCsvImport(self, vo) # データ加工(取得用) ######################## # 削除 if edit_type == UcfConfig.EDIT_TYPE_DELETE: # トップグループなら子グループをトップに昇格 if UcfUtil.getHashStr(entry_vo, 'top_group_flag') == 'TOP': GroupUtils.updateBelongMembersTopGroupFlag( self, UcfUtil.getHashStr(entry_vo, 'group_id_lower'), UcfUtil.csvToList(entry_vo['belong_members']), 'SET', operator_id=login_operator_id) # このグループをメイン組織に設定しているユーザのメイン組織をクリア OperatorUtils.removeUsersTargetMainGroup( self, UcfUtil.getHashStr(entry_vo, 'group_id_lower'), operator_id=login_operator_id) # このグループをメイン組織に設定しているグループのメイン組織をクリア GroupUtils.removeGroupsTargetMainGroup( self, UcfUtil.getHashStr(entry_vo, 'group_id_lower'), operator_id=login_operator_id) # このグループを所属メンバーとして持っている親グループからメンバーとして解除 2016.10.24 GroupUtils.removeOneMemberFromBelongGroups( self, UcfUtil.getHashStr(entry_vo, 'group_id_lower'), operator_id=login_operator_id) # このグループ自体を削除 entry.key.delete() # オペレーションログ出力 UCFMDLOperationLog.addLog( login_operator_mail_address, login_operator_unique_id, UcfConfig.SCREEN_GROUP, UcfConfig.OPERATION_TYPE_REMOVE, entry_vo.get('group_id', ''), entry_vo.get('unique_id', ''), login_operator_client_ip, '', is_async=True) deal_type = edit_type # 更新、新規 elif edit_type == UcfConfig.EDIT_TYPE_NEW or edit_type == UcfConfig.EDIT_TYPE_RENEW: # 入力チェック vc = GroupValidator( edit_type, ucffunc.isDelegateOperator(login_operator_entry), login_operator_entry.delegate_management_groups if login_operator_entry is not None else None) vc.validate(self, vo) # 入力エラーがなければ登録処理 if vc.total_count <= 0: # オペレーションログ詳細用に更新フィールドを取得(加工前に比較しておく) if edit_type == UcfConfig.EDIT_TYPE_NEW: is_diff = True diff_for_operation_log = [] else: is_diff, diff_for_operation_log = GroupUtils.isDiff( self, vo, entry_vo) # 差分があるかを判定 is_skip = not is_diff # 加工データ GroupUtils.editVoForRegist(self, vo, entry_vo, edit_type) # 新規登録場合モデルを新規作成 if edit_type == UcfConfig.EDIT_TYPE_NEW: unique_id = UcfUtil.guid() vo['unique_id'] = unique_id entry = sateraito_db.Group( unique_id=unique_id, id=GroupUtils.getKey(self, vo)) #logging.info('vo=' + str(vo)) # Voからモデルにマージ #logging.info(vo) entry.margeFromVo(vo, self._timezone) # 更新日時、更新者の更新 entry.updater_name = login_operator_id entry.date_changed = UcfUtil.getNow() # 新規登録場合ユニークIDを生成 if edit_type == UcfConfig.EDIT_TYPE_NEW: # 作成日時、作成者の更新 entry.creator_name = login_operator_id entry.date_created = UcfUtil.getNow() belong_members = UcfUtil.csvToList( vo['belong_members']) release_members = [] # 今回の変更で所属メンバーから解除されたメンバー for current_belong_member in current_belong_members: if current_belong_member not in belong_members: release_members.append( current_belong_member) # 子グループのトップフラグを更新 GroupUtils.updateBelongMembersTopGroupFlag( self, UcfUtil.getHashStr(vo, 'group_id'), belong_members, 'REMOVE', operator_id=login_operator_id) # 今回このグループからメンバー解除されたグループのトップフラグ更新 GroupUtils.updateBelongMembersTopGroupFlag( self, UcfUtil.getHashStr(vo, 'group_id'), release_members, 'SET', operator_id=login_operator_id) # 登録、更新処理(※トランザクションは制約やデメリットが多いので使用しない) if not is_skip: entry.put() # オペレーションログ出力 operation_log_detail = {} if edit_type == UcfConfig.EDIT_TYPE_RENEW: operation_log_detail[ 'fields'] = diff_for_operation_log UCFMDLOperationLog.addLog( login_operator_mail_address, login_operator_unique_id, UcfConfig.SCREEN_GROUP, UcfConfig.OPERATION_TYPE_ADD if edit_type == UcfConfig.EDIT_TYPE_NEW else UcfConfig.OPERATION_TYPE_MODIFY, vo.get('group_id', ''), vo.get('unique_id', ''), login_operator_client_ip, JSONEncoder().encode(operation_log_detail), is_async=True) deal_type = edit_type else: deal_type = UcfConfig.EDIT_TYPE_SKIP # 入力エラーがあれば else: code = '100' for key, value in vc.msg.iteritems(): #row_log_msg.extend(value) row_log_msg.extend( ['[' + key + ']' + msg for msg in value]) except BaseException, e: self.outputErrorLog(e) code = '500' row_log_msg.append(self._formatLogRecord('system error.'))
if result_json['success']: access_token = result_json.get('access_token', '') expires_in = result_json.get('expire_timestamp', 0) break # 成功なのでwhile抜ける else: return 1 except BaseException, e: if process_cnt <= MAX_RETRY_CNT: logging.warning('[process_cnt=' + str(process_cnt) + ']' + ' '.join(e.args)) else: return 2 process_cnt += 1 if expires_in != 0: memcache_expire_secs = expires_in - time.mktime(UcfUtil.getNow().timetuple()) - sateraito_inc.session_timeout else: memcache_expire_secs = sateraito_inc.session_timeout - 600 logging.info('memcache_expire_secs=' + str(memcache_expire_secs)) if memcache_expire_secs > 0 and directcloudbox_token_memcache_key != '': if not memcache.set(key=directcloudbox_token_memcache_key, value=access_token, time=memcache_expire_secs): logging.warning("Memcache set failed.") else: logging.info("Memcache set success.key=" + directcloudbox_token_memcache_key) return access_token ##################################################### # DIRECT CLOUD BOX コール #####################################################