From 8f5bb0e2d9b8c146cb42f8f84e642eb59c5344b5 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 18 Apr 2022 10:52:48 +0800 Subject: [PATCH] fix: organization gitea_token read by associations --- app/models/organization.rb | 4 ++++ app/services/organizations/create_service.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/organization.rb b/app/models/organization.rb index 40c676e05..56351a415 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -83,6 +83,10 @@ class Organization < Owner after_save :reset_cache_data + def gitea_token + team_users.joins(:team).where(teams: {authorize: "owner"}).take&.user&.gitea_token + end + def reset_cache_data Cache::V2::OwnerCommonService.new(self.id).reset end diff --git a/app/services/organizations/create_service.rb b/app/services/organizations/create_service.rb index a430ed6f4..263779191 100644 --- a/app/services/organizations/create_service.rb +++ b/app/services/organizations/create_service.rb @@ -47,7 +47,7 @@ class Organizations::CreateService < ApplicationService end def create_org_and_extension - @organization = Organization.build(params[:name], params[:nickname], user.gitea_token) + @organization = Organization.build(params[:name], params[:nickname]) org_extension = OrganizationExtension.build(organization.id, description, website, location, repo_admin_change_team_access, visibility, max_repo_creation)