Skip to content

Commit

Permalink
add rename endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-XT committed Jan 10, 2025
1 parent eaf5610 commit ffa5aeb
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
37 changes: 37 additions & 0 deletions agixt/MagicalAuth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2437,6 +2437,43 @@ def get_timezone(self):
return user_preferences["timezone"]
return getenv("TZ")

def rename_company(self, company_id, name):
# Check if company is in users companies
if str(company_id) not in self.get_user_companies():
raise HTTPException(
status_code=403,
detail="Unauthorized. Insufficient permissions.",
)
with get_session() as db:
company = db.query(Company).filter(Company.id == company_id).first()
if not company:
raise HTTPException(status_code=404, detail="Company not found")
user_role = self.get_user_role(company_id)
if user_role > 2:
raise HTTPException(
status_code=403,
detail="Unauthorized. Insufficient permissions.",
)
company.name = name
db.commit()
return CompanyResponse(
id=str(company.id),
name=company.name,
company_id=str(company.company_id) if company.company_id else None,
users=[
UserResponse(
id=str(uc.user.id),
email=uc.user.email,
first_name=uc.user.first_name,
last_name=uc.user.last_name,
role=uc.role.name,
role_id=uc.role_id,
)
for uc in company.users
],
children=[],
)


def get_user_timezone(user_id):
session = get_session()
Expand Down
17 changes: 17 additions & 0 deletions agixt/endpoints/Auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,3 +495,20 @@ async def toggle_command(
new_config={payload.command_name: payload.enable}, config_key="commands"
)
return ResponseMessage(message=update_config)


# Rename company
@app.put(
"/v1/companies/{company_id}",
response_model=CompanyResponse,
summary="Rename a company",
tags=["Companies"],
)
async def rename_company(
company_id: str,
name: str,
email: str = Depends(verify_api_key),
authorization: str = Header(None),
):
auth = MagicalAuth(token=authorization)
return auth.rename_company(company_id, name)

0 comments on commit ffa5aeb

Please sign in to comment.