api use
CI / lint-backend (push) Successful in 1m24s
CI / lint-mobile (push) Failing after 7m28s
CI / test-backend (push) Successful in 1m25s
CI / test-mobile (push) Successful in 9m9s
CI / build-backend (push) Successful in 45s
CI / docker (push) Successful in 33s
CI / lint-backend (push) Successful in 1m24s
CI / lint-mobile (push) Failing after 7m28s
CI / test-backend (push) Successful in 1m25s
CI / test-mobile (push) Successful in 9m9s
CI / build-backend (push) Successful in 45s
CI / docker (push) Successful in 33s
This commit is contained in:
@@ -455,5 +455,49 @@ func (s *Shares) ListActiveLinksForResource(resourceID string) ([]LinkInfo, erro
|
||||
return links, rows.Err()
|
||||
}
|
||||
|
||||
// ShareGrant is one active user-to-user grant on a resource (owner view).
|
||||
type ShareGrant struct {
|
||||
GranteeUserID string
|
||||
Username string
|
||||
Access string
|
||||
Inherit bool
|
||||
ExpiresAt *time.Time
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
// ListActiveForResource returns the active (non-revoked) grants on a resource,
|
||||
// oldest first. Expired grants are included (the owner sees what will lapse);
|
||||
// the caller filters display. Empty (not error) when nothing is shared.
|
||||
func (s *Shares) ListActiveForResource(resourceID string) ([]ShareGrant, error) {
|
||||
rows, err := s.DB.Query(
|
||||
`SELECT s.grantee_user_id, COALESCE(u.username, s.grantee_user_id),
|
||||
s.access, s.inherit, s.expires_at, s.updated_at
|
||||
FROM shares s
|
||||
LEFT JOIN users u ON u.id = s.grantee_user_id AND u.deleted_at IS NULL
|
||||
WHERE s.resource_id = $1 AND s.revoked_at IS NULL
|
||||
ORDER BY s.created_at ASC`,
|
||||
resourceID,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var grants []ShareGrant
|
||||
for rows.Next() {
|
||||
var (
|
||||
g ShareGrant
|
||||
expiresAt sql.NullTime
|
||||
)
|
||||
if err := rows.Scan(&g.GranteeUserID, &g.Username, &g.Access, &g.Inherit, &expiresAt, &g.UpdatedAt); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if expiresAt.Valid {
|
||||
g.ExpiresAt = &expiresAt.Time
|
||||
}
|
||||
grants = append(grants, g)
|
||||
}
|
||||
return grants, rows.Err()
|
||||
}
|
||||
|
||||
// Errors specific to shares.
|
||||
var ErrGranteeNotFound = errors.New("grantee user not found")
|
||||
|
||||
Reference in New Issue
Block a user