zhichyu commited on
Commit
f6c03ce
·
1 Parent(s): dbca2f3

Unified user_service.py (#4606)

Browse files

### What problem does this PR solve?

Unified user_service.py

### Type of change

- [x] Refactoring

Files changed (1) hide show
  1. api/db/services/user_service.py +8 -0
api/db/services/user_service.py CHANGED
@@ -13,6 +13,7 @@
13
  # See the License for the specific language governing permissions and
14
  # limitations under the License.
15
  #
 
16
  from datetime import datetime
17
 
18
  import peewee
@@ -24,6 +25,7 @@ from api.db.db_models import User, Tenant
24
  from api.db.services.common_service import CommonService
25
  from api.utils import get_uuid, current_timestamp, datetime_format
26
  from api.db import StatusEnum
 
27
 
28
 
29
  class UserService(CommonService):
@@ -48,6 +50,12 @@ class UserService(CommonService):
48
  else:
49
  return None
50
 
 
 
 
 
 
 
51
  @classmethod
52
  @DB.connection_context()
53
  def save(cls, **kwargs):
 
13
  # See the License for the specific language governing permissions and
14
  # limitations under the License.
15
  #
16
+ import hashlib
17
  from datetime import datetime
18
 
19
  import peewee
 
25
  from api.db.services.common_service import CommonService
26
  from api.utils import get_uuid, current_timestamp, datetime_format
27
  from api.db import StatusEnum
28
+ from rag.settings import MINIO
29
 
30
 
31
  class UserService(CommonService):
 
50
  else:
51
  return None
52
 
53
+ @classmethod
54
+ @DB.connection_context()
55
+ def user_gateway(cls, tenant_id):
56
+ hashobj = hashlib.sha256(tenant_id.encode("utf-8"))
57
+ return int(hashobj.hexdigest(), 16)%len(MINIO)
58
+
59
  @classmethod
60
  @DB.connection_context()
61
  def save(cls, **kwargs):