Search in sources :

Example 11 with CreateRequest

use of org.xwiki.refactoring.job.CreateRequest in project xwiki-platform by xwiki.

the class CreateJobTest method createDocumentFromRestrictedTemplate.

@Test
public void createDocumentFromRestrictedTemplate() throws Throwable {
    DocumentReference documentReference = new DocumentReference("wiki", "Space", "Page");
    when(this.modelBridge.exists(documentReference)).thenReturn(false);
    DocumentReference userReference = new DocumentReference("wiki", "Users", "Alice");
    when(this.authorization.hasAccess(Right.EDIT, userReference, documentReference)).thenReturn(true);
    DocumentReference templateReference = new DocumentReference("wiki", "Code", "Template");
    when(this.authorization.hasAccess(Right.VIEW, userReference, templateReference)).thenReturn(false);
    CreateRequest request = createRequest(documentReference, templateReference);
    request.setUserReference(userReference);
    run(request);
    verifyNoCreate();
    verify(this.mocker.getMockedLogger()).error("You are not allowed to view the template document [{}].", templateReference);
}
Also used : CreateRequest(org.xwiki.refactoring.job.CreateRequest) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 12 with CreateRequest

use of org.xwiki.refactoring.job.CreateRequest in project xwiki-platform by xwiki.

the class CreateJobTest method createSpaceWithoutTemplate.

@Test
public void createSpaceWithoutTemplate() throws Throwable {
    SpaceReference spaceReference = new SpaceReference("wiki", "Space");
    DocumentReference spaceHomeReference = new DocumentReference("WebHome", spaceReference);
    when(this.modelBridge.exists(spaceHomeReference)).thenReturn(false);
    CreateRequest request = createRequest(spaceReference, null);
    request.setCheckRights(false);
    run(request);
    verify(this.modelBridge).create(spaceHomeReference);
    verify(this.modelBridge, never()).copy(any(DocumentReference.class), any(DocumentReference.class));
    verify(this.modelBridge, never()).removeLock(any(DocumentReference.class));
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) CreateRequest(org.xwiki.refactoring.job.CreateRequest) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 13 with CreateRequest

use of org.xwiki.refactoring.job.CreateRequest in project xwiki-platform by xwiki.

the class CreateJobTest method createRestrictedDocument.

@Test
public void createRestrictedDocument() throws Throwable {
    DocumentReference documentReference = new DocumentReference("wiki", "Space", "Page");
    when(this.modelBridge.exists(documentReference)).thenReturn(false);
    DocumentReference userReference = new DocumentReference("wiki", "Users", "Alice");
    when(this.authorization.hasAccess(Right.EDIT, userReference, documentReference)).thenReturn(false);
    CreateRequest request = createRequest(documentReference, null);
    request.setUserReference(userReference);
    run(request);
    verifyNoCreate();
    verify(this.mocker.getMockedLogger()).error("You are not allowed to create the document [{}].", documentReference);
}
Also used : CreateRequest(org.xwiki.refactoring.job.CreateRequest) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Aggregations

CreateRequest (org.xwiki.refactoring.job.CreateRequest)13 Test (org.junit.Test)10 DocumentReference (org.xwiki.model.reference.DocumentReference)10 SpaceReference (org.xwiki.model.reference.SpaceReference)2 XWikiException (com.xpn.xwiki.XWikiException)1 Job (org.xwiki.job.Job)1 EntityReference (org.xwiki.model.reference.EntityReference)1 RefactoringScriptService (org.xwiki.refactoring.script.RefactoringScriptService)1 ScriptService (org.xwiki.script.service.ScriptService)1