Пример #1
0
MojErr MojDbQuotaEngine::stats(MojObject& objOut, MojDbReq& req)
{
	// check for admin permission
	if (!req.admin()) {
		MojErrThrow(MojErrDbPermissionDenied);
	}
	for (QuotaMap::ConstIterator i = m_quotas.begin(); i != m_quotas.end(); ++i) {
		MojObject quota;
		MojErr err = quota.put(MojDbServiceDefs::SizeKey, i.value()->size());
		MojErrCheck(err);
		err = quota.put(MojDbServiceDefs::UsedKey, i.value()->usage());
		MojErrCheck(err);
		err = objOut.put(i.key(), quota);
		MojErrCheck(err);
	}
	return MojErrNone;
}
Пример #2
0
MojErr MojDbQuotaEngine::put(MojObject& obj, MojDbReq& req, bool putObj)
{
	MojLogTrace(s_log);
	MojAssertWriteLocked(m_db->schemaLock());

	// check for admin permission
	if (!req.admin()) {
		MojErrThrow(MojErrDbPermissionDenied);
	}

	// pull params out of object
	MojString owner;
	MojErr err = obj.getRequired(MojDbServiceDefs::OwnerKey, owner);
	MojErrCheck(err);
	MojInt64 size = 0;
	err = obj.getRequired(MojDbServiceDefs::SizeKey, size);
	MojErrCheck(err);

	// validate owner
	err = validateWildcard(owner, MojErrDbInvalidOwner);
	MojErrCheck(err);

	// put object
	if (putObj) {
		MojString id;
		err = id.format(_T("_quotas/%s"), owner.data());
		MojErrCheck(err);
		err = obj.put(MojDb::IdKey, id);
		MojErrCheck(err);
		err = obj.putString(MojDb::KindKey, MojDbKindEngine::QuotaId);
		MojErrCheck(err);

		MojDbAdminGuard adminGuard(req);
		err = m_db->put(obj, MojDb::FlagForce, req);
		MojErrCheck(err);

		// defer commit of quota until txn commit
		MojRefCountedPtr<MojDbQuotaCommitHandler> handler(new MojDbQuotaCommitHandler(this, owner, size, req.txn()));
		MojAllocCheck(handler.get());
	} else {
		err = commitQuota(owner, size);
		MojErrCheck(err);
	}
	return MojErrNone;
}
Пример #3
0
bool MojDbKind::hasOwnerPermission(MojDbReq& req)
{
	return (req.admin() || req.domain() == m_owner);
}
Пример #4
0
MojErr MojDbKind::configure(const MojObject& obj, const KindMap& map, const MojString& locale, MojDbReq& req)
{
	MojLogTrace(s_log);

	// get owner before checking permissions
	MojString owner;
	MojErr err = obj.getRequired(OwnerKey, owner);
	MojErrCheck(err);
	// only admin can change owner
	if (!m_owner.empty() && m_owner != owner && !req.admin()) {
		err = deny(req);
		MojErrCheck(err);
	}
	m_owner = owner;

	err = checkPermission(OpKindUpdate, req);
	MojErrCheck(err);

	// schema
	MojObject schema;
	if (obj.get(SchemaKey,schema)) {
		err = m_schema.fromObject(schema);
		MojErrCheck(err);
	}
	// supers
	StringVec superIds;
	MojObject supers;
	if (obj.get(ExtendsKey, supers)) {
		MojObject::ConstArrayIterator end = supers.arrayEnd();
		for (MojObject::ConstArrayIterator i = supers.arrayBegin(); i != end; ++i) {
			MojString str;
			err = i->stringValue(str);
			MojErrCheck(err);
			err = superIds.push(str);
			MojErrCheck(err);
		}
	}
	// backup
	bool backup = false;
	if (obj.get(SyncKey, backup))
		m_backup = backup;
	bool updating = !m_obj.undefined();

	// load state
	m_state.reset(new MojDbKindState(m_id, m_kindEngine));
	MojAllocCheck(m_state.get());
	err = m_state->init(m_schema.strings(), req);
	MojErrCheck(err);
	// indexes
	err = configureIndexes(obj, locale, req);
	MojErrCheck(err);
	// supers
	err = updateSupers(map, superIds, updating, req);
	MojErrCheck(err);
	// revision sets
	err = configureRevSets(obj);
	MojErrCheck(err);

	// keep a copy of obj
	m_obj = obj;

	return MojErrNone;
}