Add Super Admin login flag and expose web tenant onboarding

issuperadmin on app_users (schema change already applied to the DB)
is now returned by AppLogin/TenantWebLogin's login response, gated
server-side rather than via a client-supplied roleid. Fixes the login
enrichment query (GetTenantUserById) to LEFT JOIN app_location instead
of INNER JOIN — a tenantless super-admin row was previously silently
dropped, so the login "succeeded" but returned an empty struct.

Also exposes createtenantuser on the web route group (was mob-only).
No repository changes were needed for location auto-provisioning:
GORM was already inserting the nested tenantlocations association on
tenant creation, it just wasn't reachable from the web.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Suriya
2026-07-16 20:45:27 +05:30
parent a9c13292f0
commit 36f9cf86e7
3 changed files with 10 additions and 2 deletions

View File

@@ -59,6 +59,7 @@ type User struct {
Applocationid int `json:"applocationid"`
Status string `json:"status"`
Shiftid int `json:"shiftid"`
Issuperadmin bool `json:"issuperadmin"`
}
type TenantUserInfo struct {
@@ -99,4 +100,5 @@ type TenantUserInfo struct {
Categoryid int `json:"categoryid"`
Categoryname string `json:"categoryname"`
Subcategoryid int `json:"subcategoryid"`
Issuperadmin bool `json:"issuperadmin"`
}

View File

@@ -213,17 +213,22 @@ func (r *userRepository) UpdateFCMToken(userid int, token string) error {
func (r *userRepository) GetTenantUserById(userid int) models.TenantUserInfo {
var info models.TenantUserInfo
// app_location is LEFT JOINed (not INNER) so a user with no matching
// tenant/applocation row — e.g. a super admin, tenantid=0 — still comes
// back with their own fields (issuperadmin included) instead of the
// whole query silently returning zero rows.
query := `
SELECT a.userid,a.authname,a.email,a.configid,a.roleid,a.authmode,a.contactno,
a.firstname,a.lastname,concat(a.firstname,' ',a.lastname) as fullname,
a.userfcmtoken,a.pin,a.deviceid,a.devicetype,a.tenantid,a.locationid,a.applocationid,
a.issuperadmin,
b.partnerid,b.moduleid,b.categoryid as categoryid,b.subcategoryid as subcategoryid,
b.applocationid,b.tenantname,b.address as tenantaddress,b.state as tenantstate,b.city as tenantcity,
b.postcode as tenantpostcode,b.latitude as tenantlat,b.longitude as tenantlong,c.locationname AS applocation,
c.latitude as applatitude,c.longitude as applongitude,c.radius as appradius, d.categoryname, e.locationname
from app_users a
LEFT JOIN tenants b ON a.tenantid=b.tenantid
INNER JOIN app_location c on c.applocationid=b.applocationid
LEFT JOIN app_location c on c.applocationid=b.applocationid
LEFT JOIN app_category d ON b.categoryid=d.categoryid
LEFT JOIN tenantlocations e ON a.locationid=e.locationid
WHERE a.userid = ?

View File

@@ -20,6 +20,7 @@ func RegisterTenantRoutes(api fiber.Router, f *facade.Facade) {
tenant.Delete("/deletelocation", f.TenantController.DeleteLocation)
tenant.Post("/createtenantlocation", f.TenantController.CreateTenantLocation)
tenant.Put("/updatetenantlocation", f.TenantController.UpdateTenantLocation)
tenant.Post("/createtenantuser", f.TenantController.CreateTenantUser)
tenant = api.Group("/v1/mob/tenants")