Skip to content

Commit 8a3bf48

Browse files
committed
Merge branch 'master' into prd_plan_share_dev
2 parents e4c8b28 + 347b223 commit 8a3bf48

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+794
-43
lines changed

lib/travis/api/app/endpoint.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ def authorizer
117117
end
118118

119119
def auth_for_repo(id, type)
120+
current_user&.touch
120121
permission = authorizer.for_repo(id, type)
121122
halt 403, { error: { message: "We're sorry, but you're not authorized to perform this request" } } unless permission
122123
rescue Travis::API::V3::AuthorizerError

lib/travis/api/app/middleware/opencensus.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ def self.handle_notification_event event
8383
span_context = ::OpenCensus::Trace.span_context
8484
if span_context
8585
span = span_context.start_span event.name, skip_frames: 2
86-
span.start_time = event.time
87-
span.end_time = event.end
86+
span.start_time = event.time.is_a?(Time) ? event.time : Time.at(event.time)
87+
span.end_time = event.end.is_a?(Time) ? event.end : Time.at(event.end)
8888
event.payload.each do |k, v|
8989
span.put_attribute "#{k}", v.to_s
9090
end

lib/travis/api/serialize/v2/http.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@
2121
require 'travis/api/serialize/v2/http/user'
2222
require 'travis/api/serialize/v2/http/validation_error'
2323
require 'travis/api/serialize/v2/http/ssh_key'
24+
require 'travis/api/serialize/v2/http/account_env_var'
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module Travis
2+
module Api
3+
module Serialize
4+
module V2
5+
module Http
6+
class AccountEnvVar < Travis::Api::Serialize::ObjectSerializer
7+
attributes :id, :owner_id, :owner_type, :name, :value, :public, :created_at, :updated_at
8+
9+
def serializable_hash(adapter_options)
10+
hash = super(adapter_options)
11+
hash.delete :value unless object.public?
12+
hash
13+
end
14+
end
15+
end
16+
end
17+
end
18+
end
19+
end
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
require 'travis/api/v3/access_control/generic'
2+
3+
module Travis::API::V3
4+
class AccessControl::OrgToken < AccessControl::Generic
5+
auth_type('org.token')
6+
7+
attr_accessor :org, :token
8+
9+
def self.for_request(type, token, env)
10+
new(token)
11+
end
12+
13+
def initialize(token)
14+
if token.is_a? Array
15+
self.org = token.first
16+
self.token = token.last
17+
elsif token.include?(':')
18+
self.org = token.split(':')&.first
19+
self.token = token.split(':')&.last
20+
else
21+
self.org = Models::OrganizationToken.find_by(token: self.token)&.organization_id
22+
self.token = token
23+
end
24+
end
25+
26+
def visible?(object, type = nil)
27+
return Models::OrganizationToken.where(organization: org).joins(:organization_token_permissions).where(organization_token_permissions: {permission: object})&.first&.token&.split(':')&.last == token
28+
end
29+
30+
def logged_in?
31+
false
32+
end
33+
34+
def full_access?
35+
false
36+
end
37+
end
38+
end

lib/travis/api/v3/access_control/user.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class AccessControl::User < AccessControl::Generic
77
def initialize(user)
88
user = Models::User.find(user.id) if user.is_a? ::User
99
@user = user
10+
user.touch
1011
@access_permissions = user.permissions.where(user_id: user.id)
1112
super()
1213
end
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
module Travis::API::V3
2+
class Models::AccountEnvVar < Model
3+
belongs_to :owner, polymorphic: true
4+
5+
serialize :value, Travis::Model::EncryptedColumn.new
6+
define_callbacks :after_change
7+
set_callback :after_change, :after, :save_audit
8+
9+
def save_account_env_var!(account_env_var)
10+
account_env_var.save if account_env_var.valid?
11+
@changes = {
12+
created:
13+
"name: #{account_env_var.name}, public: #{account_env_var.public}"
14+
}
15+
run_callbacks :after_change
16+
account_env_var
17+
end
18+
19+
def delete(account_env_var)
20+
@changes = {
21+
deleted:
22+
"name: #{account_env_var.name}, public: #{account_env_var.public}"
23+
}
24+
account_env_var.destroy
25+
run_callbacks :after_change
26+
end
27+
28+
def changes
29+
@changes
30+
end
31+
32+
private
33+
34+
def save_audit
35+
Travis::API::V3::Models::Audit.create!(
36+
owner: self.owner,
37+
change_source: 'travis-api',
38+
source: self,
39+
source_changes: {
40+
account_env_var: self.changes
41+
}
42+
)
43+
@changes = {}
44+
end
45+
end
46+
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module Travis::API::V3
2+
class Models::BulkChangeResult
3+
attr_accessor :changed, :skipped
4+
5+
def initialize(attrs)
6+
@changed = attrs[:changed]
7+
@skipped = attrs[:skipped]
8+
end
9+
end
10+
end

lib/travis/api/v3/models/cron.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def enqueue
6666
)
6767

6868
update_attribute(:last_run, DateTime.now.utc)
69+
update_activity
6970
schedule_next_build
7071
end
7172

@@ -82,6 +83,15 @@ def deactivate
8283
update!(active: false)
8384
end
8485

86+
def update_activity
87+
owner = branch.repository.owner
88+
owner&.touch if owner.is_a? Models::User
89+
build = Build.find_by_id(branch.last_build_id)
90+
if build && build.sender_type == 'User' && build.sender_id > 0
91+
Models::User.find(build.sender_id)&.touch
92+
end
93+
end
94+
8595
def deactivate_and_log_reason(reason)
8696
Travis.logger.info "Removing cron #{self.id} because the associated #{reason}"
8797
deactivate

lib/travis/api/v3/models/organization.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ class Models::Organization < Model
55
has_many :memberships
66
has_many :users, through: :memberships
77
has_one :beta_migration_request
8+
has_many :account_env_vars, as: :owner
89

910
has_preferences Models::OrganizationPreferences
1011

@@ -43,8 +44,11 @@ def ensure_preferences
4344
end
4445

4546
def custom_keys
46-
return @custom_keys if defined? @custom_keys
47-
@custom_keys = Models::CustomKey.where(owner_type: 'Organization', owner_id: id)
47+
@custom_keys ||= Models::CustomKey.where(owner_type: 'Organization', owner_id: id)
48+
end
49+
50+
def account_env_vars
51+
@account_env_vars ||= Models::AccountEnvVar.where(owner_type: 'Organization', owner_id: id)
4852
end
4953

5054
alias members users

0 commit comments

Comments
 (0)