Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 into fix-default-affiliated-insitution

* 'develop' of https://github.com/CenterForOpenScience/osf.io:
  [ENG-4560] Remove 'Untitled' as the default entry from the Title entry field for the draft registration (CenterForOpenScience#10454)
  make it so opening files happens in new tab (CenterForOpenScience#10459)

# Conflicts:
#	osf/models/mixins.py
#	osf/models/registrations.py
  • Loading branch information
John Tordoff committed Oct 17, 2023
2 parents bb2c6b2 + f1af4ad commit 4480ae6
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 19 deletions.
1 change: 1 addition & 0 deletions api_tests/draft_nodes/views/test_draft_node_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def test_detail_response(self, app, user, user_two):
assert res.status_code == 404

# cannot access draft node after it's been registered (it's now a node!)
draft_reg.title = 'test user generated title.'
draft_reg.register(Auth(user))
url = '/{}draft_nodes/{}/'.format(API_BASE, draft_node._id)
res = app.get(url, auth=user_two.auth, expect_errors=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def test_detail_view_returns_editable_fields_no_specified_node(self, app, user):
res = app.get(url, auth=user.auth, expect_errors=True)
attributes = res.json['data']['attributes']

assert attributes['title'] == 'Untitled'
assert attributes['title'] == ''
assert attributes['description'] == ''
assert attributes['category'] == ''
assert attributes['node_license'] is None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ def test_draft_registration_attributes_not_copied_from_node(self, app, project_p
res = app.post_json_api(url_draft_registrations, payload, auth=user.auth)
assert res.status_code == 201
attributes = res.json['data']['attributes']
assert attributes['title'] == 'Untitled'
assert attributes['title'] == ''
assert attributes['description'] != project_public.description
assert attributes['category'] != project_public.category
assert set(attributes['tags']) != set([tag.name for tag in project_public.tags.all()])
Expand Down
6 changes: 6 additions & 0 deletions api_tests/registrations/views/test_registration_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -1570,6 +1570,9 @@ def test_need_admin_perms_on_draft(
payload_ver['data']['attributes']['draft_registration_id'] = draft_registration._id
assert draft_registration.branched_from.is_admin_contributor(user) is False
assert draft_registration.has_permission(user, permissions.ADMIN) is True
assert draft_registration.title is ''
draft_registration.title = 'test user generated title required'
draft_registration.save()
res = app.post_json_api(url_registrations_ver, payload_ver, auth=user.auth)
assert res.status_code == 201

Expand All @@ -1578,6 +1581,9 @@ def test_need_admin_perms_on_draft(
assert draft_registration.branched_from.is_admin_contributor(user) is True
assert draft_registration.has_permission(user, permissions.ADMIN) is True
payload_ver['data']['attributes']['draft_registration_id'] = draft_registration._id
assert draft_registration.title is ''
draft_registration.title = 'test user generated title required'
draft_registration.save()
res = app.post_json_api(url_registrations_ver, payload_ver, auth=user.auth)
assert res.status_code == 201

Expand Down
24 changes: 13 additions & 11 deletions osf/models/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -2261,24 +2261,26 @@ def stage_m2m_values(self, fieldname, resource, alternative_resource=None):
else:
return []

def copy_editable_fields(
self, resource, alternative_resource=None, include_contributors=True, save=True, excluded_attributes=None
):
def copy_editable_fields(self, resource, alternative_resource=None, include_contributors=True, save=True, excluded_attributes=None):
"""
Copy editable fields from 'resource' to the current object. DraftRegistrations have different rules for creation
based on whether they are based on OSF Projects or are 'no-project` Registrations that will copu default
metadata information from the user, or some other source other then an OSF Project or Node.
This method copies various editable fields from the 'resource' object to the current object. Includes, title,
description, category, contributors, node_license, tags, subjects, and affiliated_institutions.
The field on the resource will always supersede the field on the alternative_resource. For example, copying
fields from the draft_registration to the registration. resource will be a DraftRegistration object, but the
alternative_resource will be a Node. DraftRegistration fields will trump Node fields.
:param Object resource: Primary resource to copy attributes from
:param Object resource: Primary resource where you want to copy attributes
:param Object alternative_resource: Backup resource for copying attributes
:param bool include_contributors: Whether to also copy contributors
:param bool save: Whether to save the changes immediately
:param List excluded_attributes: List of attributes to exclude from copying
:param Boolean include_contributors: represents whether to also copy the resource's contributors
:param Boolean save: represents whether to save the resources changes immediately
:param List: a list of strings representing attributes to exclude from copying
"""
if not excluded_attributes:
excluded_attributes = []

self._copy_basic_attributes(resource, alternative_resource, excluded_attributes)
for attribute in ['title', 'description', 'category', 'node_license']:
if attribute not in excluded_attributes:
self.set_editable_attribute(attribute, resource, alternative_resource)

if include_contributors:
# Contributors will always come from "resource", as contributor constraints
Expand Down
4 changes: 2 additions & 2 deletions osf/models/registrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -1265,8 +1265,8 @@ def create_from_node(cls, user, schema, node=None, data=None, provider=None):
if node:
branched_from = node
else:
branched_from = DraftNode.objects.create(creator=user, title='Untitled')
excluded_attributes = ['affiliated_institutions']
branched_from = DraftNode.objects.create(creator=user, title=settings.DEFAULT_DRAFT_NODE_TITLE)
excluded_attributes.append('title')

if not isinstance(branched_from, (Node, DraftNode)):
raise DraftRegistrationStateError()
Expand Down
5 changes: 3 additions & 2 deletions osf_tests/test_draft_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
get_default_metaschema,
)
from website.project.signals import after_create_registration
from website import settings

pytestmark = pytest.mark.django_db

Expand Down Expand Up @@ -123,8 +124,8 @@ def test_create_draft_registration_without_node(self, user):
schema=get_default_metaschema(),
data=data,
)
assert draft.title == 'Untitled'
assert draft.branched_from.title == 'Untitled'
assert draft.title == ''
assert draft.branched_from.title == settings.DEFAULT_DRAFT_NODE_TITLE
assert draft.branched_from.type == 'osf.draftnode'
assert draft.branched_from.creator == user
assert len(draft.logs.all()) == 0
Expand Down
2 changes: 1 addition & 1 deletion osf_tests/test_draft_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def test_create_from_node_draft_node(self, user):
schema=factories.get_default_metaschema(),
)

assert draft.title == 'Untitled'
assert draft.title == ''
assert draft.description == ''
assert draft.category == ''
assert user in draft.contributors.all()
Expand Down
1 change: 1 addition & 0 deletions website/settings/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -2129,3 +2129,4 @@ def from_node_usage(cls, usage_bytes, private_limit=None, public_limit=None):
PREPRINT_METRICS_START_DATE = datetime.datetime(2019, 1, 1)

WAFFLE_VALUES_YAML = 'osf/features.yaml'
DEFAULT_DRAFT_NODE_TITLE = 'Untitled'
2 changes: 1 addition & 1 deletion website/templates/project/project_header.mako
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
</a>
</li>
<li id="projectNavFiles">
<a href="${node['url']}files/" class="subnav-header">
<a href="${node['url']}files/" target="_blank" class="subnav-header">
Files
</a>
</li>
Expand Down

0 comments on commit 4480ae6

Please sign in to comment.