Skip to content

Commit

Permalink
fix typos, misc; update default communities configurations; update webui
Browse files Browse the repository at this point in the history
  • Loading branch information
emanueldima committed Nov 28, 2016
1 parent e4b4788 commit fb59619
Show file tree
Hide file tree
Showing 18 changed files with 65 additions and 28 deletions.
4 changes: 2 additions & 2 deletions b2share/modules/access/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ def _load_permissions_on_identity_loaded(sender, identity):
def _register_anonymous_loader():
"""Register the Anonymous Identity loader."""

def anonymous_idendity_loader():
def anonymous_identity_loader():
identity = AnonymousIdentity()
# Here we can add configurable permissions to anonymous users.
return identity
current_flask_security.principal.identity_loader(anonymous_idendity_loader)
current_flask_security.principal.identity_loader(anonymous_identity_loader)


def register_permissions_loader(app):
Expand Down
4 changes: 4 additions & 0 deletions b2share/modules/access/policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

from dateutil.parser import parse as dateutil_parse
from datetime import datetime, timezone
import pytz


def allow_public_file_metadata(record_metadata):
Expand All @@ -46,4 +47,7 @@ def is_under_embargo(record_metadata):
# no embargo date set
return False
embargo_date = dateutil_parse(embargo_date_string)
# assume UTC for naive datetime objects
if embargo_date.tzinfo is None or embargo_date.tzinfo.utcoffset(embargo_date) is None:
embargo_date = embargo_date.replace(tzinfo=pytz.UTC)
return datetime.now(timezone.utc) < embargo_date
35 changes: 20 additions & 15 deletions b2share/modules/communities/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
from .signals import after_community_delete, after_community_insert, \
after_community_update, before_community_delete, before_community_insert, \
before_community_update
from .models import Community as CommunityMetadata, _communiy_admin_role_name, \
_communiy_member_role_name
from .models import Community as CommunityMetadata, _community_admin_role_name, \
_community_member_role_name


class Community(object):
Expand Down Expand Up @@ -95,19 +95,19 @@ def get_all(cls, start=None, stop=None, name=None):
"""Searches for matching communities."""
if (start is None and stop is None):
if name is None:
metadata = CommunityMeta.query.order_by(CommunityMeta.created)
metadata = CommunityMetadata.query.order_by(CommunityMetadata.created)
else:
metadata = CommunityMeta.query.filter(
CommunityMeta.name.like(name)
).order_by(CommunityMeta.created)
metadata = CommunityMetadata.query.filter(
CommunityMetadata.name.like(name)
).order_by(CommunityMetadata.created)
elif not(start is None) and not(stop is None):
if name is None:
metadata = CommunityMeta.query.order_by(
CommunityMeta.created).limit(stop)[start:]
metadata = CommunityMetadata.query.order_by(
CommunityMetadata.created).limit(stop)[start:]
else:
metadata = CommunityMeta.query.filter(
CommunityMeta.name.like(name)
).order_by(CommunityMeta.created).limit(stop)[start:]
metadata = CommunityMetadata.query.filter(
CommunityMetadata.name.like(name)
).order_by(CommunityMetadata.created).limit(stop)[start:]
else:
#one of them is None this cannot happen
raise ValueError("Neither or both start and stop should be None")
Expand Down Expand Up @@ -139,8 +139,12 @@ def create_community(cls, name, description, logo=None, id_=None,
kwargs = {}
if id_ is not None:
kwargs['id'] = id_
model = CommunityMetadata(name=name, description=description,
logo=logo, **kwargs)
model = CommunityMetadata(name=name,
description=description,
logo=logo,
publication_workflow=publication_workflow,
restricted_submission=restricted_submission,
**kwargs)
community = cls(model)
before_community_insert.send(community)
db.session.add(model)
Expand Down Expand Up @@ -213,6 +217,7 @@ def patch(self, patch):
'description': self.model.description,
'logo': self.model.logo,
'publication_workflow': self.model.publication_workflow,
'restricted_submission': self.model.restricted_submission,
}, patch, True)
self.update(data)
return self
Expand Down Expand Up @@ -286,10 +291,10 @@ def restricted_submission(self):
def admin_role(self):
"""Role given to this community's administrators."""
return Role.query.filter(
Role.name == _communiy_admin_role_name(self)).one()
Role.name == _community_admin_role_name(self)).one()

