33class  Travis ::Api ::App 
44  class  SettingsEndpoint  < Endpoint 
55    include  ActiveSupport ::Callbacks 
6+     extend  ActiveSupport ::Concern 
67
78    define_callbacks  :after_save 
8- 
99    set_callback  :after_save ,  :after ,  :save_audit 
10+ 
1011    set ( :prefix )  {  "/settings/"  << name [ /[^:]+$/ ] . underscore  } 
1112
1213    class  << self 
@@ -24,7 +25,7 @@ def subclass(name)
2425      end 
2526
2627      def  create_settings_class ( name ) 
27-         klass   =   Class . new ( self )  do 
28+         Class . new ( self )  do 
2829          define_method ( :name )  {  name  } 
2930          before  {  authenticate_by_mode!  } 
3031          define_routes! 
@@ -43,7 +44,6 @@ def define_routes!
4344    # Rails style methods for easy overriding 
4445    def  index 
4546      respond_with ( collection ,  type : name ,  version : :v2 ) 
46- 
4747    end 
4848
4949    def  show 
@@ -54,8 +54,13 @@ def update
5454      disallow_migrating! ( repo ) 
5555
5656      record . update ( JSON . parse ( request . body . read ) [ singular_name ] ) 
57+ 
5758      if  record . valid? 
58-         @changes  =  {  :"env_vars"  =>  {  created : "name: #{ record . name }  , is_public: #{ record . public }  , branch: #{ record . branch  || 'all' }   "  }  }  if  is_env_var? 
59+         @changes  =  { 
60+           env_vars : { 
61+             created : "name: #{ record . name }  , is_public: #{ record . public }  , branch: #{ record . branch  || 'all' }   " 
62+           } 
63+         }  if  is_env_var? 
5964
6065        repo_settings . save 
6166        run_callbacks  :after_save  if  is_env_var? 
@@ -71,8 +76,13 @@ def create
7176      disallow_migrating! ( repo ) 
7277
7378      record  =  collection . create ( JSON . parse ( request . body . read ) [ singular_name ] ) 
79+ 
7480      if  record . valid? 
75-         @changes  =  {  :"env_vars"  =>  {  created : "name: #{ record . name }  , is_public: #{ record . public }  , branch: #{ record . branch  || 'all' }  "  }  }  if  is_env_var? 
81+         @changes  =  { 
82+           env_vars : { 
83+             created : "name: #{ record . name }  , is_public: #{ record . public }  , branch: #{ record . branch  || 'all' }  " 
84+           } 
85+         }  if  is_env_var? 
7686
7787        repo_settings . save 
7888        run_callbacks  :after_save  if  is_env_var? 
@@ -88,7 +98,11 @@ def destroy
8898      disallow_migrating! ( repo ) 
8999
90100      record  =  collection . destroy ( params [ :id ] )  || record_not_found 
91-       @changes  =  {  :"env_vars"  =>  {  destroyed : "name: #{ record . name }  , is_public: #{ record . public }  , branch: #{ record . branch  || 'all' }   "  }  }  if  is_env_var? 
101+       @changes  =  { 
102+         env_vars : { 
103+           destroyed : "name: #{ record . name }  , is_public: #{ record . public }  , branch: #{ record . branch  || 'all' }   " 
104+         } 
105+       }  if  is_env_var? 
92106
93107      repo_settings . save 
94108      run_callbacks  :after_save  if  is_env_var? 
@@ -112,8 +126,8 @@ def repo
112126    # Sinatra's method 
113127    def  repo_settings 
114128      @settings  ||= begin 
115-         service ( :find_repo_settings ,  id : params [ 'repository_id' ] . to_i ) . run 
116-       end  || halt ( 404 ,  error : "Couldn't find repository" ) 
129+                        service ( :find_repo_settings ,  id : params [ 'repository_id' ] . to_i ) . run 
130+                      end  || halt ( 404 ,  error : "Couldn't find repository" ) 
117131    end 
118132
119133    def  record 
@@ -136,7 +150,14 @@ def is_env_var?
136150
137151    def  save_audit 
138152      change_source  =  access_token . app_id  == 2  ? 'admin-v2'  : 'travis-api' 
139-       Travis ::API ::V3 ::Models ::Audit . create! ( owner : current_user ,  change_source : change_source ,  source : @repo ,  source_changes : {  settings : self . changes  } ) 
153+       Travis ::API ::V3 ::Models ::Audit . create! ( 
154+         owner : current_user , 
155+         change_source : change_source , 
156+         source : @repo , 
157+         source_changes : { 
158+           settings : self . changes 
159+         } 
160+       ) 
140161      @changes  =  { } 
141162    end 
142163  end 
0 commit comments