Skip to content

Commit

Permalink
Merge pull request #4477 from archesproject/4467_sync_history
Browse files Browse the repository at this point in the history
Prevents users from modifying critical features of a synched survey
  • Loading branch information
chiatt authored Jan 28, 2019
2 parents bd5dfec + 9dabd03 commit 56f0e40
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 21 deletions.
1 change: 0 additions & 1 deletion arches/app/media/js/models/mobile-survey.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ define([
});
}
}
currentIdentities.sort();
}
};

Expand Down
1 change: 1 addition & 0 deletions arches/app/media/js/viewmodels/mobile-survey.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ define([
}, 200);
};
this.history = params.history;
this.locked = _.keys(this.history.editors) > 0 || false;
this.history.lastsync = moment(this.history.lastsync);
_.each(this.history.editors, function(editor) {
editor.lastsync = moment(editor.lastsync);
Expand Down
25 changes: 15 additions & 10 deletions arches/app/templates/views/mobile-survey-designer.htm
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,8 @@ <h1 class="page-header text-overflow mobile-designer-title">
<!--ko if: selectedNode().cards -->
<!--ko foreach: {data: selectedNode().cards, as: 'card'} -->
<div class="checkbox">
<label class="form-checkbox form-normal form-primary" data-bind="css: {'active': card.approved}" style="padding-left: 25px; padding-top: 3px;">
<input type="checkbox" data-bind="checked: card.approved"/>
<label class="form-checkbox form-normal form-primary" data-bind="css: {'active': card.approved, 'disabled': $parent.locked}" style="padding-left: 25px; padding-top: 3px;">
<input type="checkbox" data-bind="checked: card.approved, attr: {disabled: $parent.locked}"/>
<span data-bind="text: card.name"></span>
</label>
</div>
Expand All @@ -450,7 +450,7 @@ <h1 class="page-header text-overflow mobile-designer-title">
<input class="" style="display:inline-block;"
data-bind="select2Query: {
select2Config: getSelect2ResourcesConfig()
}">
}, attr: {disabled: locked}">
</div>
</div>

Expand All @@ -472,9 +472,14 @@ <h1 class="page-header text-overflow mobile-designer-title">
<div class="mpm-item-listing-header data-panel">
{% trans 'Allow users to download data' %}
<span class="toggle-container">
<!--ko ifnot: locked-->
<span class="switch switch-small" data-bind="css: {'on': mobilesurvey.datadownloadconfig.download()}, click: function(){
mobilesurvey.datadownloadconfig.download(!mobilesurvey.datadownloadconfig.download());
}"><small></small></span>
<!--/ko-->
<!--ko if: locked-->
<span class="switch switch-small disabled" data-bind="css: {'on': mobilesurvey.datadownloadconfig.download()"><small></small></span>
<!--/ko-->
</span>
</div>

Expand All @@ -498,7 +503,7 @@ <h1 class="page-header text-overflow mobile-designer-title">
<div>
<div class="pad-top">
<label style="display:flex; align-items:center">{% trans 'Limit ' %}
<input type="number" class="form-control" style="width: 100px; margin-left: 7px;" placeholder="Search query URL" data-bind="textInput: mobilesurvey.datadownloadconfig.count, event: {'change': convertCountToInt}"></input>
<input type="number" class="form-control" style="width: 100px; margin-left: 7px;" placeholder="Search query URL" data-bind="textInput: mobilesurvey.datadownloadconfig.count, event: {'change': convertCountToInt}, attr: {disabled: locked}"></input>
</label>
</div>

Expand Down Expand Up @@ -526,7 +531,7 @@ <h1 class="page-header text-overflow mobile-designer-title">
<!-- Inline Checkboxes -->
<div class="checkbox">
<!-- ko foreach: {data:allResources, as: 'resource'} -->
<label class="form-checkbox form-normal form-primary" data-bind="text: resource.name, css: {'form-text' : true, active: _.contains($parent.mobilesurvey.datadownloadconfig.resources(), resource.id), disabled: resource.hasApprovedCards() === false}, click: function(r){if (r.hasApprovedCards()){$parent.mobilesurvey.updateResourceDownloadList(r)}}"><input type="checkbox"></label>
<label class="form-checkbox form-normal form-primary" data-bind="text: resource.name, css: {'form-text' : true, active: _.contains($parent.mobilesurvey.datadownloadconfig.resources(), resource.id), disabled: resource.hasApprovedCards() === false || $parent.locked}, click: function(r){if (r.hasApprovedCards()){$parent.mobilesurvey.updateResourceDownloadList(r)}}"><input type="checkbox"></label>
<!-- /ko -->
</div>
</div>
Expand All @@ -539,7 +544,7 @@ <h1 class="page-header text-overflow mobile-designer-title">
</p>

