WHERE NOT EXISTS (SELECT 1 FROM user_app_pkg_view
WHERE uid=NEW.uid AND app_name=NEW.app_name);
+ SELECT RAISE(ABORT, 'App defined privilege already defined')
+ WHERE EXISTS (SELECT 1 FROM app_defined_privilege_view
+ WHERE uid=NEW.uid AND app_name=NEW.app_name AND privilege=NEW.privilege);
+
INSERT OR IGNORE INTO app_defined_privilege (app_id, uid, privilege, type, license)
VALUES ((SELECT app_id FROM app WHERE name=NEW.app_name), NEW.uid, NEW.privilege, NEW.type, NEW.license);
END;
WHERE NOT EXISTS (SELECT 1 FROM user_app_pkg_view
WHERE uid=NEW.uid AND app_name=NEW.app_name);
+ SELECT RAISE(ABORT, 'Client privilege license already defined')
+ WHERE EXISTS (SELECT 1 FROM client_license_view
+ WHERE uid=NEW.uid AND app_name=NEW.app_name AND privilege=NEW.privilege);
+
INSERT OR IGNORE INTO client_license (app_id, uid, privilege, license)
VALUES ((SELECT app_id FROM app WHERE name=NEW.app_name), NEW.uid, NEW.privilege, NEW.license);
END;
// first application defines first privilege
BOOST_REQUIRE_NO_THROW(testPrivDb->AddAppDefinedPrivilege(app(1), uid(1), privileges[0]));
+ // privilege already defined
+ BOOST_REQUIRE_THROW(testPrivDb->AddAppDefinedPrivilege(app(1), uid(1), privileges[0]),
+ PrivilegeDb::Exception::ConstraintError);
+
// check non-existing privilege
std::string appName, license;
BOOST_REQUIRE_NO_THROW(
// first application use first privilege/license
BOOST_REQUIRE_NO_THROW(testPrivDb->AddClientPrivilege(app(1), uid(1), privilegesA[0].first, privilegesA[0].second));
+ // privilege license already defined
+ BOOST_REQUIRE_THROW(testPrivDb->AddClientPrivilege(app(1), uid(1), privilegesA[0].first, privilegesA[1].second),
+ PrivilegeDb::Exception::ConstraintError);
+
// check non-existing privilege
std::string license;
BOOST_REQUIRE_NO_THROW(testPrivDb->GetLicenseForClientPrivilege(app(1), uid(1), privilegesA[1].first, license));