Skip to content

Commit

Permalink
Merge pull request #1592 from goodrain/V6.1
Browse files Browse the repository at this point in the history
feat: v6.1.0 release
  • Loading branch information
zzzhangqi authored Dec 31, 2024
2 parents 53ac840 + d683139 commit d138c28
Show file tree
Hide file tree
Showing 28 changed files with 1,127 additions and 141 deletions.
6 changes: 3 additions & 3 deletions console/appstore/appstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def get_app_hub_info(self, store=None, app_id=None, enterprise_id=None):
image_config["hub_password"] = data.hub_password
image_config["namespace"] = data.namespace
if not data:
data = EnterpriseConfigService(enterprise_id).get_config_by_key("APPSTORE_IMAGE_HUB")
data = EnterpriseConfigService(enterprise_id, "").get_config_by_key("APPSTORE_IMAGE_HUB")
if data and data.enable:
image_config_dict = eval(data.value)
namespace = (image_config_dict.get("namespace") if image_config_dict.get("namespace") else data.enterprise_id)
Expand All @@ -38,7 +38,7 @@ def get_app_hub_info(self, store=None, app_id=None, enterprise_id=None):
return image_config

def is_no_multiple_region_hub(self, enterprise_id):
data = EnterpriseConfigService(enterprise_id).get_config_by_key("APPSTORE_IMAGE_HUB")
data = EnterpriseConfigService(enterprise_id, "").get_config_by_key("APPSTORE_IMAGE_HUB")
if data and data.enable:
image_config_dict = eval(data.value)
if image_config_dict["hub_url"]:
Expand All @@ -57,7 +57,7 @@ def get_slug_hub_info(self, store=None, app_id=None, enterprise_id=None):
image_config["ftp_password"] = data.hub_password
image_config["namespace"] = data.namespace
if not data:
data = EnterpriseConfigService(enterprise_id).get_config_by_key("APPSTORE_IMAGE_HUB")
data = EnterpriseConfigService(enterprise_id, "").get_config_by_key("APPSTORE_IMAGE_HUB")
if data:
image_config_dict = eval(data.value)
namespace = (image_config_dict.get("namespace") if image_config_dict.get("namespace") else data.enterprise_id)
Expand Down
6 changes: 5 additions & 1 deletion console/models/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,9 @@ class Meta:
is_deleted = models.NullBooleanField(null=True, default=False, help_text="is_deleted")
is_console = models.NullBooleanField(null=True, default=False, help_text="is_console")
is_auto_login = models.NullBooleanField(null=True, default=False, help_text="is_auto_login")
is_git = models.NullBooleanField(null=True, default=True, help_text="是否为git仓库")
is_git = models.BooleanField(default=True, help_text="是否为git仓库")
user_id = models.IntegerField(max_length=10, help_text="用户ID")
system = models.BooleanField(default=False, help_text="是否后台创建")


class UserOAuthServices(BaseModel):
Expand Down Expand Up @@ -1121,6 +1123,8 @@ class Meta:
username = models.CharField(max_length=255, help_text="username")
password = models.CharField(max_length=255, help_text="password")
region_name = models.CharField(max_length=255, help_text="region_name")
hub_type = models.CharField(max_length=32, help_text="hub type")
user_id = models.IntegerField(max_length=10, help_text="用户ID")


class RKECluster(BaseModel):
Expand Down
86 changes: 53 additions & 33 deletions console/repositories/oauth_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,50 @@


class OAuthRepo(object):
def get_conosle_oauth_service(self, eid):
return OAuthServices.objects.filter(eid=eid, is_deleted=False, is_console=True).first()
def get_conosle_oauth_service(self, eid, user_id):
return OAuthServices.objects.filter(eid=eid, is_deleted=False, is_console=True, user_id=user_id).first()

def get_all_oauth_services(self, eid):
return OAuthServices.objects.filter(eid=eid, is_deleted=False)
def get_all_oauth_services(self, eid, user_id):
return OAuthServices.objects.filter(eid=eid, is_deleted=False, user_id=user_id)

def get_oauth_services(self, eid):
return OAuthServices.objects.filter(eid=eid, is_deleted=False, enable=True)
def get_oauth_services(self, eid, user_id):
return OAuthServices.objects.filter(eid=eid, is_deleted=False, enable=True, user_id=user_id)

def get_oauth_services_by_type(self, oauth_type, eid):
return OAuthServices.objects.filter(oauth_type=oauth_type, eid=eid, enable=True, is_deleted=False)
def get_oauth_services_by_type(self, oauth_type, eid, user_id):
return OAuthServices.objects.filter(oauth_type=oauth_type, eid=eid, enable=True, is_deleted=False, user_id=user_id)

def get_oauth_services_by_service_id(self, service_id=None):
def get_all_oauth_services_by_system(self, eid, is_system=True):
"""
Get all OAuth services filtered by system status
:param eid: enterprise ID
:param is_system: if True, get only system (public) services; if False, get non-system (private) services
:return: QuerySet of OAuthServices
"""
return OAuthServices.objects.filter(eid=eid, is_deleted=False, system=is_system)

def get_oauth_services_by_service_id(self, user_id, service_id=None):
if not service_id:
pre_enterprise_center = os.getenv("PRE_ENTERPRISE_CENTER", None)
if pre_enterprise_center:
return OAuthServices.objects.get(name=pre_enterprise_center, oauth_type="enterprisecenter")
return OAuthServices.objects.filter(oauth_type="enterprisecenter", enable=True, is_deleted=False).first()
return OAuthServices.objects.get(ID=service_id, enable=True, is_deleted=False)
return OAuthServices.objects.get(user_id=user_id, name=pre_enterprise_center, oauth_type="enterprisecenter")
return OAuthServices.objects.filter(user_id=user_id, oauth_type="enterprisecenter", enable=True, is_deleted=False).first()
return OAuthServices.objects.get(ID=service_id, enable=True, is_deleted=False, user_id=user_id)

@staticmethod
def get_by_client_id(client_id):
def get_by_client_id(client_id, user_id):
try:
return OAuthServices.objects.get(client_id=client_id, enable=True, is_deleted=False)
return OAuthServices.objects.get(client_id=client_id, enable=True, is_deleted=False, user_id=user_id)
except OAuthServices.DoesNotExist:
raise ErrOauthServiceNotFound

def open_get_oauth_services_by_service_id(self, service_id):
return OAuthServices.objects.filter(ID=service_id, is_deleted=False).first()
def open_get_oauth_services_by_service_id(self, service_id, user_id):
return OAuthServices.objects.filter(ID=service_id, is_deleted=False, user_id=user_id).first()

@staticmethod
def get_by_name(name):
return OAuthServices.objects.get(name=name)
def get_by_name(name, user_id):
return OAuthServices.objects.get(name=name, user_id=user_id)

def create_or_update_oauth_services(self, values, eid=None):
def create_or_update_oauth_services(self, values, eid=None, user_id=""):
querysetlist = []
for value in values:
instance = get_oauth_instance(value["oauth_type"])
Expand All @@ -56,7 +65,7 @@ def create_or_update_oauth_services(self, values, eid=None):
if value.get("service_id") is None:
# check if the name exists
try:
self.get_by_name(value["name"])
self.get_by_name(value["name"], user_id)
raise ErrOauthServiceExists
except OAuthServices.DoesNotExist:
pass
Expand All @@ -76,15 +85,19 @@ def create_or_update_oauth_services(self, values, eid=None):
is_auto_login=value["is_auto_login"],
is_console=value["is_console"],
is_deleted=value.get("is_deleted", False),
is_git=is_git))
is_git=is_git,
user_id=user_id,
system=value.get("system", False),
)
)
else:
if value.get("is_deleted"):
self.delete_oauth_service(service_id=value.get("service_id"))
self.delete_oauth_service(service_id=value.get("service_id"), user_id=user_id)
else:
old_service = self.open_get_oauth_services_by_service_id(service_id=value.get("service_id"))
old_service = self.open_get_oauth_services_by_service_id(service_id=value.get("service_id"), user_id=user_id)
if old_service.home_url != value["home_url"]:
UserOAuthServices.objects.filter(service_id=value.get("service_id")).delete()
OAuthServices.objects.filter(ID=value["service_id"]).update(
OAuthServices.objects.filter(ID=value["service_id"], user_id=user_id).update(
name=value["name"],
eid=value["eid"],
redirect_uri=value["redirect_uri"],
Expand All @@ -98,11 +111,11 @@ def create_or_update_oauth_services(self, values, eid=None):
if eid is None:
eid = value["eid"]
OAuthServices.objects.bulk_create(querysetlist)
rst = OAuthServices.objects.filter(eid=eid)
rst = OAuthServices.objects.filter(eid=eid, user_id=user_id)
return rst

def create_or_update_console_oauth_services(self, values, eid):
old_oauth_service = OAuthServices.objects.filter(eid=eid, is_console=True).first()
def create_or_update_console_oauth_services(self, values, eid, user_id, system):
old_oauth_service = OAuthServices.objects.filter(eid=eid, is_console=True, user_id=user_id).first()
for value in values[:1]:
if value["oauth_type"] in list(support_oauth_type.keys()):
instance = get_oauth_instance(value["oauth_type"])
Expand All @@ -125,9 +138,12 @@ def create_or_update_console_oauth_services(self, values, eid):
enable=value["enable"],
is_auto_login=value["is_auto_login"],
is_console=value["is_console"],
is_git=is_git)
is_git=is_git,
user_id=user_id,
system=system,
)
elif old_oauth_service is not None and value.get("service_id") == old_oauth_service.ID:
OAuthServices.objects.filter(ID=value["service_id"]).update(
OAuthServices.objects.filter(ID=value["service_id"], user_id=user_id).update(
name=value["name"],
eid=value["eid"],
redirect_uri=value["redirect_uri"],
Expand All @@ -140,11 +156,11 @@ def create_or_update_console_oauth_services(self, values, eid):
is_console=value["is_console"])
else:
raise Exception("未找到该OAuth类型")
rst = OAuthServices.objects.filter(eid=eid, is_console=True)
rst = OAuthServices.objects.filter(eid=eid, is_console=True, user_id=user_id)
return rst

def delete_oauth_service(self, service_id):
OAuthServices.objects.filter(ID=service_id).delete()
def delete_oauth_service(self, service_id, user_id):
OAuthServices.objects.filter(ID=service_id, user_id=user_id).delete()


class UserOAuthRepo(object):
Expand Down Expand Up @@ -200,6 +216,10 @@ def user_oauth_exists(self, service_id, oauth_user_id):
except UserOAuthServices.DoesNotExist:
return None

def get_by_oauths_user_id(self, service_ids, user_id):
return UserOAuthServices.objects.filter(service_id__in=service_ids, user_id=user_id)


def get_all_user_oauth(self, user_id):
return UserOAuthServices.objects.filter(user_id=user_id)

Expand Down Expand Up @@ -252,7 +272,7 @@ def user_oauth_is_link(self, service_id, oauth_user_id):

def get_user_oauth_services_info(self, eid, user_id):
oauth_services = []
services = OAuthServices.objects.filter(eid=eid, is_deleted=False, enable=True)
services = OAuthServices.objects.filter(eid=eid, is_deleted=False, enable=True, user_id=user_id)
for service in services:
user_service = self.get_user_oauth_by_user_id(service_id=service.ID, user_id=user_id)
api = get_oauth_instance(service.oauth_type, service, None)
Expand Down
40 changes: 35 additions & 5 deletions console/repositories/team_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from console.models.main import RegionConfig, TeamGitlabInfo, TeamRegistryAuth
from console.repositories.base import BaseConnection
from django.db.models import Q
from www.models.main import (PermRelTenant, TenantEnterprise, TenantRegionInfo, Tenants, Users)
from www.models.main import (PermRelTenant, TenantEnterprise, TenantRegionInfo, Tenants, Users, TeamInvitation)
from www.utils.crypt import make_tenant_id

logger = logging.getLogger("default")
Expand Down Expand Up @@ -348,8 +348,11 @@ def get_team_repo_by_code_name(self, team_id, repo_name):


class TeamRegistryAuthRepo(object):
def list_by_team_id(self, tenant_id, region_name):
return TeamRegistryAuth.objects.filter(tenant_id=tenant_id, region_name=region_name)
def list_by_team_id(self, tenant_id, region_name, user_id):
return TeamRegistryAuth.objects.filter(tenant_id=tenant_id, region_name=region_name, user_id=user_id)

def check_exist_registry_auth(self, secret_id, user_id):
return TeamRegistryAuth.objects.filter(secret_id=secret_id, user_id=user_id)

def create_team_registry_auth(self, **params):
return TeamRegistryAuth.objects.create(**params)
Expand All @@ -358,8 +361,8 @@ def update_team_registry_auth(self, tenant_id, region_name, secret_id, **params)
return TeamRegistryAuth.objects.filter(
tenant_id=tenant_id, region_name=region_name, secret_id=secret_id).update(**params)

def delete_team_registry_auth(self, tenant_id, region_name, secret_id):
return TeamRegistryAuth.objects.filter(tenant_id=tenant_id, region_name=region_name, secret_id=secret_id).delete()
def delete_team_registry_auth(self, tenant_id, region_name, secret_id, user_id):
return TeamRegistryAuth.objects.filter(tenant_id=tenant_id, region_name=region_name, secret_id=secret_id, user_id=user_id).delete()

def get_by_secret_id(self, secret_id):
return TeamRegistryAuth.objects.filter(secret_id=secret_id)
Expand All @@ -368,6 +371,33 @@ def get_by_team_id_domain(self, tenant_id, region_name, domain):
return TeamRegistryAuth.objects.filter(tenant_id=tenant_id, region_name=region_name, domain=domain)


class TeamInvitationRepo(object):
def list_by_user_id(self, user_id):
"""获取用户收到的所有邀请"""
return TeamInvitation.objects.filter(user_id=user_id)

def get_invitation_by_id(self, invitation_id):
"""通过ID获取邀请信息"""
return TeamInvitation.objects.filter(invitation_id=invitation_id).first()

def list_by_team_id(self, team_id):
"""获取团队所有邀请记录"""
return TeamInvitation.objects.filter(tenant_id=team_id)

def create_invitation(self, **params):
"""创建新的团队邀请"""
return TeamInvitation.objects.create(**params)

def delete_invitation(self, invitation_id):
"""删除团队邀请"""
return TeamInvitation.objects.filter(invitation_id=invitation_id).delete()

def update_invitation(self, invitation_id, **params):
"""更新邀请信息"""
return TeamInvitation.objects.filter(invitation_id=invitation_id).update(**params)


team_repo = TeamRepo()
team_gitlab_repo = TeamGitlabRepo()
team_registry_auth_repo = TeamRegistryAuthRepo()
team_invitation_repo = TeamInvitationRepo()
4 changes: 2 additions & 2 deletions console/services/app_actions/app_manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def deploy(self, tenant, service, user, oauth_instance=None, service_copy_path=N
if kind == "build_from_source_code" or kind == "source":
if service.oauth_service_id:
try:
oauth_service = oauth_repo.get_oauth_services_by_service_id(service_id=service.oauth_service_id)
oauth_service = oauth_repo.get_oauth_services_by_service_id(user.user_id, service_id=service.oauth_service_id)
oauth_user = oauth_user_repo.get_user_oauth_by_user_id(
service_id=service.oauth_service_id, user_id=user.user_id)
except Exception as e:
Expand Down Expand Up @@ -629,7 +629,7 @@ def deploy_services_info(self, body, services, tenant, user, oauth_instance, tem
source_code["cmd"] = service.cmd
if service.oauth_service_id:
try:
oauth_service = oauth_repo.get_oauth_services_by_service_id(service_id=service.oauth_service_id)
oauth_service = oauth_repo.get_oauth_services_by_service_id(user.user_id, service_id=service.oauth_service_id)
oauth_user = oauth_user_repo.get_user_oauth_by_user_id(
service_id=service.oauth_service_id, user_id=user.user_id)
except Exception as e:
Expand Down
4 changes: 2 additions & 2 deletions console/services/app_check_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def check_service(self, tenant, service, is_again, event_id, user=None):
if service.service_source == AppConstants.SOURCE_CODE:
if service.oauth_service_id:
try:
oauth_service = oauth_repo.get_oauth_services_by_service_id(service.oauth_service_id)
oauth_service = oauth_repo.get_oauth_services_by_service_id(user.user_id, service.oauth_service_id)
oauth_user = oauth_user_repo.get_user_oauth_by_user_id(
service_id=service.oauth_service_id, user_id=user.user_id)
except Exception as e:
Expand Down Expand Up @@ -196,7 +196,7 @@ def update_service_check_info(self, tenant, service, data):
transaction.savepoint_rollback(sid)
raise ServiceHandleException(status_code=400, msg="handle check service code info failure", msg_show="处理检测结果失败")

def save_service_check_info(self, tenant, service, data):
def save_service_check_info(self, tenant, app_id, service, data):
# save the detection properties but does not throw any exception.
if data["check_status"] == "success" and service.create_status == "checking":
logger.debug("checking service info install,save info into database")
Expand Down
Loading

0 comments on commit d138c28

Please sign in to comment.