<div class="form-group">
<input type="text" id="" class="form-control" placeholder="Search query URL" data-bind="textInput: mobilesurvey.datadownloadconfig.custom">
<input type="text" id="" class="form-control" placeholder="Search query URL" data-bind="textInput: mobilesurvey.datadownloadconfig.custom, attr: {disabled: locked}">
</div>
</div>
</div>
Expand All @@ -562,7 +567,7 @@ <h1 class="page-header text-overflow mobile-designer-title">
<input style="width:30%; display:inline-block;"
data-bind="select2Query: {
select2Config: getSelect2GroupsConfig()
}">
}, attr: {disabled: locked}">
</div>
</div>

Expand Down Expand Up @@ -610,10 +615,10 @@ <h1 class="page-header text-overflow mobile-designer-title">
<div class="msm-user-account-panel">
<!--ko foreach: {data: selectedNode().fullusers, as: 'user'} -->
<div class="msm-user-account-item checkbox" data-bind="click: function(){$parent.mobilesurvey.selectedUser(user); return true;};, css: {selected: user.id === $parent.mobilesurvey.selectedUser().id}, visible: user.filtered() === false" class="userrow">
<label class="form-checkbox form-normal form-primary" data-bind="css: {'active': user.approved}" style="padding-left: 25px; padding-top: 3px;">
<input type="checkbox" data-bind="checked: user.approved, event: {'change': $parent.mobilesurvey.toggleIdentity}"/>
<span data-bind="text: user.name"></span>
<label class="form-checkbox form-normal form-primary" data-bind="css: {'active': user.approved, 'disabled': $parent.locked}" style="padding-left: 25px; padding-top: 3px;">
<input type="checkbox" data-bind="checked: user.approved, event: {'change': $parent.mobilesurvey.toggleIdentity}, attr: {disabled: $parent.locked}"/>
</label>
<span style="vertical-align: top" data-bind="text: user.name"></span>
</div>
<!--/ko-->
</div>
Expand Down
11 changes: 1 addition & 10 deletions arches/app/views/mobile_survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,6 @@ class MobileSurveyDesignerView(MapBaseManagerView):

def get(self, request, surveyid):

def get_last_login(date):
result = _("Not yet logged in")
try:
if date is not None:
result = datetime.strftime(date, '%Y-%m-%d %H:%M')
except TypeError as e:
print e
return result

def get_history(survey, history):
sync_log_records = models.MobileSyncLog.objects.order_by('-finished').values().filter(survey=survey)
if len(sync_log_records) > 0:
Expand All @@ -181,7 +172,7 @@ def get_history(survey, history):
for group in Group.objects.all():
users = group.user_set.all()
if len(users) > 0:
groupUsers = [{'id': user.id, 'first_name': user.first_name, 'last_name': user.last_name, 'email': user.email, 'last_login': get_last_login(user.last_login), 'username': user.username, 'groups': [g.id for g in user.groups.all()], 'group_names': ', '.join([g.name for g in user.groups.all()])} for user in users]
groupUsers = [{'id': user.id, 'first_name': user.first_name, 'last_name': user.last_name, 'email': user.email, 'username': user.username, 'groups': [g.id for g in user.groups.all()], 'group_names': ', '.join([g.name for g in user.groups.all()])} for user in users]
identities.append({'name': group.name, 'type': 'group', 'id': group.pk, 'users': groupUsers, 'default_permissions': group.permissions.all()})
for user in User.objects.filter():
groups = []
Expand Down

0 comments on commit 56f0e40

Please sign in to comment.