mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-11-03 03:16:10 -06:00 
			
		
		
		
	Fix: allow relative date queries not in quick list (#5801)
This commit is contained in:
		@@ -381,6 +381,28 @@ describe('FilterEditorComponent', () => {
 | 
			
		||||
    expect(component.textFilter).toBeNull()
 | 
			
		||||
  }))
 | 
			
		||||
 | 
			
		||||
  it('should ingest text filter content with relative dates that are not in quick list', fakeAsync(() => {
 | 
			
		||||
    expect(component.dateAddedRelativeDate).toBeNull()
 | 
			
		||||
    component.filterRules = [
 | 
			
		||||
      {
 | 
			
		||||
        rule_type: FILTER_FULLTEXT_QUERY,
 | 
			
		||||
        value: 'added:[-2 week to now]',
 | 
			
		||||
      },
 | 
			
		||||
    ]
 | 
			
		||||
    expect(component.dateAddedRelativeDate).toBeNull()
 | 
			
		||||
    expect(component.textFilter).toEqual('added:[-2 week to now]')
 | 
			
		||||
 | 
			
		||||
    expect(component.dateCreatedRelativeDate).toBeNull()
 | 
			
		||||
    component.filterRules = [
 | 
			
		||||
      {
 | 
			
		||||
        rule_type: FILTER_FULLTEXT_QUERY,
 | 
			
		||||
        value: 'created:[-2 week to now]',
 | 
			
		||||
      },
 | 
			
		||||
    ]
 | 
			
		||||
    expect(component.dateCreatedRelativeDate).toBeNull()
 | 
			
		||||
    expect(component.textFilter).toEqual('created:[-2 week to now]')
 | 
			
		||||
  }))
 | 
			
		||||
 | 
			
		||||
  it('should ingest text filter rules for more like', fakeAsync(() => {
 | 
			
		||||
    const moreLikeSpy = jest.spyOn(documentService, 'get')
 | 
			
		||||
    moreLikeSpy.mockReturnValue(of({ id: 1, title: 'Foo Bar' }))
 | 
			
		||||
@@ -1372,6 +1394,34 @@ describe('FilterEditorComponent', () => {
 | 
			
		||||
    ])
 | 
			
		||||
  }))
 | 
			
		||||
 | 
			
		||||
  it('should leave relative dates not in quick list intact', fakeAsync(() => {
 | 
			
		||||
    component.textFilterInput.nativeElement.value = 'created:[-2 week to now]'
 | 
			
		||||
    component.textFilterInput.nativeElement.dispatchEvent(new Event('input'))
 | 
			
		||||
    const textFieldTargetDropdown = fixture.debugElement.queryAll(
 | 
			
		||||
      By.directive(NgbDropdownItem)
 | 
			
		||||
    )[4]
 | 
			
		||||
    textFieldTargetDropdown.triggerEventHandler('click')
 | 
			
		||||
    fixture.detectChanges()
 | 
			
		||||
    tick(400)
 | 
			
		||||
    expect(component.filterRules).toEqual([
 | 
			
		||||
      {
 | 
			
		||||
        rule_type: FILTER_FULLTEXT_QUERY,
 | 
			
		||||
        value: 'created:[-2 week to now]',
 | 
			
		||||
      },
 | 
			
		||||
    ])
 | 
			
		||||
 | 
			
		||||
    component.textFilterInput.nativeElement.value = 'added:[-2 month to now]'
 | 
			
		||||
    component.textFilterInput.nativeElement.dispatchEvent(new Event('input'))
 | 
			
		||||
    fixture.detectChanges()
 | 
			
		||||
    tick(400)
 | 
			
		||||
    expect(component.filterRules).toEqual([
 | 
			
		||||
      {
 | 
			
		||||
        rule_type: FILTER_FULLTEXT_QUERY,
 | 
			
		||||
        value: 'added:[-2 month to now]',
 | 
			
		||||
      },
 | 
			
		||||
    ])
 | 
			
		||||
  }))
 | 
			
		||||
 | 
			
		||||
  it('should convert user input to correct filter rules on date added after', fakeAsync(() => {
 | 
			
		||||
    const dateAddedDropdown = fixture.debugElement.queryAll(
 | 
			
		||||
      By.directive(DateDropdownComponent)
 | 
			
		||||
 
 | 
			
		||||
@@ -362,10 +362,11 @@ export class FilterEditorComponent
 | 
			
		||||
                    this.dateCreatedRelativeDate =
 | 
			
		||||
                      RELATIVE_DATE_QUERYSTRINGS.find(
 | 
			
		||||
                        (qS) => qS.dateQuery == match[1]
 | 
			
		||||
                      )?.relativeDate
 | 
			
		||||
                      )?.relativeDate ?? null
 | 
			
		||||
                  }
 | 
			
		||||
                }
 | 
			
		||||
              )
 | 
			
		||||
              if (this.dateCreatedRelativeDate === null) textQueryArgs.push(arg) // relative query not in the quick list
 | 
			
		||||
            } else if (arg.match(RELATIVE_DATE_QUERY_REGEXP_ADDED)) {
 | 
			
		||||
              ;[...arg.matchAll(RELATIVE_DATE_QUERY_REGEXP_ADDED)].forEach(
 | 
			
		||||
                (match) => {
 | 
			
		||||
@@ -373,10 +374,11 @@ export class FilterEditorComponent
 | 
			
		||||
                    this.dateAddedRelativeDate =
 | 
			
		||||
                      RELATIVE_DATE_QUERYSTRINGS.find(
 | 
			
		||||
                        (qS) => qS.dateQuery == match[1]
 | 
			
		||||
                      )?.relativeDate
 | 
			
		||||
                      )?.relativeDate ?? null
 | 
			
		||||
                  }
 | 
			
		||||
                }
 | 
			
		||||
              )
 | 
			
		||||
              if (this.dateAddedRelativeDate === null) textQueryArgs.push(arg) // relative query not in the quick list
 | 
			
		||||
            } else {
 | 
			
		||||
              textQueryArgs.push(arg)
 | 
			
		||||
            }
 | 
			
		||||
