summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/com/vaadin/data/util/IndexedContainer.java75
-rw-r--r--src/com/vaadin/ui/BaseFieldFactory.java18
-rw-r--r--src/com/vaadin/ui/GridLayout.java10
3 files changed, 38 insertions, 65 deletions
diff --git a/src/com/vaadin/data/util/IndexedContainer.java b/src/com/vaadin/data/util/IndexedContainer.java
index 4cad9e3995..9ce00697a2 100644
--- a/src/com/vaadin/data/util/IndexedContainer.java
+++ b/src/com/vaadin/data/util/IndexedContainer.java
@@ -190,8 +190,7 @@ public class IndexedContainer implements Container.Indexed,
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.data.Container#getContainerProperty(java.lang.Object,
+ * @see com.vaadin.data.Container#getContainerProperty(java.lang.Object,
* java.lang.Object)
*/
public Property getContainerProperty(Object itemId, Object propertyId) {
@@ -238,8 +237,7 @@ public class IndexedContainer implements Container.Indexed,
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.data.Container#addContainerProperty(java.lang.Object,
+ * @see com.vaadin.data.Container#addContainerProperty(java.lang.Object,
* java.lang.Class, java.lang.Object)
*/
public boolean addContainerProperty(Object propertyId, Class type,
@@ -386,9 +384,7 @@ public class IndexedContainer implements Container.Indexed,
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.data.Container#removeContainerProperty(java.lang.Object
- * )
+ * @see com.vaadin.data.Container#removeContainerProperty(java.lang.Object )
*/
public boolean removeContainerProperty(Object propertyId) {
@@ -456,8 +452,7 @@ public class IndexedContainer implements Container.Indexed,
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.data.Container.Ordered#nextItemId(java.lang.Object)
+ * @see com.vaadin.data.Container.Ordered#nextItemId(java.lang.Object)
*/
public Object nextItemId(Object itemId) {
if (filteredItemIds != null) {
@@ -483,8 +478,7 @@ public class IndexedContainer implements Container.Indexed,
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.data.Container.Ordered#prevItemId(java.lang.Object)
+ * @see com.vaadin.data.Container.Ordered#prevItemId(java.lang.Object)
*/
public Object prevItemId(Object itemId) {
if (filteredItemIds != null) {
@@ -512,8 +506,7 @@ public class IndexedContainer implements Container.Indexed,
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.data.Container.Ordered#isFirstId(java.lang.Object)
+ * @see com.vaadin.data.Container.Ordered#isFirstId(java.lang.Object)
*/
public boolean isFirstId(Object itemId) {
if (filteredItemIds != null) {
@@ -551,8 +544,7 @@ public class IndexedContainer implements Container.Indexed,
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.data.Container.Ordered#addItemAfter(java.lang.Object,
+ * @see com.vaadin.data.Container.Ordered#addItemAfter(java.lang.Object,
* java.lang.Object)
*/
public Item addItemAfter(Object previousItemId, Object newItemId) {
@@ -572,8 +564,7 @@ public class IndexedContainer implements Container.Indexed,
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.data.Container.Ordered#addItemAfter(java.lang.Object)
+ * @see com.vaadin.data.Container.Ordered#addItemAfter(java.lang.Object)
*/
public Object addItemAfter(Object previousItemId) {
@@ -611,8 +602,7 @@ public class IndexedContainer implements Container.Indexed,
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.data.Container.Indexed#indexOfId(java.lang.Object)
+ * @see com.vaadin.data.Container.Indexed#indexOfId(java.lang.Object)
*/
public int indexOfId(Object itemId) {
if (filteredItemIds != null) {
@@ -636,8 +626,7 @@ public class IndexedContainer implements Container.Indexed,
/*
* (non-Javadoc)
*
- * @see com.vaadin.data.Container.Indexed#addItemAt(int,
- * java.lang.Object)
+ * @see com.vaadin.data.Container.Indexed#addItemAt(int, java.lang.Object)
*/
public Item addItemAt(int index, Object newItemId) {
@@ -737,9 +726,7 @@ public class IndexedContainer implements Container.Indexed,
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.data.Container.PropertySetChangeEvent#getContainer
- * ()
+ * @see com.vaadin.data.Container.PropertySetChangeEvent#getContainer ()
*/
public Container getContainer() {
return (Container) getSource();
@@ -768,8 +755,7 @@ public class IndexedContainer implements Container.Indexed,
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.data.Container.ItemSetChangeEvent#getContainer()
+ * @see com.vaadin.data.Container.ItemSetChangeEvent#getContainer()
*/
public Container getContainer() {
return (Container) getSource();
@@ -817,8 +803,7 @@ public class IndexedContainer implements Container.Indexed,
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.data.Container.PropertySetChangeNotifier#addListener
+ * @see com.vaadin.data.Container.PropertySetChangeNotifier#addListener
* (com.vaadin.data.Container.PropertySetChangeListener)
*/
public void addListener(Container.PropertySetChangeListener listener) {
@@ -831,8 +816,7 @@ public class IndexedContainer implements Container.Indexed,
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.data.Container.PropertySetChangeNotifier#removeListener
+ * @see com.vaadin.data.Container.PropertySetChangeNotifier#removeListener
* (com.vaadin.data.Container.PropertySetChangeListener)
*/
public void removeListener(Container.PropertySetChangeListener listener) {
@@ -844,9 +828,8 @@ public class IndexedContainer implements Container.Indexed,
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.data.Container.ItemSetChangeNotifier#addListener(com
- * .itmill.toolkit.data.Container.ItemSetChangeListener)
+ * @see com.vaadin.data.Container.ItemSetChangeNotifier#addListener(com
+ * .vaadin.data.Container.ItemSetChangeListener)
*/
public void addListener(Container.ItemSetChangeListener listener) {
if (itemSetChangeListeners == null) {
@@ -858,8 +841,7 @@ public class IndexedContainer implements Container.Indexed,
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.data.Container.ItemSetChangeNotifier#removeListener
+ * @see com.vaadin.data.Container.ItemSetChangeNotifier#removeListener
* (com.vaadin.data.Container.ItemSetChangeListener)
*/
public void removeListener(Container.ItemSetChangeListener listener) {
@@ -871,9 +853,8 @@ public class IndexedContainer implements Container.Indexed,
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.data.Property.ValueChangeNotifier#addListener(com.
- * itmill.toolkit.data.Property.ValueChangeListener)
+ * @see com.vaadin.data.Property.ValueChangeNotifier#addListener(com.
+ * vaadin.data.Property.ValueChangeListener)
*/
public void addListener(Property.ValueChangeListener listener) {
if (propertyValueChangeListeners == null) {
@@ -885,9 +866,8 @@ public class IndexedContainer implements Container.Indexed,
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.data.Property.ValueChangeNotifier#removeListener(com
- * .itmill.toolkit.data.Property.ValueChangeListener)
+ * @see com.vaadin.data.Property.ValueChangeNotifier#removeListener(com
+ * .vaadin.data.Property.ValueChangeListener)
*/
public void removeListener(Property.ValueChangeListener listener) {
if (propertyValueChangeListeners != null) {
@@ -1037,8 +1017,8 @@ public class IndexedContainer implements Container.Indexed,
/* Internal Item and Property implementations */
/*
- * A class implementing the com.vaadin.data.Item interface to be
- * contained in the list. @author IT Mill Ltd.
+ * A class implementing the com.vaadin.data.Item interface to be contained
+ * in the list. @author IT Mill Ltd.
*
* @version @VERSION@
*
@@ -1348,8 +1328,7 @@ public class IndexedContainer implements Container.Indexed,
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.data.Property.ValueChangeNotifier#addListener(
+ * @see com.vaadin.data.Property.ValueChangeNotifier#addListener(
* com.vaadin.data.Property.ValueChangeListener)
*/
public void addListener(Property.ValueChangeListener listener) {
@@ -1359,8 +1338,7 @@ public class IndexedContainer implements Container.Indexed,
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.data.Property.ValueChangeNotifier#removeListener
+ * @see com.vaadin.data.Property.ValueChangeNotifier#removeListener
* (com.vaadin.data.Property.ValueChangeListener)
*/
public void removeListener(Property.ValueChangeListener listener) {
@@ -1419,8 +1397,7 @@ public class IndexedContainer implements Container.Indexed,
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.data.Container.Sortable#getSortableContainerPropertyIds
+ * @see com.vaadin.data.Container.Sortable#getSortableContainerPropertyIds
* ()
*/
public Collection getSortableContainerPropertyIds() {
diff --git a/src/com/vaadin/ui/BaseFieldFactory.java b/src/com/vaadin/ui/BaseFieldFactory.java
index ea488bb538..0be76ab2b3 100644
--- a/src/com/vaadin/ui/BaseFieldFactory.java
+++ b/src/com/vaadin/ui/BaseFieldFactory.java
@@ -11,10 +11,9 @@ import com.vaadin.data.Property;
/**
* Default implementation of the the following Field types are used by default:
* <p>
- * <b>Boolean</b>: Button(switchMode:true).<br/>
- * <b>Date</b>: DateField(resolution: day).<br/>
- * <b>Item</b>: Form. <br/>
- * <b>default field type</b>: TextField.
+ * <b>Boolean</b>: Button(switchMode:true).<br/> <b>Date</b>:
+ * DateField(resolution: day).<br/> <b>Item</b>: Form. <br/> <b>default field
+ * type</b>: TextField.
* <p>
*
* @author IT Mill Ltd.
@@ -38,7 +37,7 @@ public class BaseFieldFactory implements FieldFactory {
* @param uiContext
* the context where the Field is presented.
*
- * @see com.itmill.toolkit.ui.FieldFactory#createField(Class, Component)
+ * @see com.vaadin.ui.FieldFactory#createField(Class, Component)
*/
public Field createField(Class type, Component uiContext) {
return DefaultFieldFactory.createFieldByPropertyType(type);
@@ -47,7 +46,7 @@ public class BaseFieldFactory implements FieldFactory {
/**
* Creates the field based on the datasource property.
*
- * @see com.itmill.toolkit.ui.FieldFactory#createField(Property, Component)
+ * @see com.vaadin.ui.FieldFactory#createField(Property, Component)
*/
public Field createField(Property property, Component uiContext) {
if (property != null) {
@@ -60,8 +59,7 @@ public class BaseFieldFactory implements FieldFactory {
/**
* Creates the field based on the item and property id.
*
- * @see com.itmill.toolkit.ui.FieldFactory#createField(Item, Object,
- * Component)
+ * @see com.vaadin.ui.FieldFactory#createField(Item, Object, Component)
*/
public Field createField(Item item, Object propertyId, Component uiContext) {
if (item != null && propertyId != null) {
@@ -79,8 +77,8 @@ public class BaseFieldFactory implements FieldFactory {
}
/**
- * @see com.itmill.toolkit.ui.FieldFactory#createField(com.itmill.toolkit.data.Container,
- * java.lang.Object, java.lang.Object, com.itmill.toolkit.ui.Component)
+ * @see com.vaadin.ui.FieldFactory#createField(com.vaadin.data.Container,
+ * java.lang.Object, java.lang.Object, com.vaadin.ui.Component)
*/
public Field createField(Container container, Object itemId,
Object propertyId, Component uiContext) {
diff --git a/src/com/vaadin/ui/GridLayout.java b/src/com/vaadin/ui/GridLayout.java
index fbbc0e3ffa..165b26491e 100644
--- a/src/com/vaadin/ui/GridLayout.java
+++ b/src/com/vaadin/ui/GridLayout.java
@@ -624,9 +624,8 @@ public class GridLayout extends AbstractLayout implements
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.ui.Layout.AlignmentHandler#getComponentAlignment(com
- * .itmill.toolkit.ui.Component)
+ * @see com.vaadin.ui.Layout.AlignmentHandler#getComponentAlignment(com
+ * .vaadin.ui.Component)
*/
public Alignment getComponentAlignment(Component childComponent) {
Alignment alignment = componentToAlignment.get(childComponent);
@@ -1077,9 +1076,8 @@ public class GridLayout extends AbstractLayout implements
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.ui.Layout.AlignmentHandler#setComponentAlignment(com
- * .itmill.toolkit.ui.Component, int, int)
+ * @see com.vaadin.ui.Layout.AlignmentHandler#setComponentAlignment(com
+ * .vaadin.ui.Component, int, int)
*/
public void setComponentAlignment(Component childComponent,
int horizontalAlignment, int verticalAlignment) {
value='backport/48081/stable28'>backport/48081/stable28 Nextcloud server, a safe home for all your data: https://github.com/nextcloud/serverwww-data
aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Files/Storage/Wrapper/PermissionsMaskTest.php
blob: ea01a0e3e9490dc32c1972a663796c37496d73ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?php
/**
 * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
 */

namespace Test\Files\Storage\Wrapper;

use OC\Files\Storage\Wrapper\Wrapper;
use OCP\Constants;
use OCP\Files\Cache\IScanner;

/**
 * @group DB
 */
class PermissionsMaskTest extends \Test\Files\Storage\Storage {
	/**
	 * @var \OC\Files\Storage\Temporary
	 */
	private $sourceStorage;

	protected function setUp(): void {
		parent::setUp();
		$this->sourceStorage = new \OC\Files\Storage\Temporary([]);
		$this->instance = $this->getMaskedStorage(Constants::PERMISSION_ALL);
	}

	protected function tearDown(): void {
		$this->sourceStorage->cleanUp();
		parent::tearDown();
	}

	protected function getMaskedStorage($mask) {
		return new \OC\Files\Storage\Wrapper\PermissionsMask([
			'storage' => $this->sourceStorage,
			'mask' => $mask
		]);
	}

	public function testMkdirNoCreate() {
		$storage = $this->getMaskedStorage(Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE);
		$this->assertFalse($storage->mkdir('foo'));
		$this->assertFalse($storage->file_exists('foo'));
	}

	public function testRmdirNoDelete() {
		$storage = $this->getMaskedStorage(Constants::PERMISSION_ALL - Constants::PERMISSION_DELETE);
		$this->assertTrue($storage->mkdir('foo'));
		$this->assertTrue($storage->file_exists('foo'));
		$this->assertFalse($storage->rmdir('foo'));
		$this->assertTrue($storage->file_exists('foo'));
	}

	public function testTouchNewFileNoCreate() {
		$storage = $this->getMaskedStorage(Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE);
		$this->assertFalse($storage->touch('foo'));
		$this->assertFalse($storage->file_exists('foo'));
	}

	public function testTouchNewFileNoUpdate() {
		$storage = $this->getMaskedStorage(Constants::PERMISSION_ALL - Constants::PERMISSION_UPDATE);
		$this->assertTrue($storage->touch('foo'));
		$this->assertTrue($storage->file_exists('foo'));
	}

	public function testTouchExistingFileNoUpdate() {
		$this->sourceStorage->touch('foo');
		$storage = $this->getMaskedStorage(Constants::PERMISSION_ALL - Constants::PERMISSION_UPDATE);
		$this->assertFalse($storage->touch('foo'));
	}

	public function testUnlinkNoDelete() {
		$storage = $this->getMaskedStorage(Constants::PERMISSION_ALL - Constants::PERMISSION_DELETE);
		$this->assertTrue($storage->touch('foo'));
		$this->assertTrue($storage->file_exists('foo'));
		$this->assertFalse($storage->unlink('foo'));
		$this->assertTrue($storage->file_exists('foo'));
	}

	public function testPutContentsNewFileNoUpdate() {
		$storage = $this->getMaskedStorage(Constants::PERMISSION_ALL - Constants::PERMISSION_UPDATE);
		$this->assertEquals(3, $storage->file_put_contents('foo', 'bar'));
		$this->assertEquals('bar', $storage->file_get_contents('foo'));
	}

	public function testPutContentsNewFileNoCreate() {
		$storage = $this->getMaskedStorage(Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE);
		$this->assertFalse($storage->file_put_contents('foo', 'bar'));
	}

	public function testPutContentsExistingFileNoUpdate() {
		$this->sourceStorage->touch('foo');
		$storage = $this->getMaskedStorage(Constants::PERMISSION_ALL - Constants::PERMISSION_UPDATE);
		$this->assertFalse($storage->file_put_contents('foo', 'bar'));
	}

	public function testFopenExistingFileNoUpdate() {
		$this->sourceStorage->touch('foo');
		$storage = $this->getMaskedStorage(Constants::PERMISSION_ALL - Constants::PERMISSION_UPDATE);
		$this->assertFalse($storage->fopen('foo', 'w'));
	}

	public function testFopenNewFileNoCreate() {
		$storage = $this->getMaskedStorage(Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE);
		$this->assertFalse($storage->fopen('foo', 'w'));
	}

	public function testScanNewFiles() {
		$storage = $this->getMaskedStorage(Constants::PERMISSION_READ + Constants::PERMISSION_CREATE);
		$storage->file_put_contents('foo', 'bar');
		$storage->getScanner()->scan('');

		$this->assertEquals(Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE, $this->sourceStorage->getCache()->get('foo')->getPermissions());
		$this->assertEquals(Constants::PERMISSION_READ, $storage->getCache()->get('foo')->getPermissions());
	}

	public function testScanNewWrappedFiles() {
		$storage = $this->getMaskedStorage(Constants::PERMISSION_READ + Constants::PERMISSION_CREATE);
		$wrappedStorage = new Wrapper(['storage' => $storage]);
		$wrappedStorage->file_put_contents('foo', 'bar');
		$wrappedStorage->getScanner()->scan('');

		$this->assertEquals(Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE, $this->sourceStorage->getCache()->get('foo')->getPermissions());
		$this->assertEquals(Constants::PERMISSION_READ, $storage->getCache()->get('foo')->getPermissions());
	}

	public function testScanNewFilesNested() {
		$storage = $this->getMaskedStorage(Constants::PERMISSION_READ + Constants::PERMISSION_CREATE + Constants::PERMISSION_UPDATE);
		$nestedStorage = new \OC\Files\Storage\Wrapper\PermissionsMask([
			'storage' => $storage,
			'mask' => Constants::PERMISSION_READ + Constants::PERMISSION_CREATE
		]);
		$wrappedStorage = new Wrapper(['storage' => $nestedStorage]);
		$wrappedStorage->file_put_contents('foo', 'bar');
		$wrappedStorage->getScanner()->scan('');

		$this->assertEquals(Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE, $this->sourceStorage->getCache()->get('foo')->getPermissions());
		$this->assertEquals(Constants::PERMISSION_READ + Constants::PERMISSION_UPDATE, $storage->getCache()->get('foo')->getPermissions());
		$this->assertEquals(Constants::PERMISSION_READ, $wrappedStorage->getCache()->get('foo')->getPermissions());
	}

	public function testScanUnchanged() {
		$this->sourceStorage->mkdir('foo');
		$this->sourceStorage->file_put_contents('foo/bar.txt', 'bar');

		$this->sourceStorage->getScanner()->scan('foo');

		$storage = $this->getMaskedStorage(Constants::PERMISSION_READ);
		$scanner = $storage->getScanner();
		$called = false;
		$scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function () use (&$called) {
			$called = true;
		});
		$scanner->scan('foo', IScanner::SCAN_RECURSIVE, IScanner::REUSE_ETAG | IScanner::REUSE_SIZE);

		$this->assertFalse($called);
	}

	public function testScanUnchangedWrapped() {
		$this->sourceStorage->mkdir('foo');
		$this->sourceStorage->file_put_contents('foo/bar.txt', 'bar');

		$this->sourceStorage->getScanner()->scan('foo');

		$storage = $this->getMaskedStorage(Constants::PERMISSION_READ);
		$wrappedStorage = new Wrapper(['storage' => $storage]);
		$scanner = $wrappedStorage->getScanner();
		$called = false;
		$scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function () use (&$called) {
			$called = true;
		});
		$scanner->scan('foo', IScanner::SCAN_RECURSIVE, IScanner::REUSE_ETAG | IScanner::REUSE_SIZE);

		$this->assertFalse($called);
	}
}