aqhome-cgi: put role management for user into single dialog.

This commit is contained in:
Martin Preuss
2025-09-20 00:54:32 +02:00
parent 5c24750acc
commit c1afb05250

View File

@@ -48,13 +48,15 @@ static void _handleRqAddUserGet(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *s
static void _handleRqAddUserPost(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, GWEN_BUFFER *dbuf);
static int _getHighestUserId(const AQH_USER_LIST *userList);
static int _modulePermsHasRole(const AQH_MODULE_PERMS *modPerms, uint8_t rid);
static void _writeEditUserForm(AQH_MODULE *m,
const AQH_USER *u,
const char *sAlias,
const char *sUrl,
const char *sSubmitText,
GWEN_BUFFER *dbuf);
static void _writeModulePerms(const AQH_MODULE *destMod, const AQH_MODULE_PERMS *modPerms, GWEN_BUFFER *dbuf);
static void _writeUserModRolesToForm(const AQH_ROLE_LIST *roles, const AQH_MODULE_PERMS *perms, const char *sModName, GWEN_BUFFER *dbuf);
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);
@@ -389,6 +391,24 @@ int _getHighestUserId(const AQH_USER_LIST *userList)
int _modulePermsHasRole(const AQH_MODULE_PERMS *modPerms, uint8_t rid)
{
if (modPerms) {
int arraySize;
int i;
arraySize=AQH_ModulePerms_GetRoleArrayArraySize();
for(i=0; i<arraySize; i++) {
if (AQH_ModulePerms_GetRoleArrayAt(modPerms, i)==rid)
return 1;
}
}
return 0;
}
void _writeEditUserForm(AQH_MODULE *m,
@@ -399,9 +419,6 @@ void _writeEditUserForm(AQH_MODULE *m,
GWEN_BUFFER *dbuf)
{
AQH_MODULE_LIST *moduleList;
uint32_t perms;
perms=AQH_ModService_GetUserPerms(m);
/* write user info */
GBAS(dbuf, "<h2>User Info</h2>\n");
@@ -416,15 +433,13 @@ void _writeEditUserForm(AQH_MODULE *m,
_addUserStateLabelAndSelectionToFormTableH("Status", "status", u?AQH_User_GetState(u):AQH_UserState_Unknown, dbuf);
GBAS(dbuf, "</table>\n");
GBAA(dbuf, "<input type=\"hidden\" name=\"alias\" value=\"%s\">\n", sAlias?sAlias:"");
GBAA(dbuf, "<input type=\"submit\" value=\"%s\">\n</form>\n\n", sSubmitText?sSubmitText:"Save");
/* module permissions */
GBAS(dbuf, "<h2>Module Roles</h2>\n");
GBAS(dbuf,
"<table class=\"datatable\">\n"
"<thead>"
"<tr><th>Module</th><th>Enabled Roles</th><th>Actions</th></tr>\n"
"<tr><th>Module</th><th>Roles</th></tr>\n"
"</thead>\n"
"<tbody>\n");
moduleList=AQH_ModService_LoadRawModules(m);
@@ -436,22 +451,15 @@ void _writeEditUserForm(AQH_MODULE *m,
currentMod=AQH_Module_List_First(moduleList);
while(currentMod) {
const char *sModName;
const AQH_MODULE_PERMS *modPerms;
sModName=AQH_Module_GetName(currentMod);
GBAA(dbuf, "<tr><td>%s</td><td>", sModName);
if (modPermsList) {
const AQH_MODULE_PERMS *modPerms;
modPerms=AQH_ModulePerms_List_GetByModuleId(modPermsList, sModName);
if (modPerms)
_writeModulePerms(currentMod, modPerms, dbuf);
modPerms=modPermsList?AQH_ModulePerms_List_GetByModuleId(modPermsList, sModName):NULL;
_writeUserModRolesToForm(AQH_Module_GetRoleList(currentMod), modPerms, sModName, dbuf);
GBAS(dbuf, "</td></tr>\n");
}
GBAS(dbuf, "<td>");
if (perms & AQH_MODADMUSERS_PERMS_USERSWRITE)
GBAA(dbuf, "<a href=\"editmodperms.html?alias=%s&module=%s\"><img src=\"/pics/edit.png\"></a>",
sAlias?sAlias:"", sModName);
GBAS(dbuf, "</td>");
currentMod=AQH_Module_List_Next(currentMod);
} /* while */
@@ -460,36 +468,42 @@ void _writeEditUserForm(AQH_MODULE *m,
GBAS(dbuf,
"</tbody>\n"
"</table>\n");
GBAA(dbuf, "<input type=\"hidden\" name=\"alias\" value=\"%s\">\n", sAlias?sAlias:"");
GBAA(dbuf, "<input type=\"submit\" value=\"%s\">\n</form>\n\n", sSubmitText?sSubmitText:"Save");
}
void _writeModulePerms(const AQH_MODULE *destMod, const AQH_MODULE_PERMS *modPerms, GWEN_BUFFER *dbuf)
void _writeUserModRolesToForm(const AQH_ROLE_LIST *roleList, const AQH_MODULE_PERMS *modPerms, const char *sModName, GWEN_BUFFER *dbuf)
{
const AQH_ROLE_LIST *roleList;
roleList=destMod?AQH_Module_GetRoleList(destMod):NULL;
if (roleList) {
int roleArraySize;
int i;
roleArraySize=AQH_ModulePerms_GetRoleArrayArraySize();
for (i=0; i<roleArraySize; i++) {
int roleId;
roleId=AQH_ModulePerms_GetRoleArrayAt(modPerms, i);
if (roleId) {
const AQH_ROLE *role;
role=AQH_Role_List_GetById(roleList, roleId);
if (role) {
const char *s;
role=AQH_Role_List_First(roleList);
while(role) {
const char *sRoleName;
uint8_t roleId;
s=AQH_Role_GetName(role);
GBAA(dbuf, "%s%s", (i>0)?", ":"", s?s:"<unnamed>");
roleId=AQH_Role_GetId(role);
sRoleName=AQH_Role_GetName(role);
if (sRoleName && *sRoleName) {
int isChecked;
isChecked=(modPerms && _modulePermsHasRole(modPerms, roleId));
if (sModName && *sModName) {
GBAA(dbuf, "<input type=\"checkbox\" name=\"%s:%s\" %s>", sModName, sRoleName, isChecked?"checked":"");
GBAA(dbuf, "<label for=\"%s:%s\">%s</label>", sModName, sRoleName, sRoleName);
}
else {
GBAA(dbuf, "<input type=\"checkbox\" name=\"%s\" %s>", sRoleName, isChecked?"checked":"");
GBAA(dbuf, "<label for=\"%s\">%s</label>", sRoleName, sRoleName);
}
}
} /* for */
role=AQH_Role_List_Next(role);
}
}
}