Skip to content

Commit

Permalink
Enhanced API links on top of the admin Member page.
Browse files Browse the repository at this point in the history
  • Loading branch information
filiptypjeu committed Aug 30, 2023
1 parent 9a20ad8 commit 3fa7670
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
10 changes: 6 additions & 4 deletions teknologr/api/bill.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ def __init__(self):
self.user = env("BILL_API_USER")
self.password = env("BILL_API_PW")

def admin_url(self, bill_code):
if not self.api_url:
return ''
return f'{"/".join(self.api_url.split("/")[:-2])}/admin/userdata?id={bill_code}'

def create_bill_account(self, username):
if not re.search(r'^[A-Za-z0-9]+$', username):
raise BILLException("Can not create a BILL account using an LDAP username containing anything other than letters and numbers")
Expand Down Expand Up @@ -63,10 +68,7 @@ def get_bill_info(self, bill_code):
error = int(r.text)
except ValueError:
# The returned string is not an integer, so presumably we have the json we want
return {
**json.loads(r.text),
"url": f'{"/".join(self.api_url.split("/")[:-2])}/admin/userdata?id={bill_code}',
}
return json.loads(r.text)
raise BILLException("BILL returned error code: " + r.text)

def find_bill_code(self, username):
Expand Down
4 changes: 2 additions & 2 deletions teknologr/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ def get_api_root_view(self, api_urls=None):
url(r'^multi-functionaries/$', multi_functionaries_save),
url(r'^multi-decorationownerships/$', multi_decoration_ownerships_save),
url(r'^multi-applicantsubmissions/$', multi_applicant_submissions),
url(r'^accounts/ldap/(\d+)/$', LDAPAccountView.as_view()),
url(r'^accounts/ldap/(\d+)/$', LDAPAccountView.as_view(), name='ldap'),
url(r'^accounts/ldap/change_pw/(\d+)/$', change_ldap_password),
url(r'^accounts/bill/(\d+)/$', BILLAccountView.as_view()),
url(r'^accounts/bill/(\d+)/$', BILLAccountView.as_view(), name='bill'),
url(r'^applicants/make-member/(\d+)/$', ApplicantMembershipView.as_view()),
url(r'^dump-htk/(?:(\d+)/)?$', dump_htk, name='dump_htk'),
url(r'^dump-modulen/$', dump_modulen, name='dump_modulen'),
Expand Down
23 changes: 16 additions & 7 deletions teknologr/members/templates/member.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,22 @@
<div class="row mb-2">
<div class="col-12">
<a class="btn btn-secondary" href="{% url 'katalogen:profile' member.id %}">Katalogen</a>
<a class="btn btn-secondary" href="{% url 'api:member-detail' member.id %}">API</a>
<a class="btn btn-secondary" href="{% url 'api:dump_htk' member.id %}">HTK dump</a>
<div class="btn btn-secondary dropdown">
API <i class="fa fa-caret-down"></i>
<div class="dropdown-content">
<a href="{% url 'api:member-detail' member.id %}">Member</a>
<a href="{% url 'api:dump_htk' member.id %}">HTK dump</a>
{% if member.username %}
<a href="{% url 'api:ldap' member.id %}">LDAP</a>
{% endif %}
{% if member.bill_code %}
<a href="{% url 'api:bill' member.id %}">BILL</a>
{% endif %}
{% if bill_admin_url %}
<a href="{{ bill_admin_url }}">BILL admin</a>
{% endif %}
</div>
</div>
</div>
</div>
<h2 class="page-header">
Expand Down Expand Up @@ -196,13 +210,8 @@ <h5>LDAP</h5>
<div class="col-sm-6">
<h5>BILL</h5>
{% if member.bill_code %}

<b>Konto:</b>
{% if BILL.url %}
<a class="monospace" href="{{ BILL.url }}" style="color: black;">{{ member.bill_code }}</a>
{% else %}
<span class="monospace">{{ member.bill_code }}</span>
{% endif %}
<br/>

{% if BILL.error %}
Expand Down
1 change: 1 addition & 0 deletions teknologr/members/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def member(request, member_id):
from api.bill import BILLAccountManager, BILLException
bm = BILLAccountManager()
try:
context['bill_admin_url'] = bm.admin_url(member.bill_code)
context['BILL'] = bm.get_bill_info(member.bill_code)

# Check that the username stored by BILL is the same as our
Expand Down

0 comments on commit 3fa7670

Please sign in to comment.