From dcc196198be4d1e2d8c5e2fb2763fbbe8fd97286 Mon Sep 17 00:00:00 2001 From: sbcgua Date: Wed, 7 Sep 2016 22:34:09 +0300 Subject: [PATCH] #326 write protection --- src/zabapgit_definitions.prog.abap | 5 +++-- src/zabapgit_gui.prog.abap | 9 +++++++++ src/zabapgit_html.prog.abap | 9 ++++++--- src/zabapgit_page.prog.abap | 17 +---------------- src/zabapgit_page_main.prog.abap | 21 +++++++++++++++++---- src/zabapgit_persistence.prog.abap | 3 ++- src/zabapgit_repo.prog.abap | 2 ++ src/zabapgit_repo_impl.prog.abap | 12 ++++++++++++ 8 files changed, 52 insertions(+), 26 deletions(-) diff --git a/src/zabapgit_definitions.prog.abap b/src/zabapgit_definitions.prog.abap index ab14d3f0b..4d858a2f4 100644 --- a/src/zabapgit_definitions.prog.abap +++ b/src/zabapgit_definitions.prog.abap @@ -114,8 +114,9 @@ CONSTANTS: BEGIN OF gc_event_state, END OF gc_event_state. CONSTANTS: BEGIN OF gc_html_opt, - emphas TYPE c VALUE 'E', - cancel TYPE c VALUE 'C', + emphas TYPE c VALUE 'E', + cancel TYPE c VALUE 'C', + crossout TYPE c VALUE 'X', END OF gc_html_opt. CONSTANTS: BEGIN OF gc_action_type, diff --git a/src/zabapgit_gui.prog.abap b/src/zabapgit_gui.prog.abap index cf23604e8..be17b6c59 100644 --- a/src/zabapgit_gui.prog.abap +++ b/src/zabapgit_gui.prog.abap @@ -993,6 +993,10 @@ CLASS lcl_gui_router IMPLEMENTATION. lo_repo ?= lcl_app=>repo_srv( )->get( iv_key ). + IF lo_repo->is_write_protected( ) = abap_true. + lcx_exception=>raise( 'Cannot reset. Local code is write-protected by repo config' ). + ENDIF. + CALL FUNCTION 'POPUP_TO_CONFIRM' EXPORTING titlebar = 'Warning' @@ -1056,6 +1060,11 @@ CLASS lcl_gui_router IMPLEMENTATION. DATA: lo_repo TYPE REF TO lcl_repo_online. lo_repo ?= lcl_app=>repo_srv( )->get( iv_key ). + + IF lo_repo->is_write_protected( ) = abap_true. + lcx_exception=>raise( 'Cannot pull. Local code is write-protected by repo config' ). + ENDIF. + lo_repo->refresh( ). lo_repo->deserialize( ). diff --git a/src/zabapgit_html.prog.abap b/src/zabapgit_html.prog.abap index 31b2bef31..a252cac6f 100644 --- a/src/zabapgit_html.prog.abap +++ b/src/zabapgit_html.prog.abap @@ -279,7 +279,7 @@ CLASS lcl_html_helper DEFINITION FINAL. METHODS add_anchor IMPORTING iv_txt TYPE string iv_act TYPE string - iv_opt TYPE char1 OPTIONAL + iv_opt TYPE clike OPTIONAL iv_typ TYPE char1 DEFAULT gc_action_type-sapevent iv_class TYPE string OPTIONAL. @@ -398,12 +398,15 @@ CLASS lcl_html_helper IMPLEMENTATION. lv_class = iv_class. - IF iv_opt = gc_html_opt-emphas. + IF iv_opt ca gc_html_opt-emphas. lv_class = lv_class && ' emphasis' ##NO_TEXT. ENDIF. - IF iv_opt = gc_html_opt-cancel. + IF iv_opt ca gc_html_opt-cancel. lv_class = lv_class && ' attention' ##NO_TEXT. ENDIF. + IF iv_opt ca gc_html_opt-crossout. + lv_class = lv_class && ' crossout grey' ##NO_TEXT. + ENDIF. IF lv_class IS NOT INITIAL. SHIFT lv_class LEFT DELETING LEADING space. lv_class = | class="{ lv_class }"|. diff --git a/src/zabapgit_page.prog.abap b/src/zabapgit_page.prog.abap index 968eb5b32..f2b70a1a8 100644 --- a/src/zabapgit_page.prog.abap +++ b/src/zabapgit_page.prog.abap @@ -268,6 +268,7 @@ CLASS lcl_gui_page_super IMPLEMENTATION. _add '.grey { color: lightgrey !important; }'. _add '.emphasis { font-weight: bold !important; }'. _add '.attention { color: red !important; }'. + _add '.crossout { text-decoration: line-through !important; }'. _add '.right { text-align:right; }'. _add '.paddings { padding: 0.5em 0.5em; }'. @@ -405,24 +406,8 @@ CLASS lcl_gui_page_super IMPLEMENTATION. _add ' background-color: #f8f0d8;'. _add '}'. - " Other and outdated (?) styles _add '/* MISC AND REFACTOR */'. - _add 'a.grey:link {color: grey; font-size: smaller;}'. - _add 'a.grey:visited {color: grey; font-size: smaller;}'. - _add 'a.plain:link {color: black; text-decoration: none;}'. - _add 'a.plain:visited {color: black; text-decoration: none;}'. - _add 'a.bkg:link {color: #E8E8E8;}'. - _add 'a.bkg:visited {color: #E8E8E8;}'. - _add 'h1 {display: inline;}'. - _add 'h2 {display: inline;}'. - _add 'h3 {'. - _add ' display: inline;'. - _add ' color: grey;'. - _add ' font-weight:normal;'. - _add ' font-size: smaller;'. - _add '}'. - _add '.hidden-submit {'. _add ' border: 0 none;'. _add ' height: 0;'. diff --git a/src/zabapgit_page_main.prog.abap b/src/zabapgit_page_main.prog.abap index 1e61a07ad..10ddf5d8e 100644 --- a/src/zabapgit_page_main.prog.abap +++ b/src/zabapgit_page_main.prog.abap @@ -207,6 +207,8 @@ CLASS lcl_gui_page_main IMPLEMENTATION. DATA: lo_toolbar TYPE REF TO lcl_html_toolbar, lv_key TYPE lcl_persistence_db=>ty_value, + lv_wp_opt LIKE gc_html_opt-crossout, + lv_pull_opt LIKE gc_html_opt-crossout, lo_sub TYPE REF TO lcl_html_toolbar, lo_branch TYPE REF TO lcl_html_toolbar, lo_repo_online TYPE REF TO lcl_repo_online. @@ -217,6 +219,16 @@ CLASS lcl_gui_page_main IMPLEMENTATION. lv_key = io_repo->get_key( ). + IF io_repo->is_offline( ) = abap_false. + lo_repo_online ?= io_repo. + IF lo_repo_online->is_write_protected( ) = abap_true. + lv_wp_opt = gc_html_opt-crossout. + lv_pull_opt = gc_html_opt-crossout. + ELSE. + lv_pull_opt = gc_html_opt-emphas. + ENDIF. + ENDIF. + IF io_repo->is_offline( ) = abap_true. lo_toolbar->add( iv_txt = 'Import ZIP' iv_act = |zipimport?{ lv_key }| @@ -225,12 +237,11 @@ CLASS lcl_gui_page_main IMPLEMENTATION. iv_act = |zipexport?{ lv_key }| iv_opt = gc_html_opt-emphas ). ELSE. - lo_repo_online ?= io_repo. TRY. IF lo_repo_online->get_sha1_remote( ) <> lo_repo_online->get_sha1_local( ). lo_toolbar->add( iv_txt = 'Pull' iv_act = |pull?{ lv_key }| - iv_opt = gc_html_opt-emphas ). + iv_opt = lv_pull_opt ). ELSEIF lcl_stage_logic=>count( lo_repo_online ) > 0. lo_toolbar->add( iv_txt = 'Stage' iv_act = |stage?{ lv_key }| @@ -248,7 +259,8 @@ CLASS lcl_gui_page_main IMPLEMENTATION. lo_branch->add( iv_txt = 'Overview' iv_act = |branch_overview?{ lv_key }| ). lo_branch->add( iv_txt = 'Switch' - iv_act = |{ c_actions-switch_branch }?{ lv_key }| ). + iv_act = |{ c_actions-switch_branch }?{ lv_key }| + iv_opt = lv_wp_opt ). lo_branch->add( iv_txt = 'Create' iv_act = |create_branch?{ lv_key }| ). lo_branch->add( iv_txt = 'Delete' @@ -257,7 +269,8 @@ CLASS lcl_gui_page_main IMPLEMENTATION. io_sub = lo_branch ) ##NO_TEXT. lo_sub->add( iv_txt = 'Reset local' - iv_act = |reset?{ lv_key }| ). + iv_act = |reset?{ lv_key }| + iv_opt = lv_wp_opt ). lo_sub->add( iv_txt = 'Background mode' iv_act = |background?{ lv_key }| ). ELSE. diff --git a/src/zabapgit_persistence.prog.abap b/src/zabapgit_persistence.prog.abap index ca7655b4b..0a9205ca0 100644 --- a/src/zabapgit_persistence.prog.abap +++ b/src/zabapgit_persistence.prog.abap @@ -105,7 +105,8 @@ CLASS lcl_persistence_repo DEFINITION FINAL. offline TYPE sap_bool, local_checksums TYPE ty_local_checksum_tt, master_language TYPE spras, - head_branch TYPE string, + head_branch TYPE string, " HEAD symref of the repo, master branch + write_protect TYPE sap_bool, " Deny destructive ops: pull, switch branch ... END OF ty_repo_xml. TYPES: BEGIN OF ty_repo, diff --git a/src/zabapgit_repo.prog.abap b/src/zabapgit_repo.prog.abap index 628b65061..10c12d149 100644 --- a/src/zabapgit_repo.prog.abap +++ b/src/zabapgit_repo.prog.abap @@ -83,6 +83,8 @@ CLASS lcl_repo_online DEFINITION INHERITING FROM lcl_repo FINAL. RETURNING VALUE(rv_name) TYPE lcl_persistence_repo=>ty_repo-branch_name, get_head_branch_name RETURNING VALUE(rv_name) TYPE lcl_persistence_repo=>ty_repo-head_branch, + is_write_protected + RETURNING VALUE(rv_yes) TYPE sap_bool, get_branches RETURNING VALUE(ro_branches) TYPE REF TO lcl_git_branch_list, set_url diff --git a/src/zabapgit_repo_impl.prog.abap b/src/zabapgit_repo_impl.prog.abap index 9c25622d5..7878d131d 100644 --- a/src/zabapgit_repo_impl.prog.abap +++ b/src/zabapgit_repo_impl.prog.abap @@ -49,6 +49,10 @@ CLASS lcl_repo_online IMPLEMENTATION. METHOD deserialize. + IF ms_data-write_protect = abap_true. + lcx_exception=>raise( 'Cannot deserialize. Local code is write-protected by repo config' ). + ENDIF. + initialize( ). super->deserialize( ). @@ -122,6 +126,10 @@ CLASS lcl_repo_online IMPLEMENTATION. rv_name = ms_data-head_branch. ENDMETHOD. "get_head_branch_name + METHOD is_write_protected. + rv_yes = ms_data-write_protect. + ENDMETHOD. "is_write_protected + METHOD get_branches. IF mo_branches IS NOT BOUND. mo_branches = lcl_git_transport=>branches( get_url( ) ). @@ -138,6 +146,10 @@ CLASS lcl_repo_online IMPLEMENTATION. METHOD set_branch_name. + IF ms_data-write_protect = abap_true. + lcx_exception=>raise( 'Cannot switch branch. Local code is write-protected by repo config' ). + ENDIF. + mv_initialized = abap_false. set( iv_branch_name = iv_branch_name ).