Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

Task 2 A: The customer view: track and reply

The whole lesson, free. Read it and have a go at the activities. To work the tasks and labs in the real lesson, press Start lab, with no account needed.

60 minutes

A quick check that you are not a bot, then your own lab opens on the interactive lesson.

Already have an account? Sign in

Your bank shows only your account

When you open a banking app, you see your own money. Never your neighbour's, even if you guess their account number.

Netheret's customers are rival small businesses. A bakery must never read a garage's requests.

Each customer also needs to follow their own requests and reply, without seeing the staff's private notes.

Key words

WordWhat it means
ConfidentialityKeeping data away from people who should not see it.
Error 404The page or record was not found.
Internal noteAn update only staff can read.
ReopenMove a finished request back to open.
QueryA question you ask the stored data.

The cells students fill in are left blank in this preview.

By the end of this lesson

Note

I can limit every customer page to that customer's own company.

Starter: what you already know

Have a go

Starter: what you already know

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Sprint 3, step 11: the goal and stories

PartFor this step
Sprint (a short block of work)Sprint 3: the knowledge base and the customer's view.
E1.4As a customer, I want to see only my company's requests, so that our data stays private.
E2.7As a customer, I want to see updates meant for me, so that I know what is happening.
E2.8As a customer, I want to add a comment, so that I can answer the help desk.

The cells students fill in are left blank in this preview.

Every query starts with the company

Every customer query in customer.py begins the same way: only tickets where the company is the customer's own company.

For one request, company_ticket_or_404 loads it and checks the company. Every customer page calls it.

Another company's request gets error 404, not 403. A 403 would say "this exists, but not for you". A 404 gives nothing away, so references cannot be guessed.

Step 11: the company check

Code: python
# helpdesk/customer.py (part)
def company_ticket_or_404(ticket_id):
    """Load a request, but only if it belongs to the customer's company.

    Another company's request gets 404, the same as one that does not exist,
    so a customer cannot find out which references are in use.
    """
    ticket = db.get_or_404(Ticket, ticket_id)
    if ticket.company_id != g.user.company_id:
        abort(404)
    return ticket


@bp.route("/my/requests")
@role_required("customer")
def my_requests():
    query = db.select(Ticket).where(Ticket.company_id == g.user.company_id)
    # ... "open" or "finished" filter ...

Make a free account to save your work and track your progress.

Check: the company rule

Have a go

Check: the company rule

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

The customer's timeline hides internal notes

Staff mark each update as customer-visible or internal. The customer's page asks only for the visible ones.

This filter is in the query, on the server. The internal notes never reach the customer's browser at all, so they cannot be found by viewing the page source.

Step 11: only visible updates

Code: python
# helpdesk/customer.py, inside my_request(ticket_id)
    ticket = company_ticket_or_404(ticket_id)
    # Only the updates meant for the customer. Internal notes stay hidden.
    updates = db.session.scalars(
        db.select(TicketUpdate)
        .where(TicketUpdate.ticket_id == ticket.id,
               TicketUpdate.visible_to_customer.is_(True))
        .order_by(TicketUpdate.created_at)
    ).all()

Make a free account to save your work and track your progress.

Try it: filter the timeline

Code: python
# Each update: the words, and whether the customer may see it.
updates = [
    ["Assigned to Tom Reid.", False],
    ["We are looking at your router now.", True],
    ["Escalated from Tier 1 to Tier 2: restart did not help", False],
    ["An engineer will visit on Tuesday at 09:00.", True],
]

print("What the customer sees:")
for update in updates:
    if update[1] == True:
        print(" -", update[0])

# Change the first update to True, then press Run. Should a customer see it?

Make a free account to save your work and track your progress.

A common mistake

Warning

Many students hide private data with CSS or leave it out of the page with an if in the template, after loading everything. Leave it out of the query instead. Data the server never sends cannot leak, even if someone reads the page source or a template has a bug.

Check: hiding internal notes

Have a go

Check: hiding internal notes

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

A reply can reopen a request

A customer can add a comment to their request. It goes on the timeline as a customer-visible update.

If the request was waiting for them, or marked resolved, the reply sets it back to open. The help desk has something to act on again.

A closed request takes no more comments. The message says what to do instead: raise a new one.

Step 11: adding a comment

Code: python
# helpdesk/customer.py, inside add_comment(ticket_id)
    ticket = company_ticket_or_404(ticket_id)
    body = request.form.get("body", "").strip()
    if ticket.status == "closed":
        flash("This request is closed. Please raise a new request.")
    elif not body:
        flash("Write your comment before sending it.")
    else:
        status_change = None
        # A reply means the help desk has something to act on again.
        if ticket.status in ["waiting", "resolved"]:
            change_status(ticket, "open")
            status_change = "open"
        add_update(ticket, body, True, status_change)
        db.session.commit()
        flash("Comment sent. The help desk will see it on your request.")

Make a free account to save your work and track your progress.

Worked example: what a comment does

Status beforeCommentStatus afterMessage
Waiting"Here is the error code."OpenComment sent
Resolved"It broke again."OpenComment sent
Open"Any news?"OpenComment sent
Closed"Still broken."ClosedPlease raise a new request
Open(empty)OpenWrite your comment before sending it

The cells students fill in are left blank in this preview.

Build it yourself: step 11

Build step 11. 1. Write customer.py with company_ticket_or_404, a list of the company's requests, a detail page and a comment route. 2. Ask only for customer-visible updates in the query. 3. A comment reopens a waiting or resolved request; a closed one is refused. 4. Show the customer's open requests on their dashboard. 5. Test by hand as two customers: open each other's requests, comment on a closed one, and check no internal note shows in the page source. 6. Commit and write the change log row, and a short Sprint 3 review.

A teacher marks this in a college. Nothing you write here is kept: it goes when you leave the page.

Make a free account to save your work, or press Start lab to work through the whole lesson.

Compare with the step 11 code

Tip

Compare yours with the step 11 code on GitHub. Sign in as two different customers and try to open each other's requests.

Change log entry for step 11

DateVersion and filesWhat changedWhy
17 Marchstep-11: customer.py, main.py, customer/list.html, customer/detail.html, dashboard.htmlCustomers see their company's requests, a timeline without internal notes, and add comments that reopen a requestCustomers must be kept informed and must only see their own company's data

The cells students fill in are left blank in this preview.

Sprint 3 done. Next: reports

Sprint 3 is finished: Tier 1 has a knowledge base and customers have their own view. Sprint 4 starts in step 12 with reports for managers. The numbers come from the data, and JavaScript draws the charts.

Exit quiz

Have a go

Exit quiz

5 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Teach this lesson with your class

On a college account your students work the tasks and the labs as well, and every mark is kept for you.