PermissionsDao: Add save()
This commit is contained in:
parent
c4072a7e95
commit
f002969cc1
@ -7,6 +7,7 @@ class PermissionsDao
|
|||||||
public:
|
public:
|
||||||
PermissionsDao();
|
PermissionsDao();
|
||||||
virtual std::optional<Permissions> find(std::string pagename, std::string username) = 0;
|
virtual std::optional<Permissions> find(std::string pagename, std::string username) = 0;
|
||||||
|
virtual void save(std::string pagename, std::string username, Permissions perms) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PERMISSIONSDAO_H
|
#endif // PERMISSIONSDAO_H
|
||||||
|
@ -41,3 +41,21 @@ std::optional<Permissions> PermissionsDaoSqlite::find(std::string pagename, std:
|
|||||||
|
|
||||||
return Permissions{permissions};
|
return Permissions{permissions};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PermissionsDaoSqlite::save(std::string pagename, std::string username, Permissions perms)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
auto query =
|
||||||
|
*db
|
||||||
|
<< "INSERT OR REPLACE INTO permissions (id, permissions, userid, page) VALUES((SELECT id FROM permissions "
|
||||||
|
"WHERE page = (SELECT id FROM page WHERE name = ?) AND userid = (SELECT id FROM user WHERE username = "
|
||||||
|
"?)), ?, (SELECT id FROM user WHERE username = ?), (SELECT id FROM page WHERE name = ?))";
|
||||||
|
query << pagename << username << perms.getPermissions() << username << pagename;
|
||||||
|
query.execute();
|
||||||
|
}
|
||||||
|
catch(const sqlite::errors::no_rows &e)
|
||||||
|
{
|
||||||
|
throwFrom(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -9,6 +9,7 @@ class PermissionsDaoSqlite : public PermissionsDao, protected SqliteDao
|
|||||||
PermissionsDaoSqlite();
|
PermissionsDaoSqlite();
|
||||||
|
|
||||||
std::optional<Permissions> find(std::string pagename, std::string username) override;
|
std::optional<Permissions> find(std::string pagename, std::string username) override;
|
||||||
|
virtual void save(std::string pagename, std::string username, Permissions perms) override;
|
||||||
using SqliteDao::SqliteDao;
|
using SqliteDao::SqliteDao;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user