Start on controllers and the API for organizations. Also adds fake model methods
This commit is contained in:
parent
621f89f826
commit
d7148b1711
5 changed files with 99 additions and 3 deletions
|
@ -166,17 +166,53 @@ def verify_user(username, password):
|
||||||
# We weren't able to authorize the user
|
# We weren't able to authorize the user
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
class dotdict(dict):
|
||||||
|
def __getattr__(self, name):
|
||||||
|
return self[name]
|
||||||
|
|
||||||
|
|
||||||
|
def get_user_organizations(username):
|
||||||
|
# TODO: return the orgs that the user is apart of.
|
||||||
|
return [dotdict({
|
||||||
|
'username': 'testorg',
|
||||||
|
'email': 'testorg@quay.io'
|
||||||
|
})]
|
||||||
|
|
||||||
|
|
||||||
|
def lookup_organization(name, username=None):
|
||||||
|
if name == 'testorg':
|
||||||
|
return dotdict({
|
||||||
|
'username': 'testorg',
|
||||||
|
'email': 'testorg@quay.io'
|
||||||
|
})
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def get_user_teams(username, organization):
|
||||||
|
# TODO: return the teams that the user is apart of.
|
||||||
|
return [dotdict({
|
||||||
|
'id': 1234,
|
||||||
|
'name': 'Owners'
|
||||||
|
})]
|
||||||
|
|
||||||
|
|
||||||
def get_visible_repositories(username=None, include_public=True, limit=None,
|
def get_visible_repositories(username=None, include_public=True, limit=None,
|
||||||
sort=False):
|
sort=False, namespace=None):
|
||||||
if not username and not include_public:
|
if not username and not include_public:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
query = Repository.select().distinct().join(Visibility)
|
query = Repository.select().distinct()
|
||||||
|
|
||||||
|
if namespace:
|
||||||
|
query = query.where(Repository.namespace == namespace)
|
||||||
|
|
||||||
|
query = query.join(Visibility)
|
||||||
or_clauses = []
|
or_clauses = []
|
||||||
if include_public:
|
if include_public:
|
||||||
or_clauses.append((Visibility.name == 'public'))
|
or_clauses.append((Visibility.name == 'public'))
|
||||||
|
|
||||||
|
|
||||||
if username:
|
if username:
|
||||||
with_perms = query.switch(Repository).join(RepositoryPermission,
|
with_perms = query.switch(Repository).join(RepositoryPermission,
|
||||||
JOIN_LEFT_OUTER)
|
JOIN_LEFT_OUTER)
|
||||||
|
|
|
@ -53,10 +53,18 @@ def welcome():
|
||||||
|
|
||||||
@app.route('/api/user/', methods=['GET'])
|
@app.route('/api/user/', methods=['GET'])
|
||||||
def get_logged_in_user():
|
def get_logged_in_user():
|
||||||
|
def org_view(o):
|
||||||
|
return {
|
||||||
|
'name': o.username,
|
||||||
|
'gravatar': compute_hash(o.email),
|
||||||
|
}
|
||||||
|
|
||||||
if current_user.is_anonymous():
|
if current_user.is_anonymous():
|
||||||
return jsonify({'anonymous': True})
|
return jsonify({'anonymous': True})
|
||||||
|
|
||||||
user = current_user.db_user()
|
user = current_user.db_user()
|
||||||
|
organizations = model.get_user_organizations(user.username)
|
||||||
|
|
||||||
return jsonify({
|
return jsonify({
|
||||||
'verified': user.verified,
|
'verified': user.verified,
|
||||||
'anonymous': False,
|
'anonymous': False,
|
||||||
|
@ -64,8 +72,10 @@ def get_logged_in_user():
|
||||||
'email': user.email,
|
'email': user.email,
|
||||||
'gravatar': compute_hash(user.email),
|
'gravatar': compute_hash(user.email),
|
||||||
'askForPassword': user.password_hash is None,
|
'askForPassword': user.password_hash is None,
|
||||||
|
'organizations': [org_view(o) for o in organizations]
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/user/', methods=['PUT'])
|
@app.route('/api/user/', methods=['PUT'])
|
||||||
@api_login_required
|
@api_login_required
|
||||||
def change_user_details():
|
def change_user_details():
|
||||||
|
@ -179,6 +189,32 @@ user_files = UserRequestFiles(app.config['AWS_ACCESS_KEY'],
|
||||||
app.config['AWS_SECRET_KEY'],
|
app.config['AWS_SECRET_KEY'],
|
||||||
app.config['REGISTRY_S3_BUCKET'])
|
app.config['REGISTRY_S3_BUCKET'])
|
||||||
|
|
||||||
|
@app.route('/api/organization/<orgname>', methods=['GET'])
|
||||||
|
def get_organization(orgname):
|
||||||
|
def team_view(t):
|
||||||
|
return {
|
||||||
|
'id': t.id,
|
||||||
|
'name': t.name
|
||||||
|
}
|
||||||
|
|
||||||
|
def org_view(o, teams):
|
||||||
|
return {
|
||||||
|
'name': o.username,
|
||||||
|
'gravatar': compute_hash(o.email),
|
||||||
|
'teams': [team_view(t) for t in teams]
|
||||||
|
}
|
||||||
|
|
||||||
|
if current_user.is_anonymous():
|
||||||
|
abort(404)
|
||||||
|
|
||||||
|
user = current_user.db_user()
|
||||||
|
organization = model.lookup_organization(orgname, username = user.username)
|
||||||
|
if not organization:
|
||||||
|
abort(404)
|
||||||
|
|
||||||
|
teams = model.get_user_teams(user.username, organization)
|
||||||
|
return jsonify(org_view(organization, teams))
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/repository', methods=['POST'])
|
@app.route('/api/repository', methods=['POST'])
|
||||||
@api_login_required
|
@api_login_required
|
||||||
|
@ -236,6 +272,7 @@ def list_repos_api():
|
||||||
}
|
}
|
||||||
|
|
||||||
limit = request.args.get('limit', None)
|
limit = request.args.get('limit', None)
|
||||||
|
namespace_filter = request.args.get('namespace', None)
|
||||||
include_public = request.args.get('public', 'true')
|
include_public = request.args.get('public', 'true')
|
||||||
include_private = request.args.get('private', 'true')
|
include_private = request.args.get('private', 'true')
|
||||||
sort = request.args.get('sort', 'false')
|
sort = request.args.get('sort', 'false')
|
||||||
|
@ -255,7 +292,7 @@ def list_repos_api():
|
||||||
|
|
||||||
repo_query = model.get_visible_repositories(username, limit=limit,
|
repo_query = model.get_visible_repositories(username, limit=limit,
|
||||||
include_public=include_public,
|
include_public=include_public,
|
||||||
sort=sort)
|
sort=sort, namespace=namespace_filter)
|
||||||
repos = [repo_view(repo) for repo in repo_query]
|
repos = [repo_view(repo) for repo in repo_query]
|
||||||
response = {
|
response = {
|
||||||
'repositories': repos
|
'repositories': repos
|
||||||
|
|
|
@ -43,6 +43,7 @@ def load_user(username):
|
||||||
|
|
||||||
@app.route('/', methods=['GET'], defaults={'path': ''})
|
@app.route('/', methods=['GET'], defaults={'path': ''})
|
||||||
@app.route('/repository/<path:path>', methods=['GET'])
|
@app.route('/repository/<path:path>', methods=['GET'])
|
||||||
|
@app.route('/organization/<path:path>', methods=['GET'])
|
||||||
def index(path):
|
def index(path):
|
||||||
return render_template('index.html')
|
return render_template('index.html')
|
||||||
|
|
||||||
|
|
|
@ -200,6 +200,11 @@ quayApp = angular.module('quay', ['restangular', 'angularMoment', 'angulartics',
|
||||||
when('/signin/', {title: 'Signin', templateUrl: '/static/partials/signin.html', controller: SigninCtrl}).
|
when('/signin/', {title: 'Signin', templateUrl: '/static/partials/signin.html', controller: SigninCtrl}).
|
||||||
when('/new/', {title: 'Create new repository', templateUrl: '/static/partials/new-repo.html', controller: NewRepoCtrl}).
|
when('/new/', {title: 'Create new repository', templateUrl: '/static/partials/new-repo.html', controller: NewRepoCtrl}).
|
||||||
|
|
||||||
|
when('/organization/:orgname', {templateUrl: '/static/partials/org-view.html', controller: OrgViewCtrl}).
|
||||||
|
when('/organization/:orgname/admin', {templateUrl: '/static/partials/org-admin.html', controller: OrgAdminCtrl}).
|
||||||
|
when('/organization/:orgname/teams', {templateUrl: '/static/partials/org-teams.html', controller: OrgTeamsCtrl}).
|
||||||
|
when('/organization/:orgname/teams/:teamname', {templateUrl: '/static/partials/team-view.html', controller: TeamViewCtrl}).
|
||||||
|
|
||||||
when('/v1/', {title: 'Activation information', templateUrl: '/static/partials/v1-page.html', controller: V1Ctrl}).
|
when('/v1/', {title: 'Activation information', templateUrl: '/static/partials/v1-page.html', controller: V1Ctrl}).
|
||||||
|
|
||||||
when('/', {title: 'Hosted Private Docker Registry', templateUrl: '/static/partials/landing.html', controller: LandingCtrl}).
|
when('/', {title: 'Hosted Private Docker Registry', templateUrl: '/static/partials/landing.html', controller: LandingCtrl}).
|
||||||
|
|
|
@ -1125,4 +1125,21 @@ function NewRepoCtrl($scope, $location, $http, UserService, Restangular, PlanSer
|
||||||
// User has no subscription
|
// User has no subscription
|
||||||
$scope.planRequired = PlanService.getMinimumPlan(1);
|
$scope.planRequired = PlanService.getMinimumPlan(1);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function OrgViewCtrl($scope, Restangular, $routeParams) {
|
||||||
|
var orgname = $routeParams.orgname;
|
||||||
|
}
|
||||||
|
|
||||||
|
function OrgAdminCtrl($scope, Restangular, $routeParams) {
|
||||||
|
var orgname = $routeParams.orgname;
|
||||||
|
}
|
||||||
|
|
||||||
|
function OrgTeamsCtrl($scope, Restangular, $routeParams) {
|
||||||
|
var orgname = $routeParams.orgname;
|
||||||
|
}
|
||||||
|
|
||||||
|
function TeamViewCtrl($scope, Restangular, $routeParams) {
|
||||||
|
var orgname = $routeParams.orgname;
|
||||||
|
var teamname = $routeParams.teamname;
|
||||||
}
|
}
|
Reference in a new issue