permissionsdao: no silent fallback to user-permissions if we find none for user
This commit is contained in:
orang tua
7630301168
melakukan
611ef12ca6
@ -10,6 +10,7 @@
|
||||
#include "sessiondao.h"
|
||||
#include "userdao.h"
|
||||
#include "categorydao.h"
|
||||
#include "permissionsdao.h"
|
||||
class Database
|
||||
{
|
||||
private:
|
||||
@ -32,6 +33,7 @@ class Database
|
||||
virtual std::unique_ptr<SessionDao> createSessionDao() const = 0;
|
||||
virtual std::unique_ptr<UserDao> createUserDao() const = 0;
|
||||
virtual std::unique_ptr<CategoryDao> createCategoryDao() const = 0;
|
||||
virtual std::unique_ptr<PermissionsDao> createPermissionsDao() const = 0;
|
||||
virtual ~Database()
|
||||
{
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ class PermissionsDao
|
||||
{
|
||||
public:
|
||||
PermissionsDao();
|
||||
virtual Permissions find(std::string pagename, std::string username) = 0;
|
||||
virtual std::optional<Permissions> find(std::string pagename, std::string username) = 0;
|
||||
};
|
||||
|
||||
#endif // PERMISSIONSDAO_H
|
||||
|
@ -24,8 +24,20 @@ PermissionsDaoSqlite::PermissionsDaoSqlite()
|
||||
{
|
||||
}
|
||||
|
||||
Permissions PermissionsDaoSqlite::find(std::string pagename, std::string username)
|
||||
std::optional<Permissions> PermissionsDaoSqlite::find(std::string pagename, std::string username)
|
||||
{
|
||||
/* auto query = *db << "SELECT COALESCE( (SELECT permissions FROM permissions WHERE page = ? AND userid = ?),
|
||||
(SELECT permissions FROM user WHERE ID = ?))"; exec*/
|
||||
auto query = *db << "SELECT permissions FROM permissions WHERE page = (SELECT id FROM page WHERE name = ?) AND "
|
||||
"userid = (SELECT id FROM user WHERE username = ?)";
|
||||
query << pagename << username;
|
||||
int permissions = 0;
|
||||
try
|
||||
{
|
||||
permissions = execInt(query);
|
||||
}
|
||||
catch(const sqlite::errors::no_rows &e)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
return Permissions{permissions};
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ class PermissionsDaoSqlite : public PermissionsDao, protected SqliteDao
|
||||
public:
|
||||
PermissionsDaoSqlite();
|
||||
|
||||
Permissions find(std::string pagename, std::string username) override;
|
||||
std::optional<Permissions> find(std::string pagename, std::string username) override;
|
||||
using SqliteDao::SqliteDao;
|
||||
};
|
||||
|
||||
|
@ -26,6 +26,7 @@ SOFTWARE.
|
||||
#include "userdaosqlite.h"
|
||||
#include "categorydaosqlite.h"
|
||||
#include "exceptions.h"
|
||||
#include "permissionsdaosqlite.h"
|
||||
|
||||
Sqlite::Sqlite(std::string path) : Database(path)
|
||||
{
|
||||
@ -58,6 +59,12 @@ std::unique_ptr<CategoryDao> Sqlite::createCategoryDao() const
|
||||
{
|
||||
return create<CategoryDaoSqlite>();
|
||||
}
|
||||
|
||||
std::unique_ptr<PermissionsDao> Sqlite::createPermissionsDao() const
|
||||
{
|
||||
return create<PermissionsDaoSqlite>();
|
||||
}
|
||||
|
||||
void Sqlite::beginTransaction()
|
||||
{
|
||||
if(!inTransaction)
|
||||
|
@ -23,6 +23,7 @@ class Sqlite : public Database
|
||||
std::unique_ptr<UserDao> createUserDao() const;
|
||||
std::unique_ptr<SessionDao> createSessionDao() const;
|
||||
std::unique_ptr<CategoryDao> createCategoryDao() const;
|
||||
std::unique_ptr<PermissionsDao> createPermissionsDao() const;
|
||||
void beginTransaction();
|
||||
void commitTransaction();
|
||||
void rollbackTransaction();
|
||||
|
Memuat…
Reference in New Issue
Block a user