From 88cbc74df20816b11b83f8eb7560507aafe54993 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 22 Jul 2019 18:21:45 +0100 Subject: [PATCH] Show roles on profile screen --- daemon.py | 79 ++++++++++++++++++++++++++++++++++--------------- webinterface.py | 28 ++++++++++++++++++ 2 files changed, 83 insertions(+), 24 deletions(-) diff --git a/daemon.py b/daemon.py index 747ffb09..1d672ac2 100644 --- a/daemon.py +++ b/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] @@ -565,30 +596,30 @@ class PubServer(BaseHTTPRequestHandler): domainFull=self.server.domain if self.server.port!=80 and self.server.port!=443: domainFull=self.server.domain+':'+str(self.server.port) - postFilename= \ - self.server.baseDir+'/accounts/'+nickname+'@'+self.server.domain+'/outbox/'+ \ - self.server.httpPrefix+':##'+domainFull+'#users#'+nickname+'#statuses#'+statusNumber+'.json' - if os.path.isfile(postFilename): - postJsonObject={} - with open(postFilename, 'r') as fp: - postJsonObject=commentjson.load(fp) - # Only authorized viewers get to see likes on posts - # Otherwize marketers could gain more social graph info - if not self._isAuthorized(): - if postJsonObject.get('likes'): - postJsonObject['likes']={} - if 'text/html' in self.headers['Accept']: - self._set_headers('text/html') - self.wfile.write(htmlIndividualPost(postJsonObject).encode('utf-8')) - else: - self._set_headers('application/json') - self.wfile.write(json.dumps(postJsonObject).encode('utf-8')) - self.server.GETbusy=False - return - else: - self._404() - self.server.GETbusy=False - return + postFilename= \ + self.server.baseDir+'/accounts/'+nickname+'@'+self.server.domain+'/outbox/'+ \ + self.server.httpPrefix+':##'+domainFull+'#users#'+nickname+'#statuses#'+statusNumber+'.json' + if os.path.isfile(postFilename): + postJsonObject={} + with open(postFilename, 'r') as fp: + postJsonObject=commentjson.load(fp) + # Only authorized viewers get to see likes on posts + # Otherwize marketers could gain more social graph info + if not self._isAuthorized(): + if postJsonObject.get('likes'): + postJsonObject['likes']={} + if 'text/html' in self.headers['Accept']: + self._set_headers('text/html') + self.wfile.write(htmlIndividualPost(postJsonObject).encode('utf-8')) + else: + self._set_headers('application/json') + self.wfile.write(json.dumps(postJsonObject).encode('utf-8')) + self.server.GETbusy=False + return + else: + self._404() + self.server.GETbusy=False + return # get the inbox for a given person if self.path.endswith('/inbox'): if '/users/' in self.path: diff --git a/webinterface.py b/webinterface.py index 1263cbf2..2a66bd41 100644 --- a/webinterface.py +++ b/webinterface.py @@ -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+='

'+project+'

' + for role in rolesList: + profileStr+='

'+role+'

' + profileStr+='
' + if len(profileStr)==0: + profileStr+='

@'+nickname+'@'+domain+' has no roles assigned

' + else: + profileStr='
'+profileStr+'
' + 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