Skip to content

Change public info #2833

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jan 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions tests/unit/accounts/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,3 +566,11 @@ def test_profile_callout_returns_user(self):
request = pretend.stub()

assert views.profile_callout(user, request) == {"user": user}


class TestEditProfileButton:

def test_edit_profile_button(self):
request = pretend.stub()

assert views.edit_profile_button(request) == {}
81 changes: 78 additions & 3 deletions tests/unit/manage/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,85 @@

class TestManageProfile:

def test_manage_profile(self):
request = pretend.stub()
def test_manage_profile(self, monkeypatch):
user_service = pretend.stub()
name = pretend.stub()
request = pretend.stub(
find_service=lambda *a, **kw: user_service,
user=pretend.stub(name=name),
)
save_profile_obj = pretend.stub()
save_profile_cls = pretend.call_recorder(lambda **kw: save_profile_obj)
monkeypatch.setattr(views, 'SaveProfileForm', save_profile_cls)
view_class = views.ManageProfileViews(request)

assert view_class.manage_profile() == {
'save_profile_form': save_profile_obj,
}
assert view_class.request == request
assert view_class.user_service == user_service
assert save_profile_cls.calls == [
pretend.call(name=name),
]

def test_save_profile(self, monkeypatch):
update_user = pretend.call_recorder(lambda *a, **kw: None)
request = pretend.stub(
POST={'name': 'new name'},
user=pretend.stub(id=pretend.stub()),
session=pretend.stub(
flash=pretend.call_recorder(lambda *a, **kw: None),
),
find_service=pretend.call_recorder(
lambda iface, context: pretend.stub(update_user=update_user)
),
)
save_profile_obj = pretend.stub(
validate=lambda: True,
data=request.POST,
)
save_profile_cls = pretend.call_recorder(lambda d: save_profile_obj)
monkeypatch.setattr(views, 'SaveProfileForm', save_profile_cls)
view_class = views.ManageProfileViews(request)

assert views.manage_profile(request) == {}
assert view_class.save_profile() == {
'save_profile_form': save_profile_obj,
}
assert request.session.flash.calls == [
pretend.call('Public profile updated.', queue='success'),
]
assert update_user.calls == [
pretend.call(request.user.id, **request.POST)
]
assert save_profile_cls.calls == [
pretend.call(request.POST),
]

def test_save_profile_validation_fails(self, monkeypatch):
update_user = pretend.call_recorder(lambda *a, **kw: None)
request = pretend.stub(
POST={'name': 'new name'},
user=pretend.stub(id=pretend.stub()),
session=pretend.stub(
flash=pretend.call_recorder(lambda *a, **kw: None),
),
find_service=pretend.call_recorder(
lambda iface, context: pretend.stub(update_user=update_user)
),
)
save_profile_obj = pretend.stub(validate=lambda: False)
save_profile_cls = pretend.call_recorder(lambda d: save_profile_obj)
monkeypatch.setattr(views, 'SaveProfileForm', save_profile_cls)
view_class = views.ManageProfileViews(request)

assert view_class.save_profile() == {
'save_profile_form': save_profile_obj,
}
assert request.session.flash.calls == []
assert update_user.calls == []
assert save_profile_cls.calls == [
pretend.call(request.POST),
]


class TestManageProjects:
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ def add_policy(name, filename):
traverse="/{project_name}",
domain=warehouse,
),
pretend.call(
"includes.edit-profile-button",
"/_includes/edit-profile-button/",
domain=warehouse,
),
pretend.call("search", "/search/", domain=warehouse),
pretend.call(
"accounts.profile",
Expand Down
9 changes: 9 additions & 0 deletions warehouse/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,3 +371,12 @@ def _login_user(request, userid):
)
def profile_callout(user, request):
return {"user": user}


@view_config(
route_name="includes.edit-profile-button",
renderer="includes/accounts/edit-profile-button.html",
uses_session=True,
)
def edit_profile_button(request):
return {}
7 changes: 7 additions & 0 deletions warehouse/manage/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,10 @@ def __init__(self, *args, user_service, **kwargs):

class ChangeRoleForm(RoleNameMixin, forms.Form):
pass


class SaveProfileForm(forms.Form):

__params__ = ['name']

name = wtforms.StringField()
39 changes: 34 additions & 5 deletions warehouse/manage/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,53 @@

from pyramid.httpexceptions import HTTPSeeOther
from pyramid.security import Authenticated
from pyramid.view import view_config
from pyramid.view import view_config, view_defaults
from sqlalchemy.orm.exc import NoResultFound

from warehouse.accounts.interfaces import IUserService
from warehouse.accounts.models import User
from warehouse.manage.forms import CreateRoleForm, ChangeRoleForm
from warehouse.manage.forms import (
CreateRoleForm, ChangeRoleForm, SaveProfileForm
)
from warehouse.packaging.models import JournalEntry, Role
from warehouse.utils.project import confirm_project, remove_project


