Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
02fa1c72
Commit
02fa1c72
authored
10 years ago
by
Cam Saul
Browse files
Options
Downloads
Patches
Plain Diff
defannotation macro
parent
4afaf95b
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/metabase/api/common.clj
+17
-3
17 additions, 3 deletions
src/metabase/api/common.clj
src/metabase/api/user.clj
+8
-6
8 additions, 6 deletions
src/metabase/api/user.clj
with
25 additions
and
9 deletions
src/metabase/api/common.clj
+
17
−
3
View file @
02fa1c72
...
...
@@ -193,10 +193,24 @@
(
defmethod
arg-annotation-fn
:default
[
annotation-kw
arg-symbol
]
(
throw
(
Exception.
(
format
"Don't know what to do with arg annotation '%s' on arg '%s'!"
(
name
annotation-kw
)
(
name
arg-symbol
)))))
(
defmacro
defannotation
"Convenience for defining a new `defendpoint` arg annotation.
BINDING is the actual symbol name of the arg being checked; `defannotation` returns form(s)
that will be included in the let binding for the annotated arg.
(defannotation required [param]
`(require-params ~param) ; quasiquoting needed to keep require-params from being evaluated at macroexpansion time
param)"
[
annotation-name
[
binding
]
&
body
]
`
(
defmethod
arg-annotation-fn
~
(
keyword
annotation-name
)
[
~
'_
~
binding
]
`
(
do
~~@
body
)))
;; `required` just calls require-params
(
def
method
arg-
annotation
-fn
:
required
[
_
arg-symbol
]
`
(
do
(
require-params
~
ar
g-symbol
)
~
arg-symbol
)
)
(
defannotation
required
[
param
]
`
(
require-params
~
p
ar
am
)
param
)
;;; ### defendpoint
...
...
This diff is collapsed.
Click to expand it.
src/metabase/api/user.clj
+
8
−
6
View file @
02fa1c72
...
...
@@ -21,14 +21,14 @@
(
hydrate
[
:org_perms
:organization
])))
(
defendpoint
GET
"/:id"
[
id
]
(
defendpoint
GET
"/:id"
[
id
fish.required
]
;; user must be getting their own details OR they must be a superuser to proceed
(
check-403
(
or
(
=
id
*current-user-id*
)
(
:is_superuser
@
*current-user*
)))
(
check-404
(
sel
:one
User
:id
id
)))
(
def
method
arg-
annotation
-fn
:
email
[
_
arg-symb
]
`
(
do
(
check
(
is-email?
~
arg-symb
)
[
400
(
format
~
(
str
(
name
arg-symb
)
" '%s' is not a valid email."
)
~
arg-symb
)])
~
arg-symb
)
)
(
defannotation
email
[
email
]
`
(
check
(
is-email?
~
email
)
[
400
(
format
~
(
str
(
name
email
)
" '%s' is not a valid email."
)
~
email
)])
email
)
(
defendpoint
PUT
"/:id"
[
id
:as
{{
:keys
[
email.email
]
:as
body
}
:body
}]
;; user must be getting their own details OR they must be a superuser to proceed
...
...
@@ -40,10 +40,12 @@
(
mapply
upd
User
id
)))
(
sel
:one
User
:id
id
))
(
defannotation
complex-password
[
password
]
`
(
check
(
password/is-complex?
~
password
)
[
400
"Insufficient password strength"
])
password
)
(
defendpoint
PUT
"/:id/password"
[
id
:as
{{
:keys
[
password.required
old_password.required
]}
:body
}]
(
defendpoint
PUT
"/:id/password"
[
id
:as
{{
:keys
[
password.required
.complex-password
old_password.required
]}
:body
}]
(
require-params
password
old_password
)
(
check
(
password/is-complex?
password
)
[
400
"Insufficient password strength"
])
(
check-403
(
or
(
=
id
*current-user-id*
)
(
:is_superuser
@
*current-user*
)))
(
let-404
[
user
(
sel
:one
[
User
:password_salt
:password
]
:id
id
)]
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment