Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feat/improve-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
julsemaan committed May 11, 2024
2 parents 9532797 + 4fc47df commit c112d42
Show file tree
Hide file tree
Showing 14 changed files with 66 additions and 103 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/docker-admin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
branches: ['**']

jobs:
docker:
docker-admin:
runs-on: ubuntu-latest
outputs:
img_tag: ${{ steps.preserve_img_tag.outputs.img_tag }}
Expand Down Expand Up @@ -47,7 +47,7 @@ jobs:
concurrency:
group: prs-to-afn-k8s
cancel-in-progress: false
needs: docker
needs: docker-admin
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
steps:
Expand All @@ -61,7 +61,7 @@ jobs:

- name: PR tag change to afn-k8s
env:
IMG_TAG: ${{needs.docker.outputs.img_tag}}
IMG_TAG: ${{needs.docker-admin.outputs.img_tag}}
GH_TOKEN: ${{ secrets.GHA_REPO_TOKEN }}
CHANGE_TYPE: admin
run: |
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/docker-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
branches: ['**']

jobs:
docker:
docker-api:
runs-on: ubuntu-latest
outputs:
img_tag: ${{ steps.preserve_img_tag.outputs.img_tag }}
Expand Down Expand Up @@ -39,7 +39,7 @@ jobs:
extra_args: --push-retry 5

deploy:
needs: docker
needs: docker-api
if: github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/production'
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -74,7 +74,7 @@ jobs:
${{ secrets.AFN_MANAGER_DEPLOY_API_SCRIPT }} ghcr.io/julsemaan/anyfile-notepad/api:${{ steps.deploy-env.outputs.TARGET_IMAGE }} ${{ steps.deploy-env.outputs.TARGET_SERVERS }}
pr_afn_k8s:
needs: docker
needs: docker-api
concurrency:
group: prs-to-afn-k8s
cancel-in-progress: false
Expand All @@ -91,7 +91,7 @@ jobs:

- name: PR tag change to afn-k8s
env:
IMG_TAG: ${{needs.docker.outputs.img_tag}}
IMG_TAG: ${{needs.docker-api.outputs.img_tag}}
GH_TOKEN: ${{ secrets.GHA_REPO_TOKEN }}
run: |
BRANCH_ID=`date "+%Y%m%d"`
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker-client-base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
branches: ['**']

jobs:
docker:
docker-client-base:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
15 changes: 9 additions & 6 deletions .github/workflows/docker-client.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Docker Image client

on:
pull_request:
branches: ["main"]
push:
branches: ['**']
paths:
Expand All @@ -11,7 +13,7 @@ on:
branches: ['**']

jobs:
docker:
docker-client:
runs-on: ubuntu-latest
outputs:
img_tag: ${{ steps.preserve_img_tag.outputs.img_tag }}
Expand Down Expand Up @@ -63,11 +65,11 @@ jobs:
--build-arg=SRC_IMAGE=ghcr.io/julsemaan/anyfile-notepad/client-full:${{ env.IMG_TAG }}
pr_afn_k8s:
needs: docker
needs: docker-client
concurrency:
group: prs-to-afn-k8s
cancel-in-progress: false
if: github.ref == 'refs/heads/master'
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/beta'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -81,7 +83,7 @@ jobs:
- name: PR tag change to afn-k8s
if: github.ref != 'refs/heads/beta'
env:
IMG_TAG: ${{needs.docker.outputs.img_tag}}
IMG_TAG: ${{needs.docker-client.outputs.img_tag}}
GH_TOKEN: ${{ secrets.GHA_REPO_TOKEN }}
CHANGE_TYPE: appProdImage
run: |
Expand All @@ -105,15 +107,16 @@ jobs:
- name: PR tag change to afn-k8s
if: github.ref == 'refs/heads/beta'
env:
IMG_TAG: ${{needs.docker.outputs.img_tag}}
IMG_TAG: ${{needs.docker-client.outputs.img_tag}}
GH_TOKEN: ${{ secrets.GHA_REPO_TOKEN }}
CHANGE_TYPE: appDevImage
run: |
BRANCH_ID=`date "+%Y%m%d"`
BRANCH_NAME=tmp/$BRANCH_ID
# The branch already exists from the previous step
git checkout $BRANCH_NAME
git checkout $BRANCH_NAME || true
git checkout -b $BRANCH_NAME
yq -i '.backend.'$CHANGE_TYPE'.tag = "'$IMG_TAG'"' charts/afn/values.yaml
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/docker-pages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
branches: ['**']

jobs:
docker:
docker-pages:
runs-on: ubuntu-latest
outputs:
img_tag: ${{ steps.preserve_img_tag.outputs.img_tag }}
Expand Down Expand Up @@ -39,7 +39,7 @@ jobs:
--push-retry 5
pr_afn_k8s:
needs: docker
needs: docker-pages
concurrency:
group: prs-to-afn-k8s
cancel-in-progress: false
Expand All @@ -56,7 +56,7 @@ jobs:

- name: PR tag change to afn-k8s
env:
IMG_TAG: ${{needs.docker.outputs.img_tag}}
IMG_TAG: ${{needs.docker-pages.outputs.img_tag}}
GH_TOKEN: ${{ secrets.GHA_REPO_TOKEN }}
CHANGE_TYPE: pages
run: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/docker-webserver.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
branches: ['**']

jobs:
docker:
docker-webserver:
runs-on: ubuntu-latest
outputs:
img_tag: ${{ steps.preserve_img_tag.outputs.img_tag }}
Expand Down Expand Up @@ -39,7 +39,7 @@ jobs:
extra_args: --push-retry 5

pr_afn_k8s:
needs: docker
needs: docker-webserver
concurrency:
group: prs-to-afn-k8s
cancel-in-progress: false
Expand All @@ -56,7 +56,7 @@ jobs:

- name: PR tag change to afn-k8s
env:
IMG_TAG: ${{needs.docker.outputs.img_tag}}
IMG_TAG: ${{needs.docker-webserver.outputs.img_tag}}
GH_TOKEN: ${{ secrets.GHA_REPO_TOKEN }}
run: |
BRANCH_ID=`date "+%Y%m%d"`
Expand Down
1 change: 1 addition & 0 deletions .vimrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set wildignore+=*/bower_components
3 changes: 2 additions & 1 deletion TODO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ X Debounce SUBMIT on contact form
X Create sliding pane with adflare ad instead of infolinks
X Have branch + GHA flow for BETA JS app
X afn-app.sh needs exit on fail, pipe fail, etc
- Prevent Authorize prompt from always coming up
X Prevent Authorize prompt from always coming up
- Reimplement authorize prompt and switch user prompt to let users know what's up before the redirect
- Implement stats monitoring via API with Prometheus
- Implement dark mode in menus and for the header
- Use JWT instead of session ID for afn-pp session (no need to sync sessions after)
Expand Down
11 changes: 9 additions & 2 deletions client/_major_notice_modal.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
<script>
function newGoogleAuthBetaTry() {
application.controllers.editor.major_notice_pref.refreshAndSet(parseInt($('#major_notice_modal').attr('data-version')), application.controllers.editor, application.controllers.editor.show_reauth)
application.try_dev_mode();
}
</script>

<script class="template-partial" data-partial-name="major_notice_modal" type="text/x-handlebars">
<div class="modal fade" id="major_notice_modal" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="false" data-version="8">
<div class="modal-dialog">
Expand All @@ -6,8 +13,8 @@
<h4>New BETA version available for early adoption</h4>

<p>The new version includes a major improvement around Google Authentication to prevent the frequent "Authorize" prompts.</p>
<a href='javascript:void(0)' onclick='javascript:application.try_dev_mode()'>Click here to try out the BETA version!</a>

<a href='javascript:void(0)' onclick='javascript:newGoogleAuthBetaTry()'>Click here to try out the BETA version!</a>

<hr>

Expand Down
2 changes: 0 additions & 2 deletions client/app.tt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
{{> modal id="app_load_modal" title="Starting up application" message="Hang tight..." with_bar=true }}
{{> modal id="app_restart_modal" title="Restarting" message="The app is being restarted, please wait." with_bar=true }}
{{> modal id="file_load_modal" title="Your file is being loaded" message="Depending on the file size, this can be long." with_bar=true }}
{{> modal id="auth_failed_modal" title="The authentication failed with Google" message="You need to enable the popups in your browser, then login in your Google account and accept the app's authorization requests." button_id="restart_app" button_text="Restart app" }}
{{> modal id="error_modal" title="An unexpected error occurred with the provider server" message="The app flow will still continue but unexpected behavior may occur. When in doubt restart the app." dismiss=true }}
{{> modal id="auth_modal" title="You need to authorize this app to access your Google Drive" message="Make sure you grant access (check the boxes) for all the permissions the app needs in the next screen." button_id="start_g_oauth" button_text="Authorize!" }}
{{> modal id="user_auth_modal" title="Switch user" message="In order to open this file, you need to switch user." button_id="switch_user" button_text="Switch user" }}

{{> file_info }}
Expand Down
5 changes: 4 additions & 1 deletion client/assets/js/Controller/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -729,8 +729,11 @@ EditorController.prototype.open_share_modal = function() {
}
}

