aqhome-cgi: put role management for user into single dialog.
This commit is contained in:
@@ -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 void _handleRqAddUserPost(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, GWEN_BUFFER *dbuf);
|
||||||
|
|
||||||
static int _getHighestUserId(const AQH_USER_LIST *userList);
|
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,
|
static void _writeEditUserForm(AQH_MODULE *m,
|
||||||
const AQH_USER *u,
|
const AQH_USER *u,
|
||||||
const char *sAlias,
|
const char *sAlias,
|
||||||
const char *sUrl,
|
const char *sUrl,
|
||||||
const char *sSubmitText,
|
const char *sSubmitText,
|
||||||
GWEN_BUFFER *dbuf);
|
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 _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);
|
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,
|
void _writeEditUserForm(AQH_MODULE *m,
|
||||||
@@ -399,9 +419,6 @@ void _writeEditUserForm(AQH_MODULE *m,
|
|||||||
GWEN_BUFFER *dbuf)
|
GWEN_BUFFER *dbuf)
|
||||||
{
|
{
|
||||||
AQH_MODULE_LIST *moduleList;
|
AQH_MODULE_LIST *moduleList;
|
||||||
uint32_t perms;
|
|
||||||
|
|
||||||
perms=AQH_ModService_GetUserPerms(m);
|
|
||||||
|
|
||||||
/* write user info */
|
/* write user info */
|
||||||
GBAS(dbuf, "<h2>User Info</h2>\n");
|
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);
|
_addUserStateLabelAndSelectionToFormTableH("Status", "status", u?AQH_User_GetState(u):AQH_UserState_Unknown, dbuf);
|
||||||
|
|
||||||
GBAS(dbuf, "</table>\n");
|
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 */
|
/* module permissions */
|
||||||
GBAS(dbuf, "<h2>Module Roles</h2>\n");
|
GBAS(dbuf, "<h2>Module Roles</h2>\n");
|
||||||
GBAS(dbuf,
|
GBAS(dbuf,
|
||||||
"<table class=\"datatable\">\n"
|
"<table class=\"datatable\">\n"
|
||||||
"<thead>"
|
"<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"
|
"</thead>\n"
|
||||||
"<tbody>\n");
|
"<tbody>\n");
|
||||||
moduleList=AQH_ModService_LoadRawModules(m);
|
moduleList=AQH_ModService_LoadRawModules(m);
|
||||||
@@ -436,22 +451,15 @@ void _writeEditUserForm(AQH_MODULE *m,
|
|||||||
currentMod=AQH_Module_List_First(moduleList);
|
currentMod=AQH_Module_List_First(moduleList);
|
||||||
while(currentMod) {
|
while(currentMod) {
|
||||||
const char *sModName;
|
const char *sModName;
|
||||||
|
const AQH_MODULE_PERMS *modPerms;
|
||||||
|
|
||||||
sModName=AQH_Module_GetName(currentMod);
|
sModName=AQH_Module_GetName(currentMod);
|
||||||
GBAA(dbuf, "<tr><td>%s</td><td>", sModName);
|
GBAA(dbuf, "<tr><td>%s</td><td>", sModName);
|
||||||
if (modPermsList) {
|
|
||||||
const AQH_MODULE_PERMS *modPerms;
|
|
||||||
|
|
||||||
modPerms=AQH_ModulePerms_List_GetByModuleId(modPermsList, sModName);
|
modPerms=modPermsList?AQH_ModulePerms_List_GetByModuleId(modPermsList, sModName):NULL;
|
||||||
if (modPerms)
|
_writeUserModRolesToForm(AQH_Module_GetRoleList(currentMod), modPerms, sModName, dbuf);
|
||||||
_writeModulePerms(currentMod, modPerms, dbuf);
|
GBAS(dbuf, "</td></tr>\n");
|
||||||
GBAS(dbuf, "</td></tr>\n");
|
|
||||||
}
|
|
||||||
GBAS(dbuf, "<td>");
|
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);
|
currentMod=AQH_Module_List_Next(currentMod);
|
||||||
} /* while */
|
} /* while */
|
||||||
@@ -460,36 +468,42 @@ void _writeEditUserForm(AQH_MODULE *m,
|
|||||||
GBAS(dbuf,
|
GBAS(dbuf,
|
||||||
"</tbody>\n"
|
"</tbody>\n"
|
||||||
"</table>\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) {
|
if (roleList) {
|
||||||
int roleArraySize;
|
const AQH_ROLE *role;
|
||||||
int i;
|
|
||||||
|
|
||||||
roleArraySize=AQH_ModulePerms_GetRoleArrayArraySize();
|
role=AQH_Role_List_First(roleList);
|
||||||
for (i=0; i<roleArraySize; i++) {
|
while(role) {
|
||||||
int roleId;
|
const char *sRoleName;
|
||||||
|
uint8_t roleId;
|
||||||
|
|
||||||
roleId=AQH_ModulePerms_GetRoleArrayAt(modPerms, i);
|
roleId=AQH_Role_GetId(role);
|
||||||
if (roleId) {
|
sRoleName=AQH_Role_GetName(role);
|
||||||
const AQH_ROLE *role;
|
if (sRoleName && *sRoleName) {
|
||||||
|
int isChecked;
|
||||||
|
|
||||||
role=AQH_Role_List_GetById(roleList, roleId);
|
isChecked=(modPerms && _modulePermsHasRole(modPerms, roleId));
|
||||||
if (role) {
|
if (sModName && *sModName) {
|
||||||
const char *s;
|
GBAA(dbuf, "<input type=\"checkbox\" name=\"%s:%s\" %s>", sModName, sRoleName, isChecked?"checked":"");
|
||||||
|
GBAA(dbuf, "<label for=\"%s:%s\">%s</label>", sModName, sRoleName, sRoleName);
|
||||||
s=AQH_Role_GetName(role);
|
}
|
||||||
GBAA(dbuf, "%s%s", (i>0)?", ":"", s?s:"<unnamed>");
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user