Skip to content

Commit

Permalink
Merge pull request #264 from Mognom/multiuser
Browse files Browse the repository at this point in the history
Adds multiuser properties on components support
  • Loading branch information
aarranz authored Feb 17, 2017
2 parents 5a7ad1a + a5b7f19 commit d2e9f4e
Show file tree
Hide file tree
Showing 35 changed files with 2,310 additions and 372 deletions.
11 changes: 10 additions & 1 deletion docs/development/macdl_rdf.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ know in order to make it persistent.
- **URI**: `http://wirecloud.conwet.fi.upm.es/ns/widget#PlatformStateProperty`

- **Properties include**: `dcterms:title`, `dcterms:description`, `wire:type`,
`rdfs:label`, `wire:default`, `wire:secure`
`rdfs:label`, `wire:default`, `wire:secure`, `wire:multiuser`

- **Used with**: `wire:hasPlatformStateProperty`

Expand Down Expand Up @@ -300,6 +300,15 @@ secure.
- **Range**: `rdfs:Literal`


#### The `wire:multiuser` property

This property states whether or not a component persistent variable is
multiuser. Multiuser persistent variables store a value for each user with access rights to the dashboard.

- **URI**: `http://wirecloud.conwet.fi.upm.es/ns/Widget#value`
- **Range**: `rdfs:Literal`


#### The `wire:index` property

This property states the logical order of elements of the same type.
Expand Down
1 change: 1 addition & 0 deletions docs/development/macdl_xml.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ following attributes:
disallowed if the value of this attribute is true (the value of this
variable will be usable through the Application Mashup
cross-domain proxy). default: `false`.
- `multiuser`: This persisten value will store it's own value for each user with access rigths to the dashboard.


### The wiring element
Expand Down
21 changes: 21 additions & 0 deletions src/wirecloud/catalogue/migrations/0002_alter_json_description.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2017-01-30 12:24
from __future__ import unicode_literals

from django.db import migrations
import wirecloud.commons.fields


class Migration(migrations.Migration):

dependencies = [
('catalogue', '0001_initial'),
]

operations = [
migrations.AlterField(
model_name='catalogueresource',
name='json_description',
field=wirecloud.commons.fields.JSONField(default={}, verbose_name='JSON description'),
),
]
3 changes: 2 additions & 1 deletion src/wirecloud/catalogue/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from whoosh.query import And, Every, Or, Term
from whoosh.sorting import FieldFacet, FunctionFacet

from wirecloud.commons.fields import JSONField
from wirecloud.commons.searchers import get_search_engine
from wirecloud.commons.utils.http import get_absolute_reverse_url
from wirecloud.commons.utils.template.parsers import TemplateParser
Expand Down Expand Up @@ -65,7 +66,7 @@ class CatalogueResource(models.Model):

popularity = models.DecimalField(_('popularity'), default=0, max_digits=2, decimal_places=1)

json_description = models.TextField(_('JSON description'))
json_description = JSONField(_('JSON description'))

@property
def local_uri_part(self):
Expand Down
4 changes: 2 additions & 2 deletions src/wirecloud/catalogue/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ def test_upload_of_basic_packaged_widget(self):
self.assertTrue(os.path.exists(os.path.join(widget_path, 'documentation/index.html')))
self.assertFalse(os.path.exists(os.path.join(widget_path, 'test.html')))
widget = CatalogueResource.objects.get(vendor='Wirecloud', short_name='Test', version='0.1')
widget_info = json.loads(widget.json_description)
widget_info = widget.json_description
self.assertEqual(widget.template_uri, 'Wirecloud_Test_0.1.wgt')
self.assertEqual(widget_info['image'], 'images/catalogue.png')

Expand Down Expand Up @@ -742,7 +742,7 @@ def test_upload_of_packaged_operators(self):
self.assertTrue(os.path.exists(os.path.join(operator_path, 'doc/images/image.png')))
self.assertTrue(os.path.exists(os.path.join(operator_path, 'doc/index.html')))
operator = CatalogueResource.objects.get(vendor='Wirecloud', short_name='basic-operator', version='0.1')
operator_info = json.loads(operator.json_description)
operator_info = operator.json_description
self.assertEqual(operator.template_uri, 'Wirecloud_basic-operator_0.1.wgt')
self.assertEqual(operator_info['image'], 'images/catalogue.png')