EditorController.prototype.restart_app = function() {
EditorController.prototype.restart_app = function(skipConfirm) {
var self = this;
if(skipConfirm) {
window.location.reload();
}
new Popup({ message : i18n("Are you sure ?"), callback : function(result) {if(result) window.location.reload()}, confirm : true});
}

Expand Down
93 changes: 18 additions & 75 deletions client/assets/js/Controller/OAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,23 @@ function GoogleOAuthController(options){
this.authed = false
this.current_user = undefined
this.client = undefined;
//this.init()
this.queue = [];
}

GoogleOAuthController.prototype.init = function(){
var self = this;
setTimeout(function(){self.check_authed()}, 15000)
this.add_to_queue(function(){
User.current_user(function(user){self.current_user = user});
});
this.add_to_queue(function() {
application.propose_upgrade();
self.keep_token_alive();
});


if(window.location.hash.match("^#google_access_token=")){
self.setToken(window.location.hash.replace("#google_access_token=", ""));
}

if(!sessionStorage.access_token) {
sessionStorage.access_token = getCookie("access_token");
Expand All @@ -34,86 +37,36 @@ GoogleOAuthController.prototype.init = function(){
gapi.client.load('drive', 'v2', function(){
gapi.load('picker', function() {
var request = gapi.client.oauth2.userinfo.get();
application.controllers.google_oauth.execute_request(request, function(response){self.post_auth(true)})
application.controllers.google_oauth.execute_request(request, function(response){self.ready()})
})
})
})
}

GoogleOAuthController.prototype.authorize_params = function(to_add) {
var self = this;
var base = {
client_id: self.client_id,
scope: self.scopes.join(" "),
ux_mode: 'popup',
};

if(User.get_session_user_id()){
base["user_id"] = User.get_session_user_id();
}

for (var attrname in to_add) { base[attrname] = to_add[attrname]; }

return base;
}


GoogleOAuthController.prototype.do_auth = function(user_id){
var self = this
var isBack = false;

$('#auth_modal').modal('show')
$('#start_g_oauth').click(function(){
self.auth_popup(user_id)
})
}

GoogleOAuthController.prototype.auth_popup = function(user_id){
var self = this
//Do it without the immediate
var params = {callback: function(auth_result){self.post_auth(auth_result)}};
sessionStorage.google_auth_return_to = window.location;
var url = "/api/oauth2/google/authorize";
if(user_id) {
params["hint"] = user_id;
url += "?login_hint="+user_id;
}
this.client = google.accounts.oauth2.initTokenClient(self.authorize_params(params))
this.client.requestAccessToken();
window.location = url;
}

GoogleOAuthController.prototype.auth_with_user = function(user_id, callback){
var self = this;
this.client = google.accounts.oauth2.initTokenClient(self.authorize_params({hint : user_id, callback: function(auth_result){
application.controllers.editor.reset_collaboration();
self.post_auth(auth_result);
callback();
}}));
this.client.requestAccessToken({login_hint:user_id});
self.do_auth(user_id);
}

GoogleOAuthController.prototype.switch_user = function() {
var self = this;
var previous_user = self.current_user;
self.auth_with_user(undefined, function(){
$('#app_restart_modal').modal('show');
window.location.hash = '#new' ;
window.location.reload()
})
self.do_auth();
}

GoogleOAuthController.prototype.post_auth = function(auth_result){
var self = this;
if (auth_result && !auth_result.error) {
if(auth_result['access_token']) {
setCookie('access_token', auth_result['access_token'], 1)
sessionStorage.access_token = auth_result['access_token'];
gapi.client.setToken({"access_token":auth_result['access_token']});
}
self.ready()
$('#auth_modal').modal('hide')
//cool it worked
}
else{
this.auth_failed();
}
GoogleOAuthController.prototype.setToken = function(token) {
setCookie('access_token', token, 1);
sessionStorage.access_token = token;
gapi.client.setToken({"access_token":token});
}

GoogleOAuthController.prototype.ready = function(){
Expand All @@ -131,18 +84,8 @@ GoogleOAuthController.prototype.add_to_queue = function(to_do){
}

GoogleOAuthController.prototype.show_reauth = function(){
$('#reauthenticate_modal').modal('show')
}

GoogleOAuthController.prototype.auth_failed = function(){
//$('#auth_failed_modal').modal('show')

}

GoogleOAuthController.prototype.check_authed = function(){
if(!this.authed){
this.auth_failed()
}
StatIncrement.record("GoogleOAuthController.prototype.show_reauth");
new Popup({ message : i18n('Failed to communicate with Google servers. Please restart the app.'), callback : function(result) {if(result) application.controllers.editor.restart_app(true)}, confirm_btn : i18n('Restart now')});
}

GoogleOAuthController.prototype.execute_request = function(request, callback, options){
Expand Down
Loading

0 comments on commit c112d42

Please sign in to comment.