Esempio n. 1
0
 def _validate_confirm(self, data):
     if utils.compare_value(
             utils.get_field_value(
                 self.instance, data, 'account_effective_start_date'),
             utils.get_field_value(self.instance, data, 'account_effective_end_date')) > 0:
         raise serializers.ValidationError(
             'Account Effective Date range is not correct')
     return data
Esempio n. 2
0
def prevent_account_exist(instance, data):
    qs = UamUser.objects.all()
    if hasattr(instance, 'related_user'):
        if instance.related_user:
            qs = qs.exclude(id=instance.related_user.id)
    error_map = {}
    if utils.get_field_value(instance, data, 'oa_need_windows_login'):
        ad_login_name = utils.get_field_value(
            instance, data, 'ad_windows_login_name')
        if qs.filter(ad_windows_login_name=ad_login_name).exists():
            error_map['Windows Login Name'] = [
                'Ad Login name %s already existed' % ad_login_name]
    if utils.get_field_value(instance, data, 'oa_need_lotus_notes'):
        login_name = utils.get_field_value(
            instance, data, 'ln_lotus_notes_mail_name')
        if qs.filter(ln_lotus_notes_mail_name=login_name).exists():
            error_map['Lotus Note Account'] = [
                'Account name %s already existed' % login_name]
    if utils.get_field_value(instance, data, 'oa_need_dp'):
        login_name = utils.get_field_value(
            instance, data, 'dp_login_id')
        if qs.filter(dp_login_id=login_name).exists():
            error_map['DP Login ID'] = [
                'Account name %s already existed' % login_name]
    if utils.get_field_value(instance, data, 'oa_need_jjo'):
        login_name = utils.get_field_value(
            instance, data, 'jjo_login_id')
        if qs.filter(jjo_login_id=login_name).exists():
            error_map['JJO Portal Login ID'] = [
                'Account name %s already existed' % login_name]
    if error_map:
        raise serializers.ValidationError(error_map)
Esempio n. 3
0
 def _validate_confirm(self, data):
     basic_rules = {}
     if utils.get_field_value(self.instance, data, 'oa_need_windows_login'):
         basic_rules['ad_windows_login_name'] = {'required': True}
     if utils.get_field_value(self.instance, data, 'oa_need_lotus_notes'):
         basic_rules['ln_lotus_notes_mail_name'] = {'required': True}
     self._validate_data(data, basic_rules)
     if utils.compare_value(
             utils.get_field_value(self.instance, data,
                                   'account_effective_start_date'),
             utils.get_field_value(self.instance, data,
                                   'account_effective_end_date')) > 0:
         raise serializers.ValidationError(
             'Account Effective Date range is not correct')
     prevent_account_exist(self.instance, data)
     return data
Esempio n. 4
0
    def _validate_data(self, data, rules_dict):
        def _convert_field_name_to_display_name(instr):
            return ' '.join(x.capitalize() for x in instr.split('_'))

        def _validate_existence(value):
            if isinstance(value, bool):
                return True
            if isinstance(value, str):
                value = value.strip()
            return bool(value)

        errors = []
        for field_name, _rule in rules_dict.items():
            if 'required' in rules_dict[field_name] and rules_dict[field_name][
                    'required']:
                if field_name in data:
                    result = _validate_existence(data[field_name])
                else:
                    result = _validate_existence(
                        utils.get_field_value(self.instance, data, field_name))
                if not result:
                    display_name = rules_dict[field_name].get(
                        'display_name',
                        _convert_field_name_to_display_name(field_name))
                    errors.append('%s shall not be empty' % display_name)
        if errors:
            raise serializers.ValidationError(errors)
Esempio n. 5
0
 def _validate_confirm(self, data):
     basic_rules = {
     }
     if utils.get_field_value(self.instance, data, 'oa_need_windows_login'):
         basic_rules['ad_windows_login_name'] = {'required': True}
     if utils.get_field_value(self.instance, data, 'oa_need_lotus_notes'):
         basic_rules['ln_lotus_notes_mail_name'] = {'required': True}
     self._validate_data(data, basic_rules)
     if utils.compare_value(
             utils.get_field_value(
                 self.instance, data, 'account_effective_start_date'),
             utils.get_field_value(self.instance, data, 'account_effective_end_date')) > 0:
         raise serializers.ValidationError(
             'Account Effective Date range is not correct')
     # if utils.get_field_value(self.instance, data, 'oa_need_windows_login'):
     #     ad_login_name = utils.get_field_value(
     #         self.instance, data, 'ad_windows_login_name')
     #     if UamUser.objects.exclude(id=self.instance.user_id).filter(ad_windows_login_name=ad_login_name).exists():
     #         raise serializers.ValidationError(
     #             'Ad Login name %s already existed' % ad_login_name)
     prevent_account_exist(self.instance, data)
     return data