Expand Down
3 changes: 1 addition & 2 deletions src/wirecloud/catalogue/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ def add_packaged_resource(file, user, wgt_file=None, template=None, deploy_only=

if not deploy_only:
resource_info.update(overrides)

resource = CatalogueResource.objects.create(
short_name=resource_info['name'],
vendor=resource_info['vendor'],
Expand All @@ -236,7 +235,7 @@ def add_packaged_resource(file, user, wgt_file=None, template=None, deploy_only=
template_uri=file_name,
creation_date=now(),
popularity='0.0',
json_description=json.dumps(resource_info)
json_description=resource_info
)

return resource
Expand Down
2 changes: 1 addition & 1 deletion src/wirecloud/catalogue/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ class ResourceDocumentationEntry(Resource):
def read(self, request, vendor, name, version):

resource = get_object_or_404(CatalogueResource, vendor=vendor, short_name=name, version=version)
resource_info = json.loads(resource.json_description)
resource_info = resource.json_description
if resource_info['doc'] == '':
raise Http404

Expand Down
33 changes: 17 additions & 16 deletions src/wirecloud/commons/fixtures/user_with_workspaces.json

Large diffs are not rendered by default.

32 changes: 24 additions & 8 deletions src/wirecloud/commons/tests/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ def setUpClass(cls):
'label': 'Preference label',
'description': 'Preference description',
'default': 'value',
'value': None
'value': None,
'multiuser': False,
},
{
'name': 'pref2',
Expand All @@ -141,7 +142,8 @@ def setUpClass(cls):
'label': 'Preference label',
'description': 'Preference description',
'default': '',
'value': '5'
'value': '5',
'multiuser': False,
}
],
'properties': [
Expand All @@ -152,6 +154,7 @@ def setUpClass(cls):
'label': 'Prop1',
'description': 'description 1',
'default': 'value1',
'multiuser': False,
},
{
'name': 'prop2',
Expand All @@ -160,6 +163,7 @@ def setUpClass(cls):
'label': 'Prop2',
'description': 'description 2',
'default': 'value2',
'multiuser': False,
}
],
'wiring': {
Expand Down Expand Up @@ -258,7 +262,8 @@ def setUpClass(cls):
'label': '__MSG_pref1_label__',
'description': '__MSG_pref1_description__',
'default': 'value',
'value': None
'value': None,
'multiuser': False,
},
{
'name': 'pref2',
Expand All @@ -268,7 +273,8 @@ def setUpClass(cls):
'label': '__MSG_pref2_label__',
'description': '__MSG_pref2_description__',
'default': '',
'value': '5'
'value': '5',
'multiuser': False,
}
],
'properties': [
Expand All @@ -279,6 +285,7 @@ def setUpClass(cls):
'label': '__MSG_prop1_label__',
'description': '__MSG_prop1_description__',
'default': 'value1',
'multiuser': False,
},
{
'name': 'prop2',
Expand All @@ -287,6 +294,7 @@ def setUpClass(cls):
'label': '__MSG_prop2_label__',
'description': '__MSG_prop2_description__',
'default': 'value2',
'multiuser': False,
}
],
'wiring': {
Expand Down Expand Up @@ -1125,7 +1133,8 @@ def setUpClass(cls):
'label': 'Preference label',
'description': 'Preference description',
'default': '',
'value': None
'value': None,
'multiuser': False,
},
{
'name': 'pref2',
Expand All @@ -1135,7 +1144,8 @@ def setUpClass(cls):
'label': 'Preference label',
'description': 'Preference description',
'default': 'value',
'value': '5'
'value': '5',
'multiuser': False,
}
],
'properties': [
Expand All @@ -1146,6 +1156,7 @@ def setUpClass(cls):
'label': 'Prop1',
'description': 'description 1',
'default': 'value1',
'multiuser': False,
},
{
'name': 'prop2',
Expand All @@ -1154,6 +1165,7 @@ def setUpClass(cls):
'label': 'Prop2',
'description': 'description 2',
'default': 'value2',
'multiuser': False,
}
],
'wiring': {
Expand Down Expand Up @@ -1326,7 +1338,8 @@ def setUpClass(cls):
'label': '',
'description': '',
'default': '',
'value': None
'value': None,
'multiuser': False,
},
{
'name': 'pref2',
Expand All @@ -1336,7 +1349,8 @@ def setUpClass(cls):
'label': '',
'description': '',
'default': '',
'value': None
'value': None,
'multiuser': False,
},
],
'properties': [],
Expand Down Expand Up @@ -1379,6 +1393,7 @@ def setUpClass(cls):
'label': '',
'description': '',
'default': '',
'multiuser': False,
},
{
'name': 'prop2',
Expand All @@ -1387,6 +1402,7 @@ def setUpClass(cls):
'label': '',
'description': '',
'default': '',
'multiuser': False,
},
],
'wiring': {
Expand Down
8 changes: 5 additions & 3 deletions src/wirecloud/commons/utils/template/parsers/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def _check_behaviour_view_fields(self, data):
self._check_connection_handles(connection)

def _add_translation_index(self, value, **kwargs):
index = get_trans_index(value)
index = get_trans_index(text_type(value))
if not index:
return

Expand All @@ -187,7 +187,7 @@ def _add_translation_index(self, value, **kwargs):

def _init(self):

self._check_string_fields(('title', 'description', 'longdescription', 'email', 'homepage','doc', 'changelog', 'image', 'smartphoneimage', 'license', 'licenseurl', 'issuetracker'))
self._check_string_fields(('title', 'description', 'longdescription', 'email', 'homepage', 'doc', 'changelog', 'image', 'smartphoneimage', 'license', 'licenseurl', 'issuetracker'))
self._check_contacts_fields(('authors', 'contributors'))

# Normalize/check preferences and properties (only for widgets and operators)
Expand All @@ -199,11 +199,13 @@ def _init(self):
self._check_string_fields(('label', 'description', 'default'), place=preference)
self._check_boolean_fields(('readonly', 'secure'), place=preference, default=False)
self._check_string_fields(('value',), place=preference, null=True, default=None)
self._check_boolean_fields(('multiuser',), place=preference, default=False)

for prop in self._info['properties']:
self._check_string_fields(('name', 'type'), place=prop, required=True)
self._check_string_fields(('label', 'description', 'default'), place=prop)
self._check_boolean_fields(('secure',), place=prop, default=False)
self._check_boolean_fields(('multiuser',), place=prop, default=False)

if self._info['type'] == 'widget':

Expand Down Expand Up @@ -251,7 +253,7 @@ def _init(self):
for behaviour in self._info['wiring']['visualdescription']['behaviours']:
self._check_behaviour_view_fields(behaviour)

if not 'wiring' in self._info:
if 'wiring' not in self._info:
self._info['wiring'] = {}

self._check_array_fields(('inputs', 'outputs'), place=self._info['wiring'], required=False)
Expand Down
10 changes: 6 additions & 4 deletions src/wirecloud/commons/utils/template/parsers/rdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ def _init(self):
def _add_translation_index(self, value, **kwargs):

if value not in self._translation_indexes:
self._translation_indexes[value] = []
self._translation_indexes[value].append(kwargs)
self._translation_indexes[text_type(value)] = []
self._translation_indexes[text_type(value)].append(kwargs)

def _get_translation_field(self, namespace, element, subject, translation_name, required=True, **kwargs):

Expand Down Expand Up @@ -203,7 +203,7 @@ def _parse_people_field(self, namespace, element, subject):
def _parse_extra_info(self):

if self._info['type'] == 'widget' or self._info['type'] == 'operator':
self._parse_widget_info()
self._parse_component_info()
elif self._info['type'] == 'mashup':
self._parse_workspace_info()

Expand Down Expand Up @@ -542,7 +542,7 @@ def _parse_wiring_views(self, wiring_element):
self._info['wiring']['outputs'] = outputs
# END TODO

def _parse_widget_info(self):
def _parse_component_info(self):

# Preference info
self._info['preferences'] = []
Expand All @@ -561,6 +561,7 @@ def _parse_widget_info(self):
'default': self._get_field(WIRE, 'default', preference, required=False),
'value': self._get_field(WIRE, 'value', preference, required=False, default=None),
'secure': self._get_field(WIRE, 'secure', preference, required=False).lower() == 'true',
'multiuser': self._get_field(WIRE, 'multiuser', preference, required=False).lower() == 'true'
}
if preference_info['type'] == 'list':
preference_info['options'] = []
Expand All @@ -587,6 +588,7 @@ def _parse_widget_info(self):
'description': self._get_translation_field(DCTERMS, 'description', prop, var_name + '_description', required=False, type='vdef', variable=var_name, field='description'),
'default': self._get_field(WIRE, 'default', prop, required=False),
'secure': self._get_field(WIRE, 'secure', prop, required=False).lower() == 'true',
'multiuser': self._get_field(WIRE, 'multiuser', prop, required=False).lower() == 'true',
})

self._parse_wiring_info()
Expand Down
Loading

0 comments on commit d2e9f4e

Please sign in to comment.