forked from indymedia/epicyon
Show roles on profile screen
parent
e94d55a768
commit
88cbc74df2
79
daemon.py
79
daemon.py
|
@ -553,6 +553,37 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
self.server.GETbusy=False
|
self.server.GETbusy=False
|
||||||
return
|
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
|
# get an individual post from the path /users/nickname/statuses/number
|
||||||
if '/statuses/' in self.path and '/users/' in self.path:
|
if '/statuses/' in self.path and '/users/' in self.path:
|
||||||
namedStatus=self.path.split('/users/')[1]
|
namedStatus=self.path.split('/users/')[1]
|
||||||
|
@ -565,30 +596,30 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
domainFull=self.server.domain
|
domainFull=self.server.domain
|
||||||
if self.server.port!=80 and self.server.port!=443:
|
if self.server.port!=80 and self.server.port!=443:
|
||||||
domainFull=self.server.domain+':'+str(self.server.port)
|
domainFull=self.server.domain+':'+str(self.server.port)
|
||||||
postFilename= \
|
postFilename= \
|
||||||
self.server.baseDir+'/accounts/'+nickname+'@'+self.server.domain+'/outbox/'+ \
|
self.server.baseDir+'/accounts/'+nickname+'@'+self.server.domain+'/outbox/'+ \
|
||||||
self.server.httpPrefix+':##'+domainFull+'#users#'+nickname+'#statuses#'+statusNumber+'.json'
|
self.server.httpPrefix+':##'+domainFull+'#users#'+nickname+'#statuses#'+statusNumber+'.json'
|
||||||
if os.path.isfile(postFilename):
|
if os.path.isfile(postFilename):
|
||||||
postJsonObject={}
|
postJsonObject={}
|
||||||
with open(postFilename, 'r') as fp:
|
with open(postFilename, 'r') as fp:
|
||||||
postJsonObject=commentjson.load(fp)
|
postJsonObject=commentjson.load(fp)
|
||||||
# Only authorized viewers get to see likes on posts
|
# Only authorized viewers get to see likes on posts
|
||||||
# Otherwize marketers could gain more social graph info
|
# Otherwize marketers could gain more social graph info
|
||||||
if not self._isAuthorized():
|
if not self._isAuthorized():
|
||||||
if postJsonObject.get('likes'):
|
if postJsonObject.get('likes'):
|
||||||
postJsonObject['likes']={}
|
postJsonObject['likes']={}
|
||||||
if 'text/html' in self.headers['Accept']:
|
if 'text/html' in self.headers['Accept']:
|
||||||
self._set_headers('text/html')
|
self._set_headers('text/html')
|
||||||
self.wfile.write(htmlIndividualPost(postJsonObject).encode('utf-8'))
|
self.wfile.write(htmlIndividualPost(postJsonObject).encode('utf-8'))
|
||||||
else:
|
else:
|
||||||
self._set_headers('application/json')
|
self._set_headers('application/json')
|
||||||
self.wfile.write(json.dumps(postJsonObject).encode('utf-8'))
|
self.wfile.write(json.dumps(postJsonObject).encode('utf-8'))
|
||||||
self.server.GETbusy=False
|
self.server.GETbusy=False
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
self._404()
|
self._404()
|
||||||
self.server.GETbusy=False
|
self.server.GETbusy=False
|
||||||
return
|
return
|
||||||
# get the inbox for a given person
|
# get the inbox for a given person
|
||||||
if self.path.endswith('/inbox'):
|
if self.path.endswith('/inbox'):
|
||||||
if '/users/' in self.path:
|
if '/users/' in self.path:
|
||||||
|
|
|
@ -71,6 +71,21 @@ def htmlProfileFollowing(baseDir: str,httpPrefix: str, \
|
||||||
profileStr+=individualFollowAsHtml(session,wfRequest,personCache,domain,item)
|
profileStr+=individualFollowAsHtml(session,wfRequest,personCache,domain,item)
|
||||||
return profileStr
|
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, \
|
def htmlProfile(baseDir: str,httpPrefix: str,authorized: bool, \
|
||||||
ocapAlways: bool,profileJson: {},selected: str, \
|
ocapAlways: bool,profileJson: {},selected: str, \
|
||||||
session,wfRequest: {},personCache: {}, \
|
session,wfRequest: {},personCache: {}, \
|
||||||
|
@ -153,6 +168,16 @@ def htmlProfile(baseDir: str,httpPrefix: str,authorized: bool, \
|
||||||
' color: white;' \
|
' color: white;' \
|
||||||
'}' \
|
'}' \
|
||||||
'' \
|
'' \
|
||||||
|
'.roles {' \
|
||||||
|
' text-align: center;' \
|
||||||
|
' left: 35%;' \
|
||||||
|
' background-color: #f1f1f1;' \
|
||||||
|
'}' \
|
||||||
|
'.roles-inner {' \
|
||||||
|
' padding: 10px 25px;' \
|
||||||
|
' background-color: #ffffff;' \
|
||||||
|
'}' \
|
||||||
|
'' \
|
||||||
'.hero-text img {' \
|
'.hero-text img {' \
|
||||||
' border-radius: 10%;' \
|
' border-radius: 10%;' \
|
||||||
' width: 50%;' \
|
' width: 50%;' \
|
||||||
|
@ -327,6 +352,9 @@ def htmlProfile(baseDir: str,httpPrefix: str,authorized: bool, \
|
||||||
authorized,ocapAlways,nickname, \
|
authorized,ocapAlways,nickname, \
|
||||||
domain,port,session, \
|
domain,port,session, \
|
||||||
wfRequest,personCache,extraJson)
|
wfRequest,personCache,extraJson)
|
||||||
|
if selected=='roles':
|
||||||
|
profileStr+= \
|
||||||
|
htmlProfileRoles(nickname,domainFull,extraJson)
|
||||||
profileStr=htmlHeader(profileStyle)+profileStr+htmlFooter()
|
profileStr=htmlHeader(profileStyle)+profileStr+htmlFooter()
|
||||||
return profileStr
|
return profileStr
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue