8000 Product management (2nd part), permission system by whisperity · Pull Request #857 · Ericsson/codechecker · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Product management (2nd part), permission system #857

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 4, 2017

Conversation

whisperity
Copy link
Contributor
@whisperity whisperity commented Aug 31, 2017

Follow-up for #773, please merge it first!
Partially implements #691.

Product management changes

  • Users can now add, delete and edit products on the Web GUI.
  • Sanitising user input for the product's endpoint was added. Valid product URL endpoints look like programming variables, mostly, matching the regex: [A-Za-z][A-Za-z0-9_]*. It's the safest way.

Permission system

The permission system has been introduced. Four permissions are defined as of now:

  • SUPERUSER
  • PRODUCT_ADMIN
  • PRODUCT_ACCESS: required to view reports, add comments, filter, etc.
  • PRODUCT_STORE: required to check in and delete runs

Users can now be assigned to groups in dictionary auth, so group authentication can be tested. LDAP groups will come in the follow-up #807.

@whisperity whisperity added enhancement 🌟 WIP 💣 Work In Progress documentation 📖 Changes to documentation. server 🖥️ GUI 🎨 WARN ⚠️: Backward compatibility breaker! MIND THE GAP! Merging this patch will mess up compatibility with the previous releases! labels Aug 31, 2017
@whisperity whisperity added this to the 6.0 pre3 milestone Aug 31, 2017
@whisperity whisperity changed the title Product management improvements and permission system Product management (2nd part), permission system Aug 31, 2017
this.set('rightsDiff', rightsDiff);

// Sort and unique the name list.
var nameSet = new Set(nameList.users.sort());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use util.arrayUnique once #847 is merged.

@whisperity whisperity force-pushed the product_management-part2 branch from 6992e97 to fc8f179 Compare September 1, 2017 13:13
@whisperity whisperity force-pushed the product_management-part2 branch from fc8f179 to 3da2c62 Compare September 1, 2017 14:21
@whisperity whisperity added API change 📄 Content of patch changes API! database 🗄️ Issues related to the database schema. and removed WIP 💣 Work In Progress labels Sep 1, 2017
@whisperity whisperity force-pushed the product_management-part2 branch 2 times, most recently from 1017ba0 to 6a00524 Compare September 1, 2017 14:40
@whisperity whisperity added the test ☑️ Adding or refactoring tests label Sep 1, 2017
@whisperity whisperity force-pushed the product_management-part2 branch from 6a00524 to b882512 Compare September 1, 2017 14:53
@whisperity whisperity force-pushed the product_management-part2 branch 2 times, most recently from 7aa083a to d4a2fc8 Compare September 3, 2017 14:03
AUTH_OBJECTS.Permission.PRODUCT_STORE, util.createPermissionParams({
productID : CURRENT_PRODUCT.id
}));
console.log("POSTCREATE", showDelete);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove it

//--- Back button to product list ---//

var productListButton = new Button({
class : 'mainMenuButton',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use dash-case class names: main-menu-button

* given other colour with the given ratio.
*
* @param blendColour a variable applicable to the constructor of
* dojo.Color. It can be a color name, a hex string, on an array of RGB.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: or an array of RGB

var adminLevel = layout.get('adminLevel');

if (adminLevel)
adminLevel = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adminLevel = adminLevel
  ? 0 : isAdminOfAnyProduct
  ? 1 : isSuperuser
  ? 2 : 0;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Be careful with this notation if you are talking to a PHP developer, as the tertiary conditional operator is working a lot differently in that context.)


layout.set('adminLevel', adminLevel);
listOfProducts.setAdmin(adminLevel);
this.set('label',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation

}
});

optionsToAdd.sort(function (a, b) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compare function has the following form:

function compare(a, b) {
  if (a is less than b by some ordering criterion) {
    return -1;
  }
  if (a is greater than b by the ordering criterion) {
    return 1;
  }
  // a must be equal to b
  return 0;
}

For more information see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort

if (mode === 'add') {
this.set('title', "Add new product");
this._metadataPane.set('settingsMode', 'add');
this._permissionPane.set('disabled', true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to hide the Permissions tab instead of disabling it. It's annoying that I cannot go to that tab when I create a new product.

content: "\e012";
}

.customIcon.product-delete {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the color and the cursor on hover of this item:

.customIcon.product-delete:hover {
  color: #ff0000;
  cursor: pointer;
}


var isAdminOfAnyProduct = PROD_SERVICE.isAdministratorOfAnyProduct();

var menuButton = new Button({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm allow to edit the product list, why don't we show the administration settings (edit, remove icons, create new product button, etc.) by default?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's bit of an extra security measure to prevent an accidental permission override or product deletion. A product deletion is a dangerous action as it irrecoverably destroys the access control list of a product. It does not destroy analysis results, but after adding the product back, the permission list will be reset to defaults.

Think of it as sudo on Linux or the UAC introduced with Windows Vista. Even though you are an admin, it's better to put this extra barrier before dangerous actions.

@@ -72,3 +84,110 @@ span.product-avatar {
.customIcon.product-error:before {
content: "\e015";
}

.customIcon.product-edit {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the color and the cursor on hover of this item:

.customIcon.product-edit:hover {
  color: #373c44;
  cursor: pointer;
}

* The following permission scopes exist.
*
* SYSTEM: These permissions are global to the running CodeChecker server.
* In this case, the 'extra_params' field is empty.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be a bit misleading if we refer to extra_params field here which is not used in the api.
Should this be extraParams?


// ----------------------------------------------------------------
// Refer to the documentation in api/shared.thrift on what data the
// 'extra_params' field for a particular permission requires.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra_params here too.


Some permissions are *default not granted*, which means that only users whom
are explicitly given the permission have it. This also means that if the
server is running with authentication disabled, noone has the permission
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no one typo

session.close()

@timeit
def getAuthorisedNames(self, permission, extra_params):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A short documentation at the api implementations would be nice too.

@@ -427,7 +473,7 @@ def __get_run_ids_to_query(self, session, cmp_data=None):

@timeit
def getRunData(self, run_name_filter):

self.__require_access()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Permissions are read from the config database for each api call?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. This is a security measure. It is not a good option security-wise to ever cache any sort of "permission" descriptor.


added = self._add_perm_impl(auth_name, is_group)

if added:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we print something if adding fails?


removed = self._rem_perm_impl(auth_name, is_group)

if removed:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we print something if the remove fails?


session = None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we set the session here to None? We will not use it until the line 440.

logging.debug('Comment cannot be removed by another user')
with self.assertRaises(RequestFailed):
self._cc_client_john.removeComment(comments[1].id)
logging.debug('Comment was be removed by another user')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was be removed?

@whisperity whisperity force-pushed the product_management-part2 branch from ba69fb2 to 5453762 Compare September 4, 2017 15:13
@whisperity whisperity requested a review from gyorb September 4, 2017 15:14
@whisperity whisperity force-pushed the product_management-part2 branch 2 times, most recently from 5c1b87a to 7bef448 Compare September 4, 2017 15:53
Copy link
Member
@dkrupp dkrupp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

with one todo for later:
TODO for later: Show active permissions for a logged in user (so he understands why he can or cannot access/change a product)

 - Add management of the "root" user automatically created at server
   start
 - Add permission management code, API bindings, handling
 - Add permission settings view to the Web GUI for global and product
   editing

[ci skip]
 - This commit also introduces the sanity check for product endpoints at
   the addition/editing of new products.

Documentation has been updated for the permission system.
@whisperity whisperity force-pushed the product_management-part2 branch from 7bef448 to 0816a36 Compare September 4, 2017 16:16
@dkrupp dkrupp merged commit 14a3ed2 into Ericsson:version6 Sep 4, 2017
@whisperity whisperity deleted the product_management-part2 branch September 4, 2017 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API change 📄 Content of patch changes API! database 🗄️ Issues related to the database schema. documentation 📖 Changes to documentation. enhancement 🌟 GUI 🎨 server 🖥️ test ☑️ Adding or refactoring tests WARN ⚠️: Backward compatibility breaker! MIND THE GAP! Merging this patch will mess up compatibility with the previous releases!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0