@view_config(
@view_defaults(
route_name="manage.profile",
renderer="manage/profile.html",
uses_session=True,
require_csrf=True,
require_methods=False,
effective_principals=Authenticated,
)
def manage_profile(request):
return {}
class ManageProfileViews:
def __init__(self, request):
self.request = request
self.user_service = request.find_service(IUserService, context=None)

@view_config(request_method="GET")
def manage_profile(self):
return {
'save_profile_form': SaveProfileForm(name=self.request.user.name),
}

@view_config(
request_method="POST",
request_param=SaveProfileForm.__params__,
)
def save_profile(self):
form = SaveProfileForm(self.request.POST)

if form.validate():
self.user_service.update_user(self.request.user.id, **form.data)
self.request.session.flash(
'Public profile updated.', queue='success'
)

return {
'save_profile_form': form,
}


@view_config(
Expand Down
5 changes: 5 additions & 0 deletions warehouse/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ def includeme(config):
traverse="/{project_name}",
domain=warehouse,
)
config.add_route(
"includes.edit-profile-button",
"/_includes/edit-profile-button/",
domain=warehouse,
)

# Search Routes
config.add_route("search", "/search/", domain=warehouse)
Expand Down
58 changes: 42 additions & 16 deletions warehouse/static/sass/blocks/_author-profile.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,54 @@

<div class="author-profile">
// Avatar here (no class required)
<h1 class="author-profile__name">
// Username
</h1>
<div class="author-profile__meta"
<p>
// Meta
</p>
<div class="author-progile__info">
<h1 class="author-profile__name">
// Username
</h1>
<div class="author-profile__meta"
<p>
// Meta
</p>
</div>
<a class="author-profile__edit-button">Edit Profile</a>
</div>
</div>
*/

.author-profile {
padding-right: $spacing-unit;
padding-bottom: $spacing-unit;

@media only screen and (max-width: $desktop){
@media only screen and (min-width: $desktop) {
padding-right: $spacing-unit;
}

@media only screen and (max-width: $desktop) and (min-width: $mobile) {
padding: 0 0 ($spacing-unit * 1.5) 0;
display: flex;
align-items: center;

img {
height: 175px;
margin-right: $spacing-unit;
}
}

img {
@media only screen and (max-width: $mobile) {
img {
display: none;
margin-right: 0;
}
}

h1.author-profile__name {
padding: 10px 0;
border-top: 2px solid $border-color;
border-bottom: 2px solid $border-color;
margin: 20px 0;
word-break: break-all;
&__info {
padding-top: $spacing-unit;
}

&__name {
@include h2;
overflow: hidden;
text-overflow: ellipsis;
padding: 0 0 $spacing-unit / 2;

@media only screen and (max-width: $desktop){
border-top: 0;
Expand All @@ -56,4 +76,10 @@
&__meta {
font-style: italic;
}

&__edit-button {
margin-top: $spacing-unit;
width: 100%;
text-align: center;
}
}
6 changes: 5 additions & 1 deletion warehouse/static/sass/blocks/_button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@
border-radius: 3px;
display: inline-block;
white-space: nowrap;
vertical-align: center;

i.fa {
position: relative;
top: 2px;
}

&:focus,
&:hover,
Expand Down
5 changes: 5 additions & 0 deletions warehouse/static/sass/blocks/_form-group.scss
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
max-width: 100%;
}

&__text {
font-size: 20px;
padding: 4px 0 8px;
}

&__help-text {
padding: 0;
margin-top: 5px;
Expand Down
50 changes: 50 additions & 0 deletions warehouse/static/sass/blocks/_gravatar-form.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*!
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
A form field, with label, input, and help text.

<div class="gravatar-form">
<img class="gravatar-form__image"/>
<div class="gravatar-form__content">
content here
</div>
</div>
*/

.gravatar-form {
display: flex;
align-items: center;

&__image {
margin-right: $spacing-unit / 2;
}

&__content {
max-width: 400px;
}

@media screen and (max-width: $small-tablet) {
display: block;

&__image {
margin-right: 0;
}

&__content {
max-width: 100%;
margin-top: 15px;
}
}
}
2 changes: 1 addition & 1 deletion warehouse/static/sass/settings/_fonts.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ $code-font: "Source Code Pro", monospace;

$em-base: 17px;
$base-font-size: 17px;
$small-font-size: $base-font-size * 0.8;
$small-font-size: $base-font-size * 0.9;
$button-font-size: $base-font-size;
$input-font-size: $base-font-size * 1.1;

Expand Down
1 change: 1 addition & 0 deletions warehouse/static/sass/warehouse.scss
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
@import "blocks/footer";
@import "blocks/form-errors";
@import "blocks/form-group";
@import "blocks/gravatar-form";
@import "blocks/heading-wsubtitle";
@import "blocks/homepage-banner";
@import "blocks/horizontal-menu";
Expand Down
Loading