예제 #1
0
    def create_api_key(cls, creator_email):
        unique_id = UcfUtil.guid()
        entry = cls(id=unique_id)
        entry.unique_id = unique_id
        api_key = UcfUtil.guid()
        entry.api_key = api_key
        entry.creator_email = creator_email

        entry_key = entry.put()

        entry_dict = entry_key.get().to_dict()

        return entry_dict
예제 #2
0
	def addMailSendQueue(cls, helper, apply_vo):
		# token作成
		token = UcfUtil.guid()
		params = {
				'apply_unique_id': UcfUtil.getHashStr(apply_vo, 'unique_id')
		}
		# taskに追加
		import_q = taskqueue.Queue('send-mail')
		import_t = taskqueue.Task(
				url='/a/' + helper._tenant + '/' + token + '/sendmail_update_approval_status',
				params=params,
				#target='mail',
				target='default',
				countdown='1'
		)
		import_q.add(import_t)
		logging.info('add taskqueue:sendmail_update_approval_status')
예제 #3
0
    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.'))