本文整理汇总了Python中server.models.ssuser.SSUser类的典型用法代码示例。如果您正苦于以下问题:Python SSUser类的具体用法?Python SSUser怎么用?Python SSUser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SSUser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: read
def read(self, userName):
theUser = SSUser.readByName(userName)
if not theUser:
return error("User %s does not exist" % userName, UserDoesNotExistError)
loggedInUser = SSUser.read(helper.getLoggedInUser())
canReadFull = loggedInUser.canReadFull(theUser)
return data(theUser.toDict((loggedInUser and canReadFull)))
示例2: update
def update(self, fields, updateDbs=True):
from server.models.ssuser import SSUser
if fields.get("content"):
self.content = fields.get("content")
if fields.get("summary"):
self.summary = self.content["summary"] = fields.get("summary")
if fields.get("broken"):
self.broken = fields.get("broken")
if fields.get("dbs"):
self.dbs = list(set(self.dbs.extend(fields.get("dbs"))))
self.modified = datetime.now()
# update the correct user db
if self.publishData.private:
db = SSUser.privateDb(self.createdBy)
else:
db = SSUser.publicDb(self.createdBy)
self.store(core.connect(db))
core.replicate(db, "shiftspace/shared")
# update followers and groups
if updateDbs:
for db in self.publishData.dbs:
dbtype, dbid = db.split("/")
if dbtype == "group":
from server.models.group import Group
Group.read(dbid).updateShift(self)
return Shift.joinData(self, self.createdBy)
示例3: publish
def publish(self, id):
# NOTE: should maybe take publishData url parameter - David 9/5/2009
loggedInUser = helper.getLoggedInUser()
theShift = Shift.read(id, loggedInUser)
if not theShift:
return error("Resource does not exist.", ResourceDoesNotExistError)
if theShift.type != "shift":
return error("Resource is not of type shift", ResourceTypeError)
publishData = json.loads(helper.getRequestBody())
# convert targets to actual database references
if publishData.get("targets"):
from server.models.group import Group
from server.models.ssuser import SSUser
theUser = SSUser.read(loggedInUser)
targets = publishData["targets"]
# convert short names to group ids
shortNames = [target[1:] for target in targets if target[0] == "&"]
groupIds = Group.shortNamesToIds(shortNames)
# convert user name to user ids
userNames = [target[1:] for target in targets if target[0] == "@"]
userIds = SSUser.namesToIds(userNames)
# create list of dbs being published to
dbs = [Group.db(groupId) for groupId in groupIds]
dbs.extend([SSUser.db(userId) for userId in userIds])
# validate
writeable = theUser.writeable()
if set(writeable) != set(dbs):
return error("Operation not permitted. You don't have permission to publish to some of these gruops", PermissionError)
publishData["dbs"] = dbs
return data(theShift.publish(publishData))
示例4: unfollow
def unfollow(self, userName):
theUser = SSUser.read(helper.getLoggedInUser())
followed = SSUser.readByName(userName)
if theUser.id == followed.id:
return error("You cannot unfollow yourself.", FollowError)
else:
theUser.unfollow(followed)
return data(followed)
示例5: unreadCount
def unreadCount(self, userName):
loggedInUser = helper.getLoggedInUser()
theUser = SSUser.read(loggedInUser)
otherUser = SSUser.readByName(userName)
if loggedInUser == otherUser.id or theUser.isAdmin():
return data(theUser.unreadCount())
else:
return error("You do not have permission to view this user's unread count.", PermissionError)
示例6: groups
def groups(self, userName, start=None, end=None, limit=25):
loggedInUser = helper.getLoggedInUser()
theUser = SSUser.read(loggedInUser)
otherUser = SSUser.readByName(userName)
if loggedInUser == otherUser.id or theUser.isAdmin():
return data(otherUser.groups(start=start, end=end, limit=limit))
else:
return error("You don't have permission to view this user's groups.", PermissionError)
示例7: create
def create(cls, shiftJson):
from server.models.ssuser import SSUser
newShift = Shift(**utils.clean(shiftJson))
createdBy = newShift.createdBy
db = core.connect(SSUser.privateDb(createdBy))
newShift.domain = utils.domain(newShift.href)
newShift.store(db)
core.replicate(SSUser.privateDb(createdBy), "shiftspace/shared")
return Shift.joinData(newShift, newShift.createdBy)
示例8: update
def update(self, userName):
theUser = SSUser.readByName(userName)
if not theUser:
return error("User %s does not exist" % userName, UserDoesNotExistError)
loggedInUser = SSUser.read(helper.getLoggedInUser())
if loggedInUser and loggedInUser.canModify(theUser):
theData = json.loads(helper.getRequestBody())
return data(theUser.update(theData))
else:
return error("Operation not permitted. You don't have permission to update this account.")
示例9: makeAdmin
def makeAdmin(self, id, userId):
from server.models.ssuser import SSUser
theGroup = Group.read(id)
theUser = SSUser.read(helper.getLoggedInUser())
if theUser.isAdminOf(theGroup):
otherUser = SSUser.read(userId)
theGroup.setPrivilege(otherUser, 3)
return ack
else:
return error("You don't have permission to promote members of this group to admin.", PermissionError)
示例10: delete
def delete(self):
from server.models.ssuser import SSUser
db = core.connect(SSUser.privateDb(self.createdBy))
if db.get(self.id):
del db[self.id]
else:
db = core.connect(SSUser.publicDb(self.createdBy))
if db.get(self.id):
del db[self.id]
core.replicate(db.name, "shiftspace/shared")
示例11: create
def create(cls, userId, shiftId, text, subscribe=False):
from server.models.ssuser import SSUser
from server.models.shift import Shift
from server.models.message import Message
# first try the public feed
theShift = Shift.load(core.connect("shiftspace/shared"), shiftId)
shiftAuthor = SSUser.load(core.connect(), theShift.createdBy)
theUser = SSUser.load(core.connect(), userId)
server = core.server()
# create the comment db if necessary
dbexists = True
if not theShift.hasThread():
server.create(Comment.db(shiftId))
dbexists = False
# get the db
db = core.connect(Comment.db(shiftId))
# if db just created, sync the views and subscribe shift author
if not dbexists:
Comment.by_created.sync(db)
Comment.all_subscribed.sync(db)
shiftAuthor.subscribe(theShift)
# subscribe the user making the comment
if not theUser.isSubscribed(theShift) and subscribe:
theUser.subscribe(theShift)
# create comment and comment stub
json = {
"createdBy": userId,
"shiftId": shiftId,
"shiftAuthor": theShift.createdBy,
"text": text,
}
newComment = Comment(**utils.clean(json))
newComment.store(db)
subscribers = theShift.subscribers()
# make a private copy
# TODO: need to think about the implications of a private copy here - David
newComment.copyTo(SSUser.privateDb(theUser.id))
# send each subscriber a message
if len(subscribers) > 0:
# TODO: needs to be optimized with a fast join - David
for subscriber in subscribers:
if subscriber != userId:
astr = ((subscriber == theShift.createdBy) and "your") or ("%s's" % shiftAuthor.userName)
json = {
"fromId": userId,
"toId": subscriber,
"title": "%s just commented on %s shift!" % (theUser.userName, astr),
"text": "%s just commented on %s shift!" % (theUser.userName, astr),
"meta": "comment"
}
Message.create(**utils.clean(json))
# TODO: don't replicate if peer - David 11/21/09
core.replicate(Comment.db(shiftId), "shiftspace/shared")
return newComment
示例12: share
def share(self, id, users):
from server.models.ssuser import SSUser
loggedInUser = helper.getLoggedInUser()
theShift = Shift.read(id)
if not theShift or theShift.publishData.private:
return error("You don't have permission to view this shift.", PermissionError)
targets = users.split(" ")
userNames = [target[1:] for target in targets if target[0] == "@"]
userIds = SSUser.namesToIds(userNames)
theShift.shareWith(userIds, fromUser=SSUser.read(loggedInUser))
return ack
示例13: delete
def delete(self, userName):
theUser = SSUser.readByName(userName)
if not theUser:
return error("User %s does not exist" % userName, UserDoesNotExistError)
loggedInUser = SSUser.read(helper.getLoggedInUser())
if loggedInUser and loggedInUser.canModify(theUser):
if theUser.id == loggedInUser.id:
helper.setLoggedInUser(None)
theUser.delete()
return ack
else:
return error("Operation not permitted. You don't have permission to delete this account.")
示例14: inviteUsers
def inviteUsers(self, id, users):
from server.models.ssuser import SSUser
loggedInUser = helper.getLoggedInUser()
groupAdmin = SSUser.read(loggedInUser)
theGroup = Group.read(id)
if groupAdmin.isAdminOf(theGroup):
db = core.connect()
users = SSUser.all(db, keys=json.loads(users))
for user in users:
groupAdmin.inviteUser(theGroup, user)
return data(theGroup)
else:
return error("Operation not permitted. You don't have permission to modify this group", PermissionError)
示例15: markRead
def markRead(self, value=True):
from server.models.ssuser import SSUser
db = core.connect(SSUser.messagesDb(self.toId))
if value:
if not self.isRead():
db[Message.makeReadId(self.id, self.toId)] = {
"type": "message-read",
"msgId": self.id,
"toId": self.toId,
}
else:
del db[Message.makeReadId(self.id, self.toId)]
core.replicate(SSUser.messagesDb(self.toId), "shiftspace/shared")
return self