Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
webomagic-auth
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Pratik Shrivastava
webomagic-auth
Commits
0d503270
Commit
0d503270
authored
Jul 21, 2024
by
deepdey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: restructure user-info
parent
f2ea403b
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
32 additions
and
28 deletions
+32
-28
app/orm/role_orm.py
app/orm/role_orm.py
+0
-2
app/orm/user_orm.py
app/orm/user_orm.py
+2
-0
app/routes/user/user_response.py
app/routes/user/user_response.py
+4
-0
app/routes/user/user_util.py
app/routes/user/user_util.py
+16
-18
database/schema.sql
database/schema.sql
+10
-8
No files found.
app/orm/role_orm.py
View file @
0d503270
...
...
@@ -25,8 +25,6 @@ class Role(db.Model, CustomSerializerMixin):
updated_by
=
db
.
Column
(
db
.
BigInteger
)
is_deleted
=
db
.
Column
(
db
.
Boolean
,
default
=
False
)
role_type
=
db
.
relationship
(
'RoleType'
)
__table_args__
=
(
db
.
UniqueConstraint
(
'project_id'
,
'role_name'
,
name
=
'uq_project_id_role_name'
),
)
...
...
app/orm/user_orm.py
View file @
0d503270
...
...
@@ -19,6 +19,7 @@ class User(db.Model, CustomSerializerMixin):
password
=
db
.
Column
(
db
.
String
(
80
),
nullable
=
False
)
organization
=
db
.
Column
(
db
.
String
(
255
),
nullable
=
False
)
project_id
=
db
.
Column
(
db
.
BigInteger
,
nullable
=
True
)
role_type_id
=
db
.
Column
(
db
.
BigInteger
,
db
.
ForeignKey
(
'role_type.id'
),
nullable
=
False
)
gstin
=
db
.
Column
(
db
.
String
(
50
),
nullable
=
False
)
email
=
db
.
Column
(
db
.
String
(
120
),
nullable
=
False
,
unique
=
True
)
phone_number
=
db
.
Column
(
db
.
String
(
20
),
nullable
=
False
,
unique
=
True
)
...
...
@@ -33,5 +34,6 @@ class User(db.Model, CustomSerializerMixin):
is_deleted
=
db
.
Column
(
db
.
Boolean
,
default
=
False
)
user_roles
=
db
.
relationship
(
'UserRoleMap'
)
role_type
=
db
.
relationship
(
'RoleType'
)
serialize_rules
=
(
'-password'
,)
app/routes/user/user_response.py
View file @
0d503270
...
...
@@ -3,6 +3,7 @@ from app.app_config.response_message import *
from
app.routes
import
api
from
flask_restx
import
fields
from
app.routes.role_type.role_type_response
import
ROLE_TYPE_RESPONSE_MODEL
from
app.utils.api_response
import
prepare_swagger_response
USER_RESPONSE_MODEL
:
any
=
api
.
model
(
...
...
@@ -18,6 +19,9 @@ USER_RESPONSE_MODEL: any = api.model(
'email_verified'
:
fields
.
Boolean
,
'phone_verified'
:
fields
.
Boolean
,
'status'
:
fields
.
String
,
'role_type_id'
:
fields
.
Integer
,
'project_id'
:
fields
.
Integer
,
'role_type'
:
fields
.
Nested
(
ROLE_TYPE_RESPONSE_MODEL
),
'user_roles'
:
fields
.
List
(
fields
.
String
(
default
=
'{}'
,
description
=
'user roles object in json'
)
),
...
...
app/routes/user/user_util.py
View file @
0d503270
from
typing
import
List
from
app
import
orm
as
ORM
from
app.app_config.constant
import
EndpointTagEnum
from
app.utils.redis
import
set_value
from
app
import
db
def
process_valid_loging
(
user_info
:
ORM
.
User
,
api_key
:
str
)
->
None
:
set_value
(
f
'{user_info.id}_un'
,
user_info
.
username
,
60
*
60
*
24
)
set_value
(
f
'{api_key}_id'
,
user_info
.
id
,
60
*
60
*
24
)
DEFAULT_EXPIRES
:
int
=
60
*
60
*
24
set_value
(
f
'{user_info.id}_un'
,
user_info
.
username
,
DEFAULT_EXPIRES
)
set_value
(
f
'{user_info.id}_pid'
,
user_info
.
project_id
,
DEFAULT_EXPIRES
)
set_value
(
f
'{api_key}_id'
,
user_info
.
id
,
DEFAULT_EXPIRES
)
# TODO: currently we consider user have only one role
if
len
(
user_info
.
user_roles
)
>
0
:
set_value
(
f
'{api_key}_rid'
,
user_info
.
user_roles
[
0
]
.
role
.
id
,
60
*
60
*
24
)
set_value
(
f
'{user_info.id}_rn'
,
user_info
.
user_roles
[
0
]
.
role
.
role_name
,
60
*
60
*
24
,
)
set_value
(
f
'{user_info.id}_rt'
,
user_info
.
user_roles
[
0
]
.
role
.
role_type
.
role_name
,
60
*
60
*
24
,
)
role_id
:
int
=
user_info
.
user_roles
[
0
]
.
role_id
role_name
:
str
=
user_info
.
user_roles
[
0
]
.
role
.
role_name
set_value
(
f
'{user_info.id}_rid'
,
role_id
,
DEFAULT_EXPIRES
)
set_value
(
f
'{user_info.id}_rn'
,
role_name
,
DEFAULT_EXPIRES
)
set_value
(
f
'{user_info.id}_rt'
,
user_info
.
role_type_id
,
DEFAULT_EXPIRES
)
# TODO: fetch all api mapped with role id and set in redis
api_list
:
List
[
ORM
.
Api
]
=
(
db
.
session
.
query
(
ORM
.
Api
)
.
join
(
ORM
.
RoleApiMap
,
ORM
.
Api
.
id
==
ORM
.
RoleApiMap
.
api_id
)
.
filter
(
ORM
.
RoleApiMap
.
role_id
==
user_info
.
user_roles
[
0
]
.
role
.
id
,
ORM
.
Api
.
tag
==
'RA'
,
ORM
.
RoleApiMap
.
role_id
==
role_
id
,
ORM
.
Api
.
tag
==
EndpointTagEnum
.
RA
.
value
,
)
.
all
()
)
for
api
in
api_list
:
set_value
(
f
'r_{
user_info.user_roles[0].role.
id}_{api.id}_{api.method}'
,
f
'r_{
role_
id}_{api.id}_{api.method}'
,
1
,
60
*
60
*
24
,
DEFAULT_EXPIRES
,
)
database/schema.sql
View file @
0d503270
CREATE
TABLE
IF
NOT
EXISTS
role_type
(
id
BIGSERIAL
PRIMARY
KEY
NOT
NULL
,
role_name
VARCHAR
(
80
)
UNIQUE
NOT
NULL
,
is_deleted
BOOLEAN
DEFAULT
false
,
created_at
TIMESTAMP
NOT
NULL
DEFAULT
now
(),
updated_at
TIMESTAMP
);
CREATE
TABLE
IF
NOT
EXISTS
webomagic_user
(
id
BIGSERIAL
PRIMARY
KEY
NOT
NULL
,
username
VARCHAR
(
80
)
UNIQUE
NOT
NULL
,
...
...
@@ -5,6 +13,7 @@ CREATE TABLE IF NOT EXISTS webomagic_user (
password
VARCHAR
(
80
)
NOT
NULL
,
organization
VARCHAR
(
255
),
project_id
BIGINT
,
role_type_id
BIGINT
NOT
NULL
,
gstin
VARCHAR
(
50
),
email
VARCHAR
(
120
)
UNIQUE
NOT
NULL
,
phone_number
VARCHAR
(
20
)
UNIQUE
NOT
NULL
,
...
...
@@ -16,6 +25,7 @@ CREATE TABLE IF NOT EXISTS webomagic_user (
created_by
BIGINT
,
updated_at
TIMESTAMP
,
updated_by
BIGINT
,
FOREIGN
KEY
(
role_type_id
)
REFERENCES
role_type
(
id
),
FOREIGN
KEY
(
created_by
)
REFERENCES
webomagic_user
(
id
),
FOREIGN
KEY
(
updated_by
)
REFERENCES
webomagic_user
(
id
)
);
...
...
@@ -34,14 +44,6 @@ CREATE TABLE IF NOT EXISTS webomagic_api (
UNIQUE
(
endpoint
,
method
)
);
CREATE
TABLE
IF
NOT
EXISTS
role_type
(
id
BIGSERIAL
PRIMARY
KEY
NOT
NULL
,
role_name
VARCHAR
(
80
)
UNIQUE
NOT
NULL
,
is_deleted
BOOLEAN
DEFAULT
false
,
created_at
TIMESTAMP
NOT
NULL
DEFAULT
now
(),
updated_at
TIMESTAMP
);
CREATE
TABLE
IF
NOT
EXISTS
role
(
id
BIGSERIAL
PRIMARY
KEY
NOT
NULL
,
role_type_id
BIGINT
NOT
NULL
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment