Add a configurable avatar system and add an internal avatar system for enterprise

This commit is contained in:
Joseph Schorr 2014-11-24 19:25:13 -05:00
parent f6dd8b0a4d
commit e9cac407df
36 changed files with 241 additions and 92 deletions

View file

@ -2,7 +2,7 @@ import logging
from flask import request
from app import billing as stripe
from app import billing as stripe, avatar
from endpoints.api import (resource, nickname, ApiResource, validate_json_request, request_error,
related_user_resource, internal_only, Unauthorized, NotFound,
require_user_admin, log_action, show_if)
@ -13,7 +13,6 @@ from auth.permissions import (AdministerOrganizationPermission, OrganizationMem
from auth.auth_context import get_authenticated_user
from data import model
from data.billing import get_plan
from util.gravatar import compute_hash
import features
@ -28,7 +27,7 @@ def org_view(o, teams):
view = {
'name': o.username,
'email': o.email if is_admin else '',
'gravatar': compute_hash(o.email),
'avatar': avatar.compute_hash(o.email, name=o.username),
'teams': {t.name : team_view(o.username, t) for t in teams},
'is_admin': is_admin
}
@ -274,14 +273,16 @@ class ApplicationInformation(ApiResource):
if not application:
raise NotFound()
org_hash = compute_hash(application.organization.email)
gravatar = compute_hash(application.gravatar_email) if application.gravatar_email else org_hash
org_hash = avatar.compute_hash(application.organization.email,
name=application.organization.username)
app_hash = (avatar.compute_hash(application.avatar_email, name=application.name) if
application.avatar_email else org_hash)
return {
'name': application.name,
'description': application.description,
'uri': application.application_uri,
'gravatar': gravatar,
'avatar': app_hash,
'organization': org_view(application.organization, [])
}
@ -297,7 +298,7 @@ def app_view(application):
'client_id': application.client_id,
'client_secret': application.client_secret if is_admin else None,
'redirect_uri': application.redirect_uri if is_admin else None,
'gravatar_email': application.gravatar_email if is_admin else None,
'avatar_email': application.avatar_email if is_admin else None,
}
@ -330,9 +331,9 @@ class OrganizationApplications(ApiResource):
'type': 'string',
'description': 'The human-readable description for the application',
},
'gravatar_email': {
'avatar_email': {
'type': 'string',
'description': 'The e-mail address of the gravatar to use for the application',
'description': 'The e-mail address of the avatar to use for the application',
}
},
},
@ -371,7 +372,7 @@ class OrganizationApplications(ApiResource):
app_data.get('application_uri', ''),
app_data.get('redirect_uri', ''),
description = app_data.get('description', ''),
gravatar_email = app_data.get('gravatar_email', None),)
avatar_email = app_data.get('avatar_email', None),)
app_data.update({
@ -416,9 +417,9 @@ class OrganizationApplicationResource(ApiResource):
'type': 'string',
'description': 'The human-readable description for the application',
},
'gravatar_email': {
'avatar_email': {
'type': 'string',
'description': 'The e-mail address of the gravatar to use for the application',
'description': 'The e-mail address of the avatar to use for the application',
}
},
},
@ -462,7 +463,7 @@ class OrganizationApplicationResource(ApiResource):
application.application_uri = app_data['application_uri']
application.redirect_uri = app_data['redirect_uri']
application.description = app_data.get('description', '')
application.gravatar_email = app_data.get('gravatar_email', None)
application.avatar_email = app_data.get('avatar_email', None)
application.save()
app_data.update({

View file

@ -6,7 +6,7 @@ from auth.permissions import (OrganizationMemberPermission, ViewTeamPermission,
AdministerOrganizationPermission)
from auth.auth_context import get_authenticated_user
from auth import scopes
from util.gravatar import compute_hash
from app import avatar
@resource('/v1/entities/<prefix>')
@ -44,7 +44,7 @@ class EntitySearch(ApiResource):
'name': namespace_name,
'kind': 'org',
'is_org_member': True,
'gravatar': compute_hash(organization.email),
'avatar': avatar.compute_hash(organization.email, name=organization.username),
}]
except model.InvalidOrganizationException:

View file

@ -8,7 +8,7 @@ from auth.auth_context import get_authenticated_user
from auth import scopes
from data import model
from util.useremails import send_org_invite_email
from util.gravatar import compute_hash
from app import avatar
import features
@ -63,7 +63,7 @@ def member_view(member, invited=False):
'name': member.username,
'kind': 'user',
'is_robot': member.robot,
'gravatar': compute_hash(member.email) if not member.robot else None,
'avatar': avatar.compute_hash(member.email, name=member.username) if not member.robot else None,
'invited': invited,
}
@ -75,7 +75,7 @@ def invite_view(invite):
return {
'email': invite.email,
'kind': 'invite',
'gravatar': compute_hash(invite.email),
'avatar': avatar.compute_hash(invite.email),
'invited': True
}

View file

@ -5,7 +5,7 @@ from flask import request
from flask.ext.login import logout_user
from flask.ext.principal import identity_changed, AnonymousIdentity
from app import app, billing as stripe, authentication
from app import app, billing as stripe, authentication, avatar
from endpoints.api import (ApiResource, nickname, resource, validate_json_request, request_error,
log_action, internal_only, NotFound, require_user_admin, parse_args,
query_param, InvalidToken, require_scope, format_date, hide_if, show_if,
@ -20,7 +20,6 @@ from auth.permissions import (AdministerOrganizationPermission, CreateRepository
UserAdminPermission, UserReadPermission, SuperUserPermission)
from auth.auth_context import get_authenticated_user
from auth import scopes
from util.gravatar import compute_hash
from util.useremails import (send_confirmation_email, send_recovery_email, send_change_email, send_password_changed)
from util.names import parse_single_urn
@ -34,7 +33,7 @@ def user_view(user):
admin_org = AdministerOrganizationPermission(o.username)
return {
'name': o.username,
'gravatar': compute_hash(o.email),
'avatar': avatar.compute_hash(o.email, name=o.username),
'is_org_admin': admin_org.can(),
'can_create_repo': admin_org.can() or CreateRepositoryPermission(o.username).can(),
'preferred_namespace': not (o.stripe_id is None)
@ -61,7 +60,7 @@ def user_view(user):
'anonymous': False,
'username': user.username,
'email': user.email,
'gravatar': compute_hash(user.email),
'avatar': avatar.compute_hash(user.email, name=user.username),
}
user_admin = UserAdminPermission(user.username)
@ -572,10 +571,12 @@ def authorization_view(access_token):
'name': oauth_app.name,
'description': oauth_app.description,
'url': oauth_app.application_uri,
'gravatar': compute_hash(oauth_app.gravatar_email or oauth_app.organization.email),
'avatar': avatar.compute_hash(oauth_app.avatar_email or oauth_app.organization.email,
name=oauth_app.name),
'organization': {
'name': oauth_app.organization.username,
'gravatar': compute_hash(oauth_app.organization.email)
'avatar': avatar.compute_hash(oauth_app.organization.email,
name=oauth_app.organization.username)
}
},
'scopes': scopes.get_scope_information(access_token.scope),