Skip to content

Commit

Permalink
Merge branch 'release/0.117.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
brianjgeiger committed Jul 13, 2017
2 parents 5f321d5 + 280295d commit dd06be1
Show file tree
Hide file tree
Showing 129 changed files with 8,390 additions and 5,971 deletions.
13 changes: 12 additions & 1 deletion addons/base/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,12 +748,23 @@ def addon_view_file(auth, node, file_node, version):
'file_tags': list(file_node.tags.filter(system=False).values_list('name', flat=True)) if not file_node._state.adding else [], # Only access ManyRelatedManager if saved
'file_guid': file_node.get_guid()._id,
'file_id': file_node._id,
'allow_comments': file_node.provider in settings.ADDONS_COMMENTABLE
'allow_comments': file_node.provider in settings.ADDONS_COMMENTABLE,
'checkout_user': file_node.checkout._id if file_node.checkout else None,
'pre_reg_checkout': is_pre_reg_checkout(node, file_node),
})

ret.update(rubeus.collect_addon_assets(node))
return ret

def is_pre_reg_checkout(node, file_node):
checkout_user = file_node.checkout
if not checkout_user:
return False
if checkout_user in node.contributors:
return False
if checkout_user.has_perm('osf.prereg_view'):
return node.draft_registrations_active.filter(registration_schema__name='Prereg Challenge').exists()
return False

def get_archived_from_url(node, file_node):
if file_node.copied_from:
Expand Down
4 changes: 2 additions & 2 deletions addons/forward/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ class ForwardAddonAppConfig(BaseAddonAppConfig):

name = 'addons.forward'
label = 'addons_forward'
full_name = 'External Link'
full_name = 'Redirect Link'
short_name = 'forward'
configs = ['node']
configs = []
owners = ['node']
views = ['widget']
categories = ['other']
Expand Down
139 changes: 86 additions & 53 deletions addons/forward/static/forwardConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,29 @@ var $osf = require('js/osfHelpers');

var MESSAGE_TIMEOUT = 5000;

var DEFAULT_FORWARD_BOOL = true;