@@ -787,27 +789,6 @@ export class FilterEditorComponent
 | 
			
		||||
        })
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    if (
 | 
			
		||||
      this.dateCreatedRelativeDate == null &&
 | 
			
		||||
      this.dateAddedRelativeDate == null
 | 
			
		||||
    ) {
 | 
			
		||||
      const existingRule = filterRules.find(
 | 
			
		||||
        (fr) => fr.rule_type == FILTER_FULLTEXT_QUERY
 | 
			
		||||
      )
 | 
			
		||||
      if (
 | 
			
		||||
        existingRule?.value.match(RELATIVE_DATE_QUERY_REGEXP_CREATED) ||
 | 
			
		||||
        existingRule?.value.match(RELATIVE_DATE_QUERY_REGEXP_ADDED)
 | 
			
		||||
      ) {
 | 
			
		||||
        // remove any existing date query
 | 
			
		||||
        existingRule.value = existingRule.value
 | 
			
		||||
          .replace(RELATIVE_DATE_QUERY_REGEXP_CREATED, '')
 | 
			
		||||
          .replace(RELATIVE_DATE_QUERY_REGEXP_ADDED, '')
 | 
			
		||||
        if (existingRule.value.replace(',', '').trim() === '') {
 | 
			
		||||
          // if its empty now, remove it entirely
 | 
			
		||||
          filterRules.splice(filterRules.indexOf(existingRule), 1)
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    if (this.permissionsSelectionModel.ownerFilter == OwnerFilterType.SELF) {
 | 
			
		||||
      filterRules.push({
 | 
			
		||||
        rule_type: FILTER_OWNER,
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user