Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def root_page_name(self, new_root_page_name):
globals = WM.Globals.query.get(app_config_id=self.config._id)
if globals is not None:
globals.root = new_root_page_name
elif new_root_page_name != self.default_root_page_name:
globals = WM.Globals(
app_config_id=self.config._id, root=new_root_page_name)
if globals is not None:
session(globals).flush(globals)
id=c.user._id,
username=c.user.username,
display_name=c.user.get_pref('display_name'),
logged_ip=ip_address),
data=state(self).clone())
while True:
self.version += 1
data['version'] = self.version
data['timestamp'] = datetime.utcnow()
ss = self.__mongometa__.history_class(**data)
try:
session(ss).insert_now(ss, state(ss))
except pymongo.errors.DuplicateKeyError:
log.warning('Trying to create duplicate version %s of %s',
self.version, self.__class__)
session(ss).expunge(ss)
continue
else:
break
log.debug('Snapshot version %s of %s',
self.version, self.__class__)
if update_stats:
if self.version > 1:
g.statsUpdater.modifiedArtifact(
self.type_s, self.mod_date, self.project, c.user)
else:
g.statsUpdater.newArtifact(
self.type_s, self.mod_date, self.project, c.user)
return ss
t = Thread.new(
app_config_id=self.app_config_id,
discussion_id=self.app_config.discussion_id,
ref_id=idx['id'],
subject='%s discussion' % h.get_first(idx, 'title'))
elif len(threads) == 1:
t = threads[0]
else:
# there should not be multiple threads, we'll merge them
destination = threads.pop()
for thread in threads:
for post in thread.posts:
post.thread_id = destination._id
destination.num_replies += 1
destination.last_post_date = max(destination.last_post_date, post.mod_date)
session(post).flush(post)
session(post).expunge(post) # so thread.posts ref later in the code doesn't use stale posts
Thread.query.remove({'_id': thread._id}) # NOT thread.delete() since that would remove its posts too
thread.attachment_class().query.update({'thread_id': thread._id},
{'$set': {'thread_id': destination._id}},
multi=True)
t = destination
parent_id = None
if data:
in_reply_to = data.get('in_reply_to', [])
if in_reply_to:
parent_id = in_reply_to[0]
return t, parent_id
'Mount point "%s" is already in use' % mount_point)
assert self.app_instance(mount_point) is None
if ordinal is None:
ordinal = int(self.ordered_mounts(include_search=True)[-1]['ordinal']) + 1
options = App.default_options()
options['mount_point'] = mount_point
options['mount_label'] = mount_label or App.default_mount_label or mount_point
options['ordinal'] = int(ordinal)
options.update(override_options)
cfg = AppConfig(
project_id=self._id,
tool_name=ep_name,
options=options)
app = App(self, cfg)
with h.push_config(c, project=self, app=app):
session(cfg).flush()
app.install(self)
return app
def main():
test = sys.argv[-1] == 'test'
projects = M.Project.query.find().all()
log.info('Restoring labels on projects')
for p in projects:
restore_labels(p, test)
if not test:
session(p).flush()
log.info('Restoring labels on artifacts')
for p in projects:
if p.parent_id:
continue
c.project = p
for name, cls in MappedClass._registry.iteritems():
if not issubclass(cls, M.Artifact):
continue
if session(cls) is None:
continue
for a in cls.query.find():
restore_labels(a, test)
if not test:
M.artifact_orm_session.flush()
M.artifact_orm_session.clear()
def add_login_detail(self, detail):
try:
session(detail).flush(detail)
except DuplicateKeyError:
session(detail).expunge(detail)
def register(cls, shortname, fullname, orgtype, user):
o=cls.query.get(shortname=shortname)
if o is not None: return None
try:
o = cls(
shortname=shortname,
fullname=fullname,
organization_type=orgtype)
session(o).flush(o)
except pymongo.errors.DuplicateKeyError:
session(o).expunge(o)
return None
if o is not None:
n = M.Neighborhood.query.get(name='Organizations')
n.register_project('o/'+shortname, user=user, user_project=False)
return o
if user.disabled:
log.info('User %s is already disabled', user.username)
continue
provider.disable_user(user, audit=False)
msg = u'Account disabled because project {}{} is deleted. Reason: {}'.format(
project.neighborhood.url_prefix,
project.shortname,
reason)
auditlog = h.auditlog_user(msg, user=user)
if auditlog:
session(auditlog).flush(auditlog)
else:
log.error('For some reason no auditlog written in disable_project_users for: %s %s', user, msg)
# `users` can contain duplicates. Make sure changes are visible
# to next iterations, so that `user.disabled` check works.
session(user).expunge(user)
'app_config_id': c.app.config._id,
'artifact_index_id': {'$in': artifact_index_ids},
'topic': {'$in': [None, topic]}
}
mboxes = cls.query.find(d).all()
log.debug('Delivering notification %s to mailboxes [%s]', nid, ', '.join([str(m._id) for m in mboxes]))
for mbox in mboxes:
try:
mbox.query.update(
# _id is automatically specified by ming's "query", so this matches the current mbox
{'$push': dict(queue=nid),
'$set': dict(last_modified=datetime.utcnow(),
queue_empty=False),
})
# Make sure the mbox doesn't stick around to be flush()ed
session(mbox).expunge(mbox)
except:
# log error but try to keep processing, lest all the other eligible
# mboxes for this notification get skipped and lost forever
log.exception(
'Error adding notification: %s for artifact %s on project %s to user %s',
nid, artifact_index_ids, c.project._id, mbox.user_id)
def _fs(cls):
return GridFS(
session(cls).impl.db,
cls._root_collection())