当前位置: 首页>>代码示例>>Python>>正文


Python APIPermissions.get_user_by_key方法代码示例

本文整理汇总了Python中API.APIPermissions.get_user_by_key方法的典型用法代码示例。如果您正苦于以下问题:Python APIPermissions.get_user_by_key方法的具体用法?Python APIPermissions.get_user_by_key怎么用?Python APIPermissions.get_user_by_key使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在API.APIPermissions的用法示例。


在下文中一共展示了APIPermissions.get_user_by_key方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_user_get_user_by_key_succeed

# 需要导入模块: from API import APIPermissions [as 别名]
# 或者: from API.APIPermissions import get_user_by_key [as 别名]
	def test_user_get_user_by_key_succeed(self):
		usr = User('[email protected]')
		usr.set_nickname('Somebodyguks')
		usr.set_user_id('SomeUserid1234guks')
		key = ps.add_user(usr)

		self.assertEqual(ps.get_user_by_key(key).email(), usr.email())
开发者ID:Keesaco,项目名称:KeesaFlo,代码行数:9,代码来源:TestAPIPermissions.py

示例2: test_user_modify_user_by_id_succeed

# 需要导入模块: from API import APIPermissions [as 别名]
# 或者: from API.APIPermissions import get_user_by_key [as 别名]
	def test_user_modify_user_by_id_succeed(self):
		usr = User('[email protected]')
		usr.set_nickname('Somebodymids')
		usr.set_user_id('SomeUserid1234mids')
		ps.add_user(usr)

		newusr = User('[email protected]')
		newusr.set_nickname('SomebodyElsemids')
		newusr.set_user_id('SomeUotherId3878mids')
		key = ps.modify_user_by_id('SomeUserid1234mids',newusr)

		self.assertEqual(ps.get_user_by_key(key).email(), newusr.email())
开发者ID:Keesaco,项目名称:KeesaFlo,代码行数:14,代码来源:TestAPIPermissions.py

示例3: test_user_get_user_by_key_fail

# 需要导入模块: from API import APIPermissions [as 别名]
# 或者: from API.APIPermissions import get_user_by_key [as 别名]
	def test_user_get_user_by_key_fail(self):
		fakeKey = ndb.Key("doesntExist","noReally")

		self.assertIsNone(ps.get_user_by_key(fakeKey))
开发者ID:Keesaco,项目名称:KeesaFlo,代码行数:6,代码来源:TestAPIPermissions.py

示例4: file_permissions_json

# 需要导入模块: from API import APIPermissions [as 别名]
# 或者: from API.APIPermissions import get_user_by_key [as 别名]
def file_permissions_json(request):
	authed_user = auth.get_current_user()
	if authed_user is None:
		return __unauthed_response()
	
	user_key = ps.get_user_key_by_id(authed_user.user_id())

	json_response = {
		'success' 		: False,
		'users'			: []
	}

	try:
		list_req = json.loads(request.raw_post_data)
	except ValueError:
		json_response.update({'error' : 'Invalid request payload.'})
		return HttpResponse(json.dumps(json_response), content_type="application/json")

	if 'filename' not in list_req:
		json_response.update({'error' : 'Incomplete request.'})
		return HttpResponse(json.dumps(json_response), content_type="application/json")

	filename = list_req['filename']

	file_entry = ps.get_file_by_name(DATA_BUCKET + '/' + filename)
	if file_entry is None:
		json_response.update( { 'error' : 'File does not exist.' } )
		return HttpResponse(json.dumps(json_response), content_type="application/json")
		
	fp_entry = ps.get_user_file_permissions(file_entry.key, user_key)
	if fp_entry is None:
		json_response.update( { 'error' : 'Permission denied.' } )
		return HttpResponse(json.dumps(json_response), content_type="application/json")

	permissions_list = ps.get_file_permissions_list(file_entry.key)
	if permissions_list is None:
		json_response.update( { 'error' : 'Permission could not be retrieved.' } )
		return HttpResponse(json.dumps(json_response), content_type="application/json")

	for perm in permissions_list:
		new_perm = {}
		user = ps.get_user_by_key(perm.user_key)
		if user is not None:
			nickname = user.nickname()
			email = user.email()
			user_found = True
		else:
			nickname = 'Unknown'
			email = 'unknown'
			user_found = False

		new_perm.update( {
			'nickname' 		: nickname,
			'userFound'		: user_found,
			'email'			: email,
			'isMe'			: (perm.user_key == user_key),
			'permissions'	: {
				'read'			: perm.read,
				'write'			: perm.write,
				'fullControl'	: perm.full_control
			}
		} )

		json_response['users'].append(new_perm)

	json_response.update({ 'success' : True })
	return HttpResponse(json.dumps(json_response), content_type="application/json")
开发者ID:Keesaco,项目名称:KeesaFlo,代码行数:69,代码来源:views.py


注:本文中的API.APIPermissions.get_user_by_key方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。