@property
def member_role(self):
"""Role given to this community's members."""
return Role.query.filter(
Role.name == _communiy_member_role_name(self)).one()
Role.name == _community_member_role_name(self)).one()
8 changes: 4 additions & 4 deletions b2share/modules/communities/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ class Community(db.Model, Timestamp):
default=False)


def _communiy_admin_role_name(community):
def _community_admin_role_name(community):
"""Generate the name of the given community's admin role."""
return 'com:{0}:{1}'.format(community.id.hex, 'admin')


def _communiy_member_role_name(community):
def _community_member_role_name(community):
"""Generate the name of the given community's member role."""
return 'com:{0}:{1}'.format(community.id.hex, 'member')

Expand All @@ -97,11 +97,11 @@ def receive_before_insert(mapper, connection, target):
from b2share.modules.deposit.api import PublicationStates

admin_role = Role(
name=_communiy_admin_role_name(target),
name=_community_admin_role_name(target),
description='Admin role of the community "{}"'.format(target.name)
)
member_role = Role(
name=_communiy_member_role_name(target),
name=_community_member_role_name(target),
description='Member role of the community "{}"'.format(target.name)
)

Expand Down
2 changes: 1 addition & 1 deletion b2share/modules/communities/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def direct_publish_workflow(previous_model, new_deposit):
raise InvalidPublicationStateError(
description='Transition from publication state {0} to {1} is '
'not allowed by community\'s workflow {2}'.format(
previous_state, new_state, 'review_and_publish'
previous_state, new_state, 'direct_publish'
)
)
# Publish automatically when submitted
Expand Down
2 changes: 2 additions & 0 deletions demo/b2share_demo/data/communities/aalto.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"description": "Aalto University",
"id": "c4234f93-da96-4d2f-a2c8-fa83d0775212",
"logo": "/img/communities/aalto.jpg",
"publication_workflow": "direct_publish",
"restricted_submission": true,
"community_schemas": [
{
"json_schema": {
Expand Down
2 changes: 2 additions & 0 deletions demo/b2share_demo/data/communities/bbmri.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"description": "Biomedical Research.",
"logo": "/img/communities/bbmri.png",
"id": "99916f6f-9a2c-4feb-a342-6552ac7f1529",
"publication_workflow": "direct_publish",
"restricted_submission": false,
"community_schemas": [
{
"root_schema_version": 0,
Expand Down
2 changes: 2 additions & 0 deletions demo/b2share_demo/data/communities/clarin.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"description": "Linguistic data",
"logo": "/img/communities/clarin.png",
"id": "0AFEDE87-2BF2-4D89-867E-D2EE57251C62",
"publication_workflow": "direct_publish",
"restricted_submission": false,
"community_schemas": [
{
"root_schema_version": 0,
Expand Down
2 changes: 2 additions & 0 deletions demo/b2share_demo/data/communities/drihm.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"description": "Meteorology and climate data.",
"name": "DRIHM",
"logo": "/img/communities/drihm.png",
"publication_workflow": "direct_publish",
"restricted_submission": false,
"community_schemas": [
{
"json_schema": {
Expand Down
2 changes: 2 additions & 0 deletions demo/b2share_demo/data/communities/eiscat.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"description": "Incoherent scatter radar data",
"id": "b344f92a-cd0e-4e4c-aa09-28b5f95f7e41",
"name": "EISCAT",
"publication_workflow": "direct_publish",
"restricted_submission": true,
"community_schemas": [
{
"json_schema": {
Expand Down
2 changes: 2 additions & 0 deletions demo/b2share_demo/data/communities/eudat.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"description": "The big Eudat community. Use this community if no other is suited for you",
"logo": "/img/communities/eudat.png",
"id": "E9B9792E-79FB-4B07-B6B4-B9C2BD06D095",
"publication_workflow": "direct_publish",
"restricted_submission": false,
"community_schemas": [
{
"root_schema_version": 0,
Expand Down
2 changes: 2 additions & 0 deletions demo/b2share_demo/data/communities/euon.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"id": "893fad89-dc4a-4f1b-a9ba-4240aa18e12b",
"name": "EUON",
"logo": "/img/communities/euon.png",
"publication_workflow": "direct_publish",
"restricted_submission": false,
"community_schemas": [
{
"json_schema": {
Expand Down
2 changes: 2 additions & 0 deletions demo/b2share_demo/data/communities/gbif.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"id": "867c4e67-9227-4b6f-8595-c97d37e9de61",
"description": "Biodiversity data.",
"logo": "/img/communities/gbif.png",
"publication_workflow": "direct_publish",
"restricted_submission": false,
"community_schemas": [
{
"root_schema_version": 0,
Expand Down
2 changes: 2 additions & 0 deletions demo/b2share_demo/data/communities/lter.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"description": "Long-Term Ecosystem Research in Europe",
"logo": "/img/communities/lter.jpg",
"id": "d952913c-451e-4b5c-817e-d578dc8a4469",
"publication_workflow": "direct_publish",
"restricted_submission": false,
"community_schemas": [
{
"json_schema": {
Expand Down
2 changes: 2 additions & 0 deletions demo/b2share_demo/data/communities/nrm.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"description": "Herbarium data.",
"logo": "/img/communities/nrm.png",
"name": "NRM",
"publication_workflow": "direct_publish",
"restricted_submission": false,
"community_schemas": [
{
"root_schema_version": 0,
Expand Down
2 changes: 2 additions & 0 deletions demo/b2share_demo/data/communities/rda.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"description": "Research Data Alliance",
"logo": "/img/communities/rda.png",
"id": "8D963A29-5E19-492B-8CFE-97DA4F54FAD2",
"publication_workflow": "direct_publish",
"restricted_submission": true,
"community_schemas": [
{
"root_schema_version": 0,
Expand Down
6 changes: 6 additions & 0 deletions demo/b2share_demo/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,16 @@ def _create_communities(path, verbose):
with open(os.path.join(communities_dir,
filename)) as json_file:
json_config = json.loads(json_file.read())
workflow = json_config.get('publication_workflow',
'review_and_publish')
is_restricted = json_config.get('restricted_submission',
False)
community = Community.create_community(
name=json_config['name'],
description=json_config['description'],
logo=json_config['logo'],
publication_workflow=workflow,
restricted_submission=is_restricted,
id_=UUID(json_config['id']),
)
if verbose > 1:
Expand Down
12 changes: 6 additions & 6 deletions webui/src/components/editrecord.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -569,15 +569,15 @@ const EditRecord = React.createClass({
this.setState({dirty:false});
}
serverCache.patchRecord(this.props.record.get('id'), patch,
this.getPublishedState() ? onSaveAndPublish : onSave);
this.isSubmittedSet() ? onSaveAndPublish : onSave);
},

getPublishedState() {
return this.state.record.get('publication_state') == 'published';
isSubmittedSet() {
return this.state.record.get('publication_state') == 'submitted';
},

setPublishedState(e) {
const state = e.target.checked ? 'published' : 'draft';
const state = e.target.checked ? 'submitted' : 'draft';
const record = this.state.record.set('publication_state', state);
this.setState({record});
},
Expand Down Expand Up @@ -623,12 +623,12 @@ const EditRecord = React.createClass({
<div className="col-sm-offset-3 col-sm-6 alert alert-warning" key={id}>{msg} </div>) }
<div className="col-sm-offset-3 col-sm-6">
<label style={{fontSize:18, fontWeight:'normal'}}>
<input type="checkbox" value={this.getPublishedState} onChange={this.setPublishedState}/>
<input type="checkbox" value={this.isSubmittedSet} onChange={this.setPublishedState}/>
{" "}Submit draft for publication
</label>
<p>When the draft is published it will be assigned a PID, making it publicly citable.
But a published record's files can no longer be modified by its owner. </p>
{ this.getPublishedState() ?
{ this.isSubmittedSet() ?
<button type="submit" className="btn btn-primary btn-default btn-block btn-danger" onClick={this.updateRecord}>
Save and Publish </button>
: this.state.dirty ?
Expand Down

0 comments on commit fb59619

Please sign in to comment.