/**
* Knockout view model for the Forward node settings widget.
*/
var ViewModel = function(url, nodeId) {
var ViewModel = function(node, enabled, url, label) {

var self = this;

// Forward configuration
self.url = ko.observable().extend({
var forwardUrl = $osf.apiV2Url('nodes/' + node.id + '/addons/forward/');

self.enabled = ko.observable(enabled);
self.label = koHelpers.sanitizedObservable(label);
self.url = ko.observable(url).extend({
ensureHttp: true,
url: true,
required: true
});

// Flashed messages
self.message = ko.observable('');
self.messageClass = ko.observable('text-info');

self.pendingRequest = ko.observable(false);

ko.validation.addAnonymousRule(
self.url,
koHelpers.makeRegexValidator(
Expand All @@ -31,50 +39,54 @@ var ViewModel = function(url, nodeId) {
false
)
);
self.label = koHelpers.sanitizedObservable();

// Flashed messages
self.message = ko.observable('');
self.messageClass = ko.observable('text-info');

self.validators = ko.validatedObservable({
url: self.url,
});


/**
* Update the view model from data returned from the server.
*/
self.updateFromData = function(data) {
self.url(data.url);
self.label(data.label);
};

self.fetchFromServer = function() {
$.ajax({
type: 'GET',
url: url,
dataType: 'json'
}).done(function(response) {
self.updateFromData(response);
}).fail(function(xhr, textStatus, error) {
self.changeMessage('Could not retrieve Forward settings at ' +
'this time. Please refresh ' +
'the page. If the problem persists, email ' +
'<a href="mailto:[email protected]">[email protected]</a>.',
'text-danger');
Raven.captureMessage('Could not GET get Forward addon settings.', {
extra: {
url: url,
textStatus: textStatus,
error: error
self.enabled.subscribe(function(newValue) {
self.pendingRequest(true);
if (!newValue) {
$osf.ajaxJSON(
'delete',
forwardUrl,
{'isCors': true}
).done(function(response) {
self.pendingRequest(false);
}).fail(function(xhr, status, error) {
$osf.growl('Error', 'Unable to disable redirect link.');
Raven.captureMessage('Error disabling redirect link.', {
extra: {
url: forwardUrl, status: status, error: error
}
});
});
} else {
$osf.ajaxJSON(
'post',
forwardUrl,
{
'data': {
'data': {
'id': 'forward',
'type': 'node_addons',
'attributes': {}
}
},
'isCors': true
}
).done(function(response) {
self.pendingRequest(false);
}).fail(function(xhr, status, error) {
$osf.growl('Error', 'Unable to enable redirect link.');
Raven.captureMessage('Error enabling redirect link.', {
extra: {
url: forwardUrl, status: status, error: error
}
});
});
});
};

// Initial fetch from server
self.fetchFromServer();
}
});

function onSubmitSuccess() {
if (self.url() == null) {
Expand Down Expand Up @@ -103,24 +115,45 @@ var ViewModel = function(url, nodeId) {
}
else {
self.changeMessage(
'Could not change settings. Please try again later.',
'Could not change redirect link settings. Please try again later.',
'text-danger'
);
Raven.captureMessage('Error updating redirect link.', {
extra: {
url: forwardUrl, status: status, error: error
}
});
}
}

/**
* Submit new settings.
*/
self.submitSettings = function() {
$osf.putJSON(
url,
ko.toJS(self)
).done(
onSubmitSuccess
).fail(
onSubmitError
);
self.pendingRequest(true);
$osf.ajaxJSON(
'put',
forwardUrl,
{
'data': {
'data': {
'id': 'forward',
'type': 'node_addons',
'attributes': {
'url': self.url(),
'label': self.label()
}
}
},
'isCors': true
}
).done(function(response) {
onSubmitSuccess()
self.pendingRequest(false);
}).fail(function(response) {
onSubmitError()
self.pendingRequest(false);
});
};

/** Change the flashed message. */
Expand All @@ -140,9 +173,9 @@ var ViewModel = function(url, nodeId) {
};

// Public API
function ForwardConfig(selector, url, nodeId) {
function ForwardConfig(selector, node, enabled, url, label) {
var self = this;
self.viewModel = new ViewModel(url, nodeId);
self.viewModel = new ViewModel(node, enabled, url, label);
$osf.applyBindings(self.viewModel, selector);
}

Expand Down
34 changes: 29 additions & 5 deletions addons/forward/static/node-cfg.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,31 @@
var $osf = require('js/osfHelpers');
var ForwardConfig = require('./forwardConfig.js');

var url = window.contextVars.node.urls.api + 'forward/config/';
// #forwardScope will only be in the DOM if the addon is properly configured
if ($('#forwardScope')[0]) {
new ForwardConfig('#forwardScope', url, window.contextVars.node.id);
}
var ctx = window.contextVars;

var enabled = false;
var url = '';
var label = '';

$(document).ready(function() {
$osf.ajaxJSON(
'GET',
$osf.apiV2Url('nodes/' + ctx.node.id + '/addons/'),
{'isCors': true}
).done(function(response){
response.data.forEach(function(addon) {
if (addon.id === 'forward') {
enabled = true;
url = addon.attributes.url;
label = addon.attributes.label;
}
});
new ForwardConfig('#configureForward', ctx.node, enabled, url, label);
}).fail(function(response){
$osf.growl('Error:', 'Unable to retrieve settings.');
Raven.captureMessage('Error occurred retrieving node addons');
});

});


7 changes: 1 addition & 6 deletions addons/forward/templates/forward_node_settings.mako
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
<div id="forwardScope" class="scripted">

<h4 class="addon-title">
<i class="fa fa-external-link"></i>
External Link
</h4>

<!-- Settings Pane -->
<div class="forward-settings">

Expand All @@ -16,7 +11,7 @@
id="forwardUrl"
class="form-control"
data-bind="value: url"
placeholder="Required"
placeholder="Send people who visit your OSF project page to this link instead"
/>
</div>

Expand Down
1 change: 1 addition & 0 deletions admin/base/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
url(r'^password/', include('password_reset.urls')),
url(r'^nodes/', include('admin.nodes.urls', namespace='nodes')),
url(r'^preprints/', include('admin.preprints.urls', namespace='preprints')),
url(r'^subjects/', include('admin.subjects.urls', namespace='subjects')),
url(r'^users/', include('admin.users.urls', namespace='users')),
url(r'^meetings/', include('admin.meetings.urls',
namespace='meetings')),
Expand Down
4 changes: 4 additions & 0 deletions admin/nodes/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
name='confirm-spam'),
url(r'^(?P<guid>[a-z0-9]+)/confirm_ham/$', views.NodeConfirmHamView.as_view(),
name='confirm-ham'),
url(r'^(?P<guid>[a-z0-9]+)/reindex_share_node/$', views.NodeReindexShare.as_view(),
name='reindex-share-node'),
url(r'^(?P<guid>[a-z0-9]+)/reindex_elastic_node/$', views.NodeReindexElastic.as_view(),
name='reindex-elastic-node'),
url(r'^(?P<node_id>[a-z0-9]+)/remove_user/(?P<user_id>[a-z0-9]+)/$',
views.NodeRemoveContributorView.as_view(), name='remove_user'),
]
50 changes: 48 additions & 2 deletions admin/nodes/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from django.contrib.auth.mixins import PermissionRequiredMixin
from modularodm import Q

from website import search
from osf.models import NodeLog
from osf.models.user import OSFUser
from osf.models.node import Node
Expand All @@ -19,9 +20,14 @@
NODE_REMOVED,
NODE_RESTORED,
CONTRIBUTOR_REMOVED,
CONFIRM_SPAM, CONFIRM_HAM)
CONFIRM_SPAM,
CONFIRM_HAM,
REINDEX_SHARE,
REINDEX_ELASTIC,
)
from admin.nodes.templatetags.node_extras import reverse_node
from admin.nodes.serializers import serialize_node, serialize_simple_user_and_node_permissions
from website.project.tasks import update_share
from website.project.views.register import osf_admin_change_status_identifier


Expand Down Expand Up @@ -238,7 +244,7 @@ def get_queryset(self):
query = (
Q('spam_status', 'eq', self.SPAM_STATE)
)
return Node.find(query).sort(self.ordering)
return Node.find(query).order_by(self.ordering)

def get_context_data(self, **kwargs):
query_set = kwargs.pop('object_list', self.object_list)
Expand Down Expand Up @@ -318,3 +324,43 @@ def delete(self, request, *args, **kwargs):
action_flag=CONFIRM_HAM
)
return redirect(reverse_node(self.kwargs.get('guid')))

class NodeReindexShare(PermissionRequiredMixin, NodeDeleteBase):
template_name = 'nodes/reindex_node_share.html'
permission_required = 'osf.mark_spam'
raise_exception = True

def get_object(self, queryset=None):
return Node.load(self.kwargs.get('guid')) or Registration.load(self.kwargs.get('guid'))

def delete(self, request, *args, **kwargs):
node = self.get_object()
update_share(node)
update_admin_log(
user_id=self.request.user.id,
object_id=node._id,
object_repr='Node',
message='Node Reindexed (SHARE): {}'.format(node._id),
action_flag=REINDEX_SHARE
)
return redirect(reverse_node(self.kwargs.get('guid')))

class NodeReindexElastic(PermissionRequiredMixin, NodeDeleteBase):
template_name = 'nodes/reindex_node_elastic.html'
permission_required = 'osf.mark_spam'
raise_exception = True

def get_object(self, queryset=None):
return Node.load(self.kwargs.get('guid')) or Registration.load(self.kwargs.get('guid'))

def delete(self, request, *args, **kwargs):
node = self.get_object()
search.search.update_node(node, bulk=False, async=False)
update_admin_log(
user_id=self.request.user.id,
object_id=node._id,
object_repr='Node',
message='Node Reindexed (Elastic): {}'.format(node._id),
action_flag=REINDEX_ELASTIC
)
return redirect(reverse_node(self.kwargs.get('guid')))
7 changes: 6 additions & 1 deletion admin/preprint_providers/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,12 @@ def get_context_data(self, *args, **kwargs):
preprint_provider_attributes = model_to_dict(preprint_provider)
kwargs.setdefault('page_number', self.request.GET.get('page', '1'))

preprint_provider_attributes['licenses_acceptable'] = preprint_provider.licenses_acceptable.values_list('name', flat=True)
licenses_acceptable = list(preprint_provider.licenses_acceptable.values_list('name', flat=True))
licenses_html = '<ul>'
for license in licenses_acceptable:
licenses_html += '<li>{}</li>'.format(license)
licenses_html += '</ul>'
preprint_provider_attributes['licenses_acceptable'] = licenses_html

subject_html = '<ul class="three-cols">'
for parent in preprint_provider.top_level_subjects:
Expand Down
Loading

0 comments on commit dd06be1

Please sign in to comment.