Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize page styles and fix known bugs #99

Merged
merged 2 commits into from
Sep 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions backend/app/controllers/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
def add():
_ = getI18n("controllers")
name = request.json.get('app_name')
tenant_id = request.json.get('app_tenant_id')
tenant_id = session['tenant_id']
app_id = request.json.get('app_id')
default_source_branch = request.json.get('app_default_source_branch')
default_target_branch = request.json.get('app_default_target_branch')
Expand Down Expand Up @@ -50,11 +50,11 @@ def add():
@json_response
def getAll():
_ = getI18n("controllers")
owner = session['username']
tenantID = session['tenant_id']
appID = request.args.get('app_id')

try:
apps = Application.get_all_application(owner, appID)
apps = Application.get_all_application(tenantID, appID)

return {'apps': apps}
except Exception as e:
Expand Down
26 changes: 21 additions & 5 deletions backend/app/controllers/requirement.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from flask import Blueprint, request, session
from flask import Blueprint, request, session, json
from app.controllers.common import json_response
from app.models.task import getEmptyTaskInfo
from app.pkgs.tools.i18b import getI18n
Expand All @@ -18,10 +18,11 @@ def clear_up():
print("clear_up failed:"+str(e))

session[session["username"]] = getEmptyTaskInfo()
tenant_name = "DevOpsGPT"
tenant_name = "-"
if GRADE != "base":
tenant = Tenant.get_tenant_baseinfo_by_id(session["tenant_id"])
tenant_name = tenant["name"]
if tenant:
tenant_name = tenant["name"]

return {"username": session["username"], "tenant_name": tenant_name, "tenant_id": session["tenant_id"], "info": session[session["username"]]}

Expand All @@ -40,7 +41,7 @@ def setup_app():
if GRADE != "base" and not Tenant.check_quota(tenantID):
raise Exception(_("You have exceeded your quota limit, please check your business bill."))

requirement = Requirement.create_requirement(tenantID, "New requirement", "New", appID, 1, sourceBranch, featureBranch, REQUIREMENT_STATUS_NotStarted, 0, 0)
requirement = Requirement.create_requirement(tenantID, "New requirement", "New", appID, username, sourceBranch, featureBranch, REQUIREMENT_STATUS_NotStarted, 0, 0)

session[username]['memory']['task_info'] = {
"app_id": appID,
Expand Down Expand Up @@ -86,4 +87,19 @@ def get_one():
if GRADE != "base":
requirement["memory"] = RequirementMemory.get_all_requirement_memories(requirementID, 1)

return requirement
return requirement

@bp.route('/update', methods=['POST'])
@json_response
def update():
_ = getI18n("controllers")
data = request.json
requirement_id = data['requirement_id']
update_data = data['data']

requirement = Requirement.update_requirement(requirement_id, **update_data)

if requirement.requirement_id:
return Requirement.get_requirement_by_id(requirement.requirement_id)
else:
raise Exception(_("Failed to set up app."))
14 changes: 7 additions & 7 deletions backend/app/controllers/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@json_response
def get_git_config_list():
_ = getI18n("controllers")
tenantID = session['tenant_id']
tenantID = request.args.get('tenant_id')

gitList, success = getGitConfigList(tenantID, 0)
if not success:
Expand All @@ -25,7 +25,7 @@ def get_git_config_list():
@json_response
def get_ci_config_list():
_ = getI18n("controllers")
tenantID = session['tenant_id']
tenantID = request.args.get('tenant_id')

gitList, success = getCIConfigList(tenantID, 0)
if not success:
Expand All @@ -37,7 +37,7 @@ def get_ci_config_list():
@json_response
def get_cd_config_list():
_ = getI18n("controllers")
tenantID = session['tenant_id']
tenantID = request.args.get('tenant_id')

gitList, success = getCDConfigList(tenantID, 0)
if not success:
Expand All @@ -50,7 +50,7 @@ def get_cd_config_list():
def get_llm_config_list():
_ = getI18n("controllers")
raise Exception(_("Failed to get git config list."))
tenantID = session['tenant_id']
tenantID = request.args.get('tenant_id')

gitList, success = getLLMConfigList(tenantID, 0)
if not success:
Expand All @@ -70,7 +70,7 @@ def edit_git():
git_config_id = request.json.get('git_config_id')
name = request.json.get('git_name')
creater = session['username']
tenant_id = session['tenant_id']
tenant_id = request.json.get('tenant_id')

try:
if git_config_id:
Expand All @@ -94,7 +94,7 @@ def edit_ci():
ci_config_id = request.json.get('ci_config_id')
name = request.json.get('ci_name')
creater = session['username']
tenant_id = session['tenant_id']
tenant_id = request.json.get('tenant_id')

try:
if ci_config_id:
Expand All @@ -118,7 +118,7 @@ def edit_cd():
cd_provider = request.json.get('cd_provider')
name = request.json.get('cd_name')
creater = session['username']
tenant_id = session['tenant_id']
tenant_id = request.json.get('tenant_id')

try:
if cd_config_id:
Expand Down
6 changes: 5 additions & 1 deletion backend/app/controllers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,19 @@ def login():
if GRADE == "base":
ok = User.checkPassword(username, password)
session['tenant_id'] = 0
session['user_id'] = 1
session['username'] = username
else:
ok = UserPro.checkPassword(username, password)
if ok:
userinfo = UserPro.get_user_by_name(username)
session['language'] = userinfo["zone_language"]

session['tenant_id'] = userinfo["current_tenant"]
session['user_id'] = userinfo["user_id"]
session['username'] = username

if ok:
session['username'] = username
return {'message': _('Login successful.')}
else:
raise Exception(_("Invalid username or password"))
Expand Down
4 changes: 3 additions & 1 deletion backend/app/models/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ def create(tenant_id, creater, name, description, default_source_branch, default
return app

@staticmethod
def get_all_application(owner, appID):
def get_all_application(tenant_id, appID):
applications = Application.query.order_by(Application.app_id.desc()).all()
if appID:
applications = Application.query.filter_by(app_id=appID).all()
if tenant_id:
applications = Application.query.filter_by(tenant_id=tenant_id).all()

application_list = []

Expand Down
34 changes: 10 additions & 24 deletions backend/app/models/requirement.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import datetime
from app.extensions import db
from app.models.application import Application

Expand All @@ -7,7 +8,7 @@ class Requirement(db.Model):
requirement_name = db.Column(db.String(255), nullable=False)
original_requirement = db.Column(db.String(1000))
app_id = db.Column(db.Integer, nullable=False)
user_id = db.Column(db.Integer, nullable=False)
username = db.Column(db.String(100))
default_source_branch = db.Column(db.String(255))
default_target_branch = db.Column(db.String(255))
status = db.Column(db.String(20))
Expand All @@ -17,13 +18,13 @@ class Requirement(db.Model):
updated_at = db.Column(db.TIMESTAMP, default=db.func.current_timestamp(), onupdate=db.func.current_timestamp())

@staticmethod
def create_requirement(tenant_id, requirement_name, original_requirement, app_id, user_id, default_source_branch, default_target_branch, status, satisfaction_rating=None, completion_rating=None):
def create_requirement(tenant_id, requirement_name, original_requirement, app_id, username, default_source_branch, default_target_branch, status, satisfaction_rating=None, completion_rating=None):
requirement = Requirement(
tenant_id=tenant_id,
requirement_name=requirement_name,
original_requirement=original_requirement,
app_id=app_id,
user_id=user_id,
username=username,
status=status,
default_source_branch=default_source_branch,
default_target_branch=default_target_branch,
Expand All @@ -45,7 +46,7 @@ def get_all_requirements(tenantID=None):
'requirement_name': req.requirement_name,
'original_requirement': req.original_requirement,
'app_id': req.app_id,
'user_id': req.user_id,
'username': req.username,
'default_source_branch': req.default_source_branch,
'default_target_branch': req.default_target_branch,
'status': req.status,
Expand All @@ -67,7 +68,7 @@ def get_requirement_by_id(requirement_id):
'requirement_name': req.requirement_name,
'original_requirement': req.original_requirement,
'app_id': req.app_id,
'user_id': req.user_id,
'username': req.username,
'default_source_branch': req.default_source_branch,
'default_target_branch': req.default_target_branch,
'status': req.status,
Expand All @@ -81,31 +82,16 @@ def get_requirement_by_id(requirement_id):
return None

@staticmethod
def update_requirement(requirement_id, requirement_name=None, original_requirement=None, app_id=None, user_id=None, status=None, satisfaction_rating=None, completion_rating=None):
def update_requirement(requirement_id, **kwargs):
requirement = Requirement.query.get(requirement_id)

if requirement:
if requirement_name is not None:
requirement.requirement_name = requirement_name
if original_requirement is not None:
requirement.original_requirement = original_requirement
if app_id is not None:
requirement.app_id = app_id
if user_id is not None:
requirement.user_id = user_id
if status is not None:
requirement.status = status
if satisfaction_rating is not None:
requirement.satisfaction_rating = satisfaction_rating
if completion_rating is not None:
requirement.completion_rating = completion_rating

for key, value in kwargs.items():
setattr(requirement, key, value)
requirement.updated_at = datetime.utcnow()
db.session.commit()
return requirement

return None


@staticmethod
def delete_requirement(requirement_id):
requirement = Requirement.query.get(requirement_id)
Expand Down
3 changes: 3 additions & 0 deletions backend/app/pkgs/tools/i18b.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,7 @@ def getFrontendText():
"app_cd_config": _("Associated CD Config"),
"app_ci_config": _("Associated CI Config"),
"app_git_config": _("Associated Git Config"),
"my_role": _("My Role"),
"others_1": _("The tenant does not exist or is abnormal"),
"others_2": _("Insufficient authority."),
}
51 changes: 20 additions & 31 deletions backend/run.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from app.extensions import db
import datetime
from app.controllers import register_controllers
from flask import Flask, request, session, abort
from flask import Flask, request, session
from flask_cors import CORS
from app.models.task import getEmptyTaskInfo
from app.models.tenant_pro import Tenant
from app.models.tenant_user_pro import TenantUser
from app.models.user_pro import UserPro
from config import APP_SECRET_KEY, BACKEND_DEBUG, BACKEND_HOST, BACKEND_PORT, AICODER_ALLOWED_ORIGIN, AUTO_LOGIN, GRADE

app = Flask(__name__)
Expand All @@ -16,13 +15,14 @@

@app.before_request
def require_login():
if AUTO_LOGIN:
if AUTO_LOGIN and GRADE == "base":
if "username" not in session:
session['username'] = "demo_user"
session['user_id'] = 1
session['tenant_id'] = 0
session[session["username"]] = getEmptyTaskInfo()
path = request.path

path = request.path
if path == '/user/language' or path == '/user/login' or path == '/user/logout' or path == '/user/change_language' or path == '/user/register':
pass
elif 'username' not in session:
Expand All @@ -35,35 +35,24 @@ def require_login():
print(f"req_user: {user}")
print(f"req_path: {path}")
print(f"req_args: {args}")

if GRADE != "base":
current_path = request.args.get('url_path')
if (current_path == "/tenant.html" or current_path == "/tenant_new.html") and path=="/requirement/clear_up":
pass
elif path =="/tenant/create" or path=="/tenant/get_all" or path=="/tenant/use_tenant":
pass
else:
success, msg, code = check_tenant_membership_and_permissions()
if not success:
return {'success': False, 'error': msg, 'code': code}

def check_tenant_membership_and_permissions():
username = session["username"]
user = UserPro.get_user_by_name(username)
tenant_id = session['tenant_id']
success, msg = Tenant.check_tenant(tenant_id)
print("check_tenant_membership_and_permissions:")
print(tenant_id)
print(msg)
print(success)
if not success:
return success, msg, 404

success, msg = TenantUser.check_role(user["user_id"], tenant_id, request.path)
if not success:
return success, msg, 403

return success, msg, 200
try:
tenant_id = session['tenant_id']
if not tenant_id:
tenant_id = request.args.get('tenant_id')
except Exception as e:
tenant_id = 0

# If not on the company management page, determine the company status
if not path.startswith("/tenant/") and path != "/requirement/clear_up":
success, msg = Tenant.check_tenant(tenant_id)
if not success:
return {'success': False, 'error': msg, 'code': 404}
# authority check
success, msg = TenantUser.check_role(session['user_id'], tenant_id, path)
if not success:
return {'success': False, 'error': msg, 'code': 403}

@app.after_request
def after_request(response):
Expand Down
Binary file modified db/database.db
Binary file not shown.
Loading