Add robots to the entity search.

This commit is contained in:
yackob03 2013-11-20 18:23:59 -05:00
parent 026ed7ffb4
commit b407c1d9fb
8 changed files with 51 additions and 30 deletions

View file

@ -379,11 +379,19 @@ def get_matching_teams(team_prefix, organization):
return query.limit(10)
def get_matching_users(username_prefix, organization=None):
def get_matching_users(username_prefix, robot_namespace=None,
organization=None):
Org = User.alias()
users_no_orgs = (User.username ** (username_prefix + '%') &
(User.organization == False))
query = User.select(User.username, Org.username).where(users_no_orgs)
direct_user_query = (User.username ** (username_prefix + '%') &
(User.organization == False) & (User.robot == False))
if robot_namespace:
robot_prefix = format_robot_username(robot_namespace, username_prefix)
direct_user_query = (direct_user_query |
(User.username ** (robot_prefix + '%') &
(User.robot == True)))
query = User.select(User.username, Org.username, User.robot).where(direct_user_query)
if organization:
with_team = query.join(TeamMember, JOIN_LEFT_OUTER).join(Team,
@ -396,6 +404,7 @@ def get_matching_users(username_prefix, organization=None):
class MatchingUserResult(object):
def __init__(self, *args):
self.username = args[0]
self.is_robot = args[2]
if organization:
self.is_org_member = (args[1] == organization.username)
else:

View file

@ -260,20 +260,26 @@ def get_matching_users(prefix):
def get_matching_entities(prefix):
teams = []
organization_name = request.args.get('organization', None)
namespace_name = request.args.get('namespace', None)
robot_namespace = None
organization = None
if organization_name:
permission = OrganizationMemberPermission(organization_name)
if permission.can():
try:
organization = model.get_organization(organization_name)
except model.InvalidOrganizationException:
pass
organization = model.get_organization(namespace_name)
if organization:
# namespace name was an org
permission = OrganizationMemberPermission(namespace_name)
if permission.can():
robot_namespace = namespace_name
if request.args.get('includeTeams', False):
teams = model.get_matching_teams(prefix, organization)
users = model.get_matching_users(prefix, organization)
except model.InvalidOrganizationException:
# namespace name was a user
if current_user.db_user().username == namespace_name:
robot_namespace = namespace_name
users = model.get_matching_users(prefix, robot_namespace, organization)
def entity_team_view(team):
result = {
@ -286,7 +292,7 @@ def get_matching_entities(prefix):
def user_view(user):
user_json = {
'name': user.username,
'kind': 'user',
'kind': 'robot' if user.is_robot else 'user',
}
if user.is_org_member is not None:

View file

@ -132,6 +132,8 @@ def populate_database():
new_user_1.verified = True
new_user_1.save()
model.create_robot('dtrobot', new_user_1)
new_user_2 = model.create_user('public', 'password',
'jacob.moshenko@gmail.com')
new_user_2.verified = True
@ -188,6 +190,8 @@ def populate_database():
org.stripe_id = TEST_STRIPE_ID
org.save()
model.create_robot('neworgrobot', org)
owners = model.get_organization_team('buynlarge', 'owners')
owners.description = 'Owners have unfetterd access across the entire org.'
owners.save()

View file

@ -604,9 +604,10 @@ quayApp.directive('entitySearch', function () {
transclude: false,
restrict: 'C',
scope: {
'organization': '=organization',
'namespace': '=namespace',
'inputTitle': '=inputTitle',
'entitySelected': '=entitySelected'
'entitySelected': '=entitySelected',
'includeTeams': '=includeTeams'
},
controller: function($scope, $element) {
if (!$scope.entitySelected) { return; }
@ -614,15 +615,16 @@ quayApp.directive('entitySearch', function () {
number++;
var input = $element[0].firstChild;
$scope.organization = $scope.organization || '';
$scope.namespace = $scope.namespace || '';
$(input).typeahead({
name: 'entities' + number,
remote: {
url: '/api/entities/%QUERY',
replace: function (url, uriEncodedQuery) {
url = url.replace('%QUERY', uriEncodedQuery);
if ($scope.organization) {
url += '?organization=' + encodeURIComponent($scope.organization);
url += '?namespace=' + encodeURIComponent($scope.namespace);
if ($scope.includeTeams) {
url += '&includeTeams=true'
}
return url;
},
@ -648,7 +650,7 @@ quayApp.directive('entitySearch', function () {
}
template += '<span class="name">' + datum.value + '</span>';
if (datum.entity.is_org_member !== undefined && !datum.entity.is_org_member) {
if (datum.entity.is_org_member !== undefined && !datum.entity.is_org_member && datum.kind == 'user') {
template += '<div class="alert-warning warning">This user is outside your organization</div>';
}

View file

@ -1296,7 +1296,7 @@ function TeamViewCtrl($rootScope, $scope, Restangular, $routeParams) {
'html': true
});
var orgname = $routeParams.orgname;
$scope.orgname = $routeParams.orgname;
var teamname = $routeParams.teamname;
$rootScope.title = 'Loading...';
@ -1307,7 +1307,7 @@ function TeamViewCtrl($rootScope, $scope, Restangular, $routeParams) {
if ($scope.members[member.name]) { return; }
$scope.$apply(function() {
var addMember = Restangular.one(getRestUrl('organization', orgname, 'team', teamname, 'members', member.name));
var addMember = Restangular.one(getRestUrl('organization', $scope.orgname, 'team', teamname, 'members', member.name));
addMember.customPOST().then(function(resp) {
$scope.members[member.name] = resp;
}, function() {
@ -1317,7 +1317,7 @@ function TeamViewCtrl($rootScope, $scope, Restangular, $routeParams) {
};
$scope.removeMember = function(username) {
var removeMember = Restangular.one(getRestUrl('organization', orgname, 'team', teamname, 'members', username));
var removeMember = Restangular.one(getRestUrl('organization', $scope.orgname, 'team', teamname, 'members', username));
removeMember.customDELETE().then(function(resp) {
delete $scope.members[username];
}, function() {
@ -1328,7 +1328,7 @@ function TeamViewCtrl($rootScope, $scope, Restangular, $routeParams) {
$scope.updateForDescription = function(content) {
$scope.organization.teams[teamname].description = content;
var updateTeam = Restangular.one(getRestUrl('organization', orgname, 'team', teamname));
var updateTeam = Restangular.one(getRestUrl('organization', $scope.orgname, 'team', teamname));
var data = $scope.organization.teams[teamname];
updateTeam.customPUT(data).then(function(resp) {
}, function() {
@ -1337,7 +1337,7 @@ function TeamViewCtrl($rootScope, $scope, Restangular, $routeParams) {
};
var loadOrganization = function() {
var getOrganization = Restangular.one(getRestUrl('organization', orgname))
var getOrganization = Restangular.one(getRestUrl('organization', $scope.orgname))
getOrganization.get().then(function(resp) {
$scope.organization = resp;
$scope.team = $scope.organization.teams[teamname];
@ -1350,12 +1350,12 @@ function TeamViewCtrl($rootScope, $scope, Restangular, $routeParams) {
};
var loadMembers = function() {
var getMembers = Restangular.one(getRestUrl('organization', orgname, 'team', teamname, 'members'));
var getMembers = Restangular.one(getRestUrl('organization', $scope.orgname, 'team', teamname, 'members'));
getMembers.get().then(function(resp) {
$scope.members = resp.members;
$scope.canEditMembers = resp.can_edit;
$scope.loading = !$scope.organization || !$scope.members;
$rootScope.title = teamname + ' (' + orgname + ')';
$rootScope.title = teamname + ' (' + $scope.orgname + ')';
}, function() {
$scope.organization = null;
$scope.members = null;

View file

@ -91,7 +91,7 @@
<tr>
<td colspan="2">
<span class="entity-search" organization="repo.namespace" input-title="'Add a ' + (repo.is_organization ? 'team or ' : '') + 'user...'" entity-selected="addNewPermission"></span>
<span class="entity-search" namespace="repo.namespace" include-teams="true" input-title="'Add a ' + (repo.is_organization ? 'team or ' : '') + 'user...'" entity-selected="addNewPermission"></span>
</td>
</tr>
</table>

View file

@ -33,7 +33,7 @@
<tr ng-show="canEditMembers">
<td colspan="2">
<span class="entity-search" organization="''" input-title="'Add a user...'" entity-selected="addNewMember"></span>
<span class="entity-search" namespace="orgname" include-teams="false" input-title="'Add a user...'" entity-selected="addNewMember"></span>
</td>
</tr>
</table>

Binary file not shown.