Allow for not displaying shared links on specific hosts
This commit is contained in:
parent
c4e2729144
commit
e31139add1
4
Makefile
4
Makefile
@ -13,5 +13,5 @@ sqlc: queries.sql schema.sql
|
||||
build:
|
||||
go build
|
||||
|
||||
run: build
|
||||
./gostart -name startdev
|
||||
run: sqlc build
|
||||
./gostart -name startdev -db ./test.db
|
||||
|
1
app.go
1
app.go
@ -32,6 +32,7 @@ func (a *App) getOwner(r *http.Request) (*tailcfg.Node, error) {
|
||||
_, err = a.queries.AddOwner(a.ctx, data.AddOwnerParams{
|
||||
ID: int64(who.Node.ID),
|
||||
Name: who.Node.ComputedName,
|
||||
ShowShared: false,
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal("adding owner failed: ", err)
|
||||
|
@ -33,6 +33,7 @@ type Owner struct {
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
LastUsed time.Time `json:"last_used"`
|
||||
Name string `json:"name"`
|
||||
ShowShared bool `json:"show_shared"`
|
||||
}
|
||||
|
||||
type PullRequest struct {
|
||||
|
@ -69,23 +69,25 @@ func (q *Queries) AddLink(ctx context.Context, arg AddLinkParams) (Link, error)
|
||||
}
|
||||
|
||||
const addOwner = `-- name: AddOwner :one
|
||||
insert into owners (id, name)
|
||||
values (?, ?) returning id, created_at, last_used, name
|
||||
insert into owners (id, name, show_shared)
|
||||
values (?, ?, ?) returning id, created_at, last_used, name, show_shared
|
||||
`
|
||||
|
||||
type AddOwnerParams struct {
|
||||
ID int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
ShowShared bool `json:"show_shared"`
|
||||
}
|
||||
|
||||
func (q *Queries) AddOwner(ctx context.Context, arg AddOwnerParams) (Owner, error) {
|
||||
row := q.db.QueryRowContext(ctx, addOwner, arg.ID, arg.Name)
|
||||
row := q.db.QueryRowContext(ctx, addOwner, arg.ID, arg.Name, arg.ShowShared)
|
||||
var i Owner
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.CreatedAt,
|
||||
&i.LastUsed,
|
||||
&i.Name,
|
||||
&i.ShowShared,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@ -299,7 +301,8 @@ func (q *Queries) GetAllLinks(ctx context.Context) ([]Link, error) {
|
||||
const getAllLinksForOwner = `-- name: GetAllLinksForOwner :many
|
||||
select id, owner_id, created_at, url, name, clicked, logo_url, shared
|
||||
from links
|
||||
where owner_id = ? or shared = true
|
||||
where owner_id = ?
|
||||
or shared = true
|
||||
`
|
||||
|
||||
func (q *Queries) GetAllLinksForOwner(ctx context.Context, ownerID int64) ([]Link, error) {
|
||||
@ -502,7 +505,9 @@ func (q *Queries) GetIconByLinkID(ctx context.Context, arg GetIconByLinkIDParams
|
||||
}
|
||||
|
||||
const getLinkByID = `-- name: GetLinkByID :one
|
||||
select id, owner_id, created_at, url, name, clicked, logo_url, shared from links where id = ?
|
||||
select id, owner_id, created_at, url, name, clicked, logo_url, shared
|
||||
from links
|
||||
where id = ?
|
||||
`
|
||||
|
||||
func (q *Queries) GetLinkByID(ctx context.Context, id int64) (Link, error) {
|
||||
@ -522,7 +527,7 @@ func (q *Queries) GetLinkByID(ctx context.Context, id int64) (Link, error) {
|
||||
}
|
||||
|
||||
const getOwner = `-- name: GetOwner :one
|
||||
select id, created_at, last_used, name
|
||||
select id, created_at, last_used, name, show_shared
|
||||
from owners
|
||||
where id = ?
|
||||
`
|
||||
@ -535,6 +540,7 @@ func (q *Queries) GetOwner(ctx context.Context, id int64) (Owner, error) {
|
||||
&i.CreatedAt,
|
||||
&i.LastUsed,
|
||||
&i.Name,
|
||||
&i.ShowShared,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
@ -19,7 +19,7 @@
|
||||
in {
|
||||
gostart = pkgs.buildGoModule {
|
||||
pname = "gostart";
|
||||
version = "v0.1.5";
|
||||
version = "v0.1.6";
|
||||
src = ./.;
|
||||
|
||||
vendorSha256 =
|
||||
|
22
handlers.go
22
handlers.go
@ -350,7 +350,7 @@ var templateFuncs = template.FuncMap{
|
||||
|
||||
func index(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
owner, err := app.getOwner(r)
|
||||
systemOwner, err := app.getOwner(r)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
@ -367,6 +367,21 @@ func index(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
owner, err := app.queries.GetOwner(ctx, ownerID)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
// TODO: maybe I can do this with an sql join...
|
||||
filteredLinks := []data.Link{}
|
||||
for _, l := range links {
|
||||
if !owner.ShowShared && l.OwnerID != ownerID {
|
||||
continue
|
||||
}
|
||||
filteredLinks = append(filteredLinks, l)
|
||||
}
|
||||
|
||||
prs, err := app.queries.GetAllPullRequests(dbCtx, ownerID)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
@ -380,9 +395,10 @@ func index(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
stuff := &Page{
|
||||
Node: *owner,
|
||||
Node: *systemOwner,
|
||||
System: owner,
|
||||
Title: "StartPage",
|
||||
Links: links,
|
||||
Links: filteredLinks,
|
||||
PullRequests: prs,
|
||||
Watches: app.watches.forID(ownerID),
|
||||
CurrentLimits: app.watches.GetLimits(),
|
||||
|
1
page.go
1
page.go
@ -97,6 +97,7 @@ func getData(q GQLQuery, token string) (*WatchResult, error) {
|
||||
|
||||
type Page struct {
|
||||
Title string
|
||||
System data.Owner
|
||||
PullRequests []data.PullRequest
|
||||
Links []data.Link
|
||||
Node tailcfg.Node
|
||||
|
11
queries.sql
11
queries.sql
@ -1,6 +1,6 @@
|
||||
-- name: AddOwner :one
|
||||
insert into owners (id, name)
|
||||
values (?, ?) returning *;
|
||||
insert into owners (id, name, show_shared)
|
||||
values (?, ?, ?) returning *;
|
||||
|
||||
-- name: GetOwner :one
|
||||
select *
|
||||
@ -29,7 +29,8 @@ where id = ?
|
||||
-- name: GetAllLinksForOwner :many
|
||||
select *
|
||||
from links
|
||||
where owner_id = ? or shared = true;
|
||||
where owner_id = ?
|
||||
or shared = true;
|
||||
|
||||
-- name: GetAllLinks :many
|
||||
select *
|
||||
@ -40,7 +41,9 @@ insert into links (owner_id, url, name, logo_url, shared)
|
||||
values (?, ?, ?, ?, ?) returning *;
|
||||
|
||||
-- name: GetLinkByID :one
|
||||
select * from links where id = ?;
|
||||
select *
|
||||
from links
|
||||
where id = ?;
|
||||
|
||||
-- name: DeleteLink :exec
|
||||
delete
|
||||
|
@ -3,7 +3,8 @@ create table owners
|
||||
id integer primary key not null,
|
||||
created_at datetime default current_timestamp not null,
|
||||
last_used datetime default current_timestamp not null,
|
||||
name text not null unique
|
||||
name text not null unique,
|
||||
show_shared bool default false not null
|
||||
);
|
||||
create table watch_items
|
||||
(
|
||||
|
@ -55,6 +55,7 @@
|
||||
<body>
|
||||
<header>
|
||||
<h1>{{.Title}} for {{.Node.ComputedName}}</h1>
|
||||
{{if .System.ShowShared}}Showing shared links.{{end}}
|
||||
<p>
|
||||
Remaining queries: <b>{{.CurrentLimits.Remaining}}</b><br />
|
||||
Limit resets in <b>{{remaining .CurrentLimits.ResetAt}}</b> minutes.
|
||||
|
Loading…
Reference in New Issue
Block a user