aqhome-cgi: implemented adding roles for users.
This commit is contained in:
@@ -58,6 +58,12 @@ static void _writeEditUserForm(AQH_MODULE *m,
|
||||
GWEN_BUFFER *dbuf);
|
||||
static void _writeUserModRolesToForm(const AQH_ROLE_LIST *roles, const AQH_MODULE_PERMS *perms, const char *sModName, GWEN_BUFFER *dbuf);
|
||||
|
||||
static void _readAllModRolesForUserFromForm(AQH_MODULE *m, GWEN_DB_NODE *dbPost, AQH_USER *u);
|
||||
static void _readModRolesFromForm(GWEN_DB_NODE *dbPost,
|
||||
const AQH_ROLE_LIST *roleList,
|
||||
const char *sPrefix,
|
||||
AQH_MODULE_PERMS *modPerms);
|
||||
|
||||
static void _addLabelAndInputToFormTableH(const char *title, const char *name, const char *value, const char *xxtra, GWEN_BUFFER *dbuf);
|
||||
static void _addUserStateLabelAndSelectionToFormTableH(const char *sTitle, const char *sName, int st, GWEN_BUFFER *dbuf);
|
||||
|
||||
@@ -284,6 +290,8 @@ void _handleRqEditUserPost(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *sessio
|
||||
if (state!=AQH_UserState_Unknown)
|
||||
AQH_User_SetState(u, state);
|
||||
|
||||
_readAllModRolesForUserFromForm(m, dbPost, u);
|
||||
|
||||
rv=AQH_Service_SaveUser(sv, u);
|
||||
if (rv<0) {
|
||||
GBAS(dbuf, "<h2>Error</h2><p>Error saving user</p>");
|
||||
@@ -477,6 +485,49 @@ void _writeEditUserForm(AQH_MODULE *m,
|
||||
|
||||
|
||||
|
||||
void _readAllModRolesForUserFromForm(AQH_MODULE *m, GWEN_DB_NODE *dbPost, AQH_USER *u)
|
||||
{
|
||||
AQH_MODULE_LIST *moduleList;
|
||||
|
||||
moduleList=AQH_ModService_LoadRawModules(m);
|
||||
if (moduleList) {
|
||||
AQH_MODULE_PERMS_LIST *permsList;
|
||||
const AQH_MODULE *module;
|
||||
|
||||
permsList=AQH_User_GetModulePermList(u);
|
||||
if (permsList==NULL) {
|
||||
DBG_ERROR(NULL, "Creating module perms list for user");
|
||||
permsList=AQH_ModulePerms_List_new();
|
||||
AQH_User_SetModulePermList(u, permsList);
|
||||
}
|
||||
|
||||
module=AQH_Module_List_First(moduleList);
|
||||
while(module) {
|
||||
const char *sModName;
|
||||
const AQH_ROLE_LIST *roleList;
|
||||
|
||||
sModName=AQH_Module_GetName(module);
|
||||
roleList=AQH_Module_GetRoleList(module);
|
||||
if (sModName && *sModName && roleList) {
|
||||
AQH_MODULE_PERMS *modPerms;
|
||||
|
||||
modPerms=AQH_ModulePerms_List_GetByModuleId(permsList, sModName);
|
||||
if (modPerms==NULL) {
|
||||
modPerms=AQH_ModulePerms_new();
|
||||
AQH_ModulePerms_SetModuleId(modPerms, sModName);
|
||||
AQH_ModulePerms_List_Add(modPerms, permsList);
|
||||
}
|
||||
_readModRolesFromForm(dbPost, roleList, sModName, modPerms);
|
||||
}
|
||||
module=AQH_Module_List_Next(module);
|
||||
}
|
||||
|
||||
AQH_Module_List_free(moduleList);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _writeUserModRolesToForm(const AQH_ROLE_LIST *roleList, const AQH_MODULE_PERMS *modPerms, const char *sModName, GWEN_BUFFER *dbuf)
|
||||
{
|
||||
if (roleList) {
|
||||
@@ -509,6 +560,55 @@ void _writeUserModRolesToForm(const AQH_ROLE_LIST *roleList, const AQH_MODULE_PE
|
||||
|
||||
|
||||
|
||||
void _readModRolesFromForm(GWEN_DB_NODE *dbPost,
|
||||
const AQH_ROLE_LIST *roleList,
|
||||
const char *sPrefix,
|
||||
AQH_MODULE_PERMS *modPerms)
|
||||
{
|
||||
GWEN_DB_WriteFile(dbPost, "/var/www/aqhome-cgi/log/test.log", GWEN_DB_FLAGS_DEFAULT);
|
||||
AQH_ModulePerms_PresetRoleArray(modPerms, 0);
|
||||
if (roleList) {
|
||||
GWEN_BUFFER *tbuf;
|
||||
uint32_t pos;
|
||||
const AQH_ROLE *role;
|
||||
int nextRolePos=0;
|
||||
|
||||
tbuf=GWEN_Buffer_new(0, 256, 0, 1);
|
||||
if (sPrefix && *sPrefix)
|
||||
GBAA(tbuf, "%s:", sPrefix);
|
||||
pos=GWEN_Buffer_GetPos(tbuf);
|
||||
|
||||
role=AQH_Role_List_First(roleList);
|
||||
while(role) {
|
||||
const char *roleName;
|
||||
|
||||
roleName=AQH_Role_GetName(role);
|
||||
if (roleName && *roleName) {
|
||||
const char *s;
|
||||
|
||||
GBAS(tbuf, roleName);
|
||||
DBG_ERROR(NULL, "Looking for %s", GWEN_Buffer_GetStart(tbuf));
|
||||
s=GWEN_DB_GetCharValue(dbPost, GWEN_Buffer_GetStart(tbuf), 0, NULL);
|
||||
if (s && *s) {
|
||||
DBG_ERROR(NULL, "Got %s (%d)[%d]", GWEN_Buffer_GetStart(tbuf), AQH_Role_GetId(role), nextRolePos);
|
||||
if (nextRolePos<AQH_ModulePerms_GetRoleArrayArraySize())
|
||||
AQH_ModulePerms_SetRoleArrayAt(modPerms, nextRolePos++, AQH_Role_GetId(role));
|
||||
}
|
||||
GWEN_Buffer_Crop(tbuf, 0, pos);
|
||||
}
|
||||
|
||||
role=AQH_Role_List_Next(role);
|
||||
} /* while */
|
||||
GWEN_Buffer_free(tbuf);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void _addUserStateLabelAndSelectionToFormTableH(const char *sTitle, const char *sName, int st, GWEN_BUFFER *dbuf)
|
||||
{
|
||||
int i;
|
||||
|
||||
Reference in New Issue
Block a user