forked from indymedia/epicyon
Show roles on profile screen
parent
e94d55a768
commit
88cbc74df2
31
daemon.py
31
daemon.py
|
@ -553,6 +553,37 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
self.server.GETbusy=False
|
||||
return
|
||||
|
||||
if self.path.endswith('/roles') and '/users/' in self.path:
|
||||
namedStatus=self.path.split('/users/')[1]
|
||||
if '/' in namedStatus:
|
||||
postSections=namedStatus.split('/')
|
||||
nickname=postSections[0]
|
||||
actorFilename=self.server.baseDir+'/accounts/'+nickname+'@'+self.server.domain+'.json'
|
||||
if os.path.isfile(actorFilename):
|
||||
with open(actorFilename, 'r') as fp:
|
||||
actorJson=commentjson.load(fp)
|
||||
if actorJson.get('roles'):
|
||||
if 'text/html' in self.headers['Accept']:
|
||||
getPerson = \
|
||||
personLookup(self.server.domain,self.path.replace('/roles',''), \
|
||||
self.server.baseDir)
|
||||
if getPerson:
|
||||
self._set_headers('text/html')
|
||||
self.wfile.write(htmlProfile(self.server.baseDir, \
|
||||
self.server.httpPrefix, \
|
||||
True, \
|
||||
self.server.ocapAlways, \
|
||||
getPerson,'roles', \
|
||||
self.server.session, \
|
||||
self.server.cachedWebfingers, \
|
||||
self.server.personCache, \
|
||||
actorJson['roles']).encode('utf-8'))
|
||||
else:
|
||||
self._set_headers('application/json')
|
||||
self.wfile.write(json.dumps(actorJson['roles']).encode('utf-8'))
|
||||
self.server.GETbusy=False
|
||||
return
|
||||
|
||||
# get an individual post from the path /users/nickname/statuses/number
|
||||
if '/statuses/' in self.path and '/users/' in self.path:
|
||||
namedStatus=self.path.split('/users/')[1]
|
||||
|
|
|
@ -71,6 +71,21 @@ def htmlProfileFollowing(baseDir: str,httpPrefix: str, \
|
|||
profileStr+=individualFollowAsHtml(session,wfRequest,personCache,domain,item)
|
||||
return profileStr
|
||||
|
||||
def htmlProfileRoles(nickname: str,domain: str,rolesJson: {}) -> str:
|
||||
"""Shows roles on the profile screen
|
||||
"""
|
||||
profileStr=''
|
||||
for project,rolesList in rolesJson.items():
|
||||
profileStr+='<div class="roles"><h2>'+project+'</h2><div class="roles-inner">'
|
||||
for role in rolesList:
|
||||
profileStr+='<h3>'+role+'</h3>'
|
||||
profileStr+='</div></div>'
|
||||
if len(profileStr)==0:
|
||||
profileStr+='<p>@'+nickname+'@'+domain+' has no roles assigned</p>'
|
||||
else:
|
||||
profileStr='<div>'+profileStr+'</div>'
|
||||
return profileStr
|
||||
|
||||
def htmlProfile(baseDir: str,httpPrefix: str,authorized: bool, \
|
||||
ocapAlways: bool,profileJson: {},selected: str, \
|
||||
session,wfRequest: {},personCache: {}, \
|
||||
|
@ -153,6 +168,16 @@ def htmlProfile(baseDir: str,httpPrefix: str,authorized: bool, \
|
|||
' color: white;' \
|
||||
'}' \
|
||||
'' \
|
||||
'.roles {' \
|
||||
' text-align: center;' \
|
||||
' left: 35%;' \
|
||||
' background-color: #f1f1f1;' \
|
||||
'}' \
|
||||
'.roles-inner {' \
|
||||
' padding: 10px 25px;' \
|
||||
' background-color: #ffffff;' \
|
||||
'}' \
|
||||
'' \
|
||||
'.hero-text img {' \
|
||||
' border-radius: 10%;' \
|
||||
' width: 50%;' \
|
||||
|
@ -327,6 +352,9 @@ def htmlProfile(baseDir: str,httpPrefix: str,authorized: bool, \
|
|||
authorized,ocapAlways,nickname, \
|
||||
domain,port,session, \
|
||||
wfRequest,personCache,extraJson)
|
||||
if selected=='roles':
|
||||
profileStr+= \
|
||||
htmlProfileRoles(nickname,domainFull,extraJson)
|
||||
profileStr=htmlHeader(profileStyle)+profileStr+htmlFooter()
|
||||
return profileStr
|
||||
|
||||
|
|
Loading…
Reference in New Issue