Skip to content

What can user do #82

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 1 commit into from
Jul 11, 2016
Merged

What can user do #82

merged 1 commit into from
Jul 11, 2016

Conversation

jhadvig
Copy link
Member

@jhadvig jhadvig commented Jun 20, 2016

Created a new AuthorizationService to determine actions that user can/can't do.
The new service consists from two main methods:

  • reviewUserRules
    • which serves for reviewing multiple resource/verb pairs (namespaced and also non-namespaced)
    • resource/verb pair combinations are listed in the $scope.canI variable which should be set in each controller which will call this method.
    • obtained rules will be cached, until refreshing the page,changing projects, when 3 minute interval passes
  • canI
    • lightweight version of the first method (response only takes info if user is allowed to perform action on the ressource)
    • servers for reviewing single resource/verb pair (namespaced and also non-namespaced)
    • does not need $scope.canI variable, will create one if not present in controller and adds the result of the resource/verb review to it.

@jwforres PTAL

Implements https://trello.com/c/UQEUgVrY

if (pageRules) {
_.each(this.rules, function(rule) {
_.each(pageRules, function(verbs, resource) {
if (_.indexOf(rule.resources, resource) !== -1) {
Copy link
Member

Choose a reason for hiding this comment

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

Does this work (here and below)?

_.includes(rule.resources, resource)

@jhadvig
Copy link
Member Author

jhadvig commented Jun 20, 2016

will add bindata after review :)

@jwforres
Copy link
Member

I suspect @liggitt will be interested in this one

@jwforres
Copy link
Member

So first, keep your existing changes in a side branch since you have them working ...
But I'd like you to try something else since I would prefer to see no changes to the controllers. Here is what I am thinking:

  1. Add a filter that passes through to AuthorizationService.canI (similar to what we do with the navigate filters), AuthorizationService.canI should just return false if a rules review has not yet been performed. Views should call the canI filter for the individual actions.
  2. To determine whether to show the Actions dropdown menu, you'll want to add a filter which is canIDoAny that accepts an array of actions it wants to check and will return true as soon as it determines the user can perform any of the actions.
  3. Instead of having all the controllers for namespace scoped pages requesting to have a rules review performed, we should request a rules review as part of ProjectsService.getProject

I've at least run this by @spadgett and @benjaminapetersen and we agree in theory

// added into the $scope.canI variable.
// In case a resource shall to be added into the $scope.canI variable under a different unique name(eg. not as a
// resource kind) but a different unique name(eg. namespace), use the 'identifier' parameter.
AuthorizationService.prototype.canI = function(ns, verb, kind, $scope, identifier) {
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be more specific regarding api group, kind, and resource?

@openshift-bot openshift-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 20, 2016
this.projectNameRules = null;
}

AuthorizationService.prototype.reviewUserRules = function($scope) {
Copy link
Member

Choose a reason for hiding this comment

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

I know we do this in other places, but we shouldn't pass scope to services. Services shouldn't know anything about a controller's scope.

@spadgett
Copy link
Member

@jhadvig jhadvig force-pushed the can_i branch 2 times, most recently from c377e4f to 701a714 Compare June 23, 2016 15:55
@jhadvig
Copy link
Member Author

jhadvig commented Jun 23, 2016

@jwforres I've updated the PR(not final) to get additional feedback.
Things I want to ask:

  1. I've add the AuthorizationService.getProjectRules call to the projects.js service, but not sure if that s the right place, since at the settings page im experiancing that the $digest is not triggered when the $http get call response with the selfsubjectrulesreviews.
  2. Whats you opinion on showing the 'missing health check' notification, specifically the links to 'Add Health Check'. Also for metrics, as QA asked in the card https://trello.com/c/UQEUgVrY/661-3-only-show-users-actions-they-have-authority-to-perform

@openshift-bot openshift-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 23, 2016
AuthorizationService.prototype.canI = function(resource, verb) {
var rules = this.getRules();
if (rules) {
if (resource) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You can probably just return _.contains(rules[resource], verb) here since underscore will return true or false for you.

@openshift-bot openshift-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 28, 2016
<!-- Primary Actions -->
<button class="btn btn-default hidden-xs"
ng-click="cancelBuild()"
ng-if="!build.metadata.deletionTimestamp && (build | isIncompleteBuild)">Cancel Build</button>
ng-if="!build.metadata.deletionTimestamp && (build | isIncompleteBuild) && ('builds/clone' | canI : 'create')">Cancel Build</button>
Copy link
Member

Choose a reason for hiding this comment

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

create on builds/clone isnt the right check for cancel build, copy/paste error i'm guessing, same thing on line 42 below. Should just be checking update on builds i think.

@jwforres
Copy link
Member

jwforres commented Jul 6, 2016

Can you go ahead and add this to otherResources.js so that it will only put things in the dropdown that can actually be listed by the user:

   // for context, goes underneath the .then
    ProjectsService
      .get($routeParams.project)
      .then(_.spread(function(project, context
...
...
       // add this
        $scope.kinds = _.filter($scope.kinds, function(kind){
          var resource = APIService.kindToResource(kind.kind);
          return AuthorizationService.canI("list", kind.group ? kind.group + "/" + resource : resource, $scope.projectName);
        });

You'll also need to include AuthorizationService in the list of deps at the top of the service. You'll know its working if you can't see PetSets.

Then in constants.js please remove

      "LocalResourceAccessReview",
      "LocalSubjectAccessReview",
      "ResourceAccessReview",
      "SubjectAccessReview",
      "ReplicationControllerDummy",

from the blacklist, they'll now be cleanly removed from the list because the List verb isn't allowed on them. You need to leave DeploymentConfigRollback for now.

// - subresource taht contains '/', eg: 'builds/source', 'builds/logs', ...
// - resource ending with 'review' string: 'localsubjectaccessreviews', 'selfsubjectrulesreviews', 'subjectaccessreviews'
var checkResource = function(resource) {
if (resource === "projectrequests" || _.contains(resource, "/") || resource.endsWith("reviews")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

checking if it contains / is fine, but I'd rather not use endsWith... we should have an explicit list (or hash) of resources we don't care about for this

@jwforres
Copy link
Member

jwforres commented Jul 6, 2016

also remove ReplicaSet, PodTemplate, and ThirdPartyResource from the blacklist

@jwforres
Copy link
Member

jwforres commented Jul 6, 2016

@@ -122,7 +122,7 @@
<uib-tab active="selectedTab.terminal"
select="terminalTabWasSelected = true"
ng-init="containers = pod.status.containerStatuses"
ng-if="containersRunning(pod.status.containerStatuses) > 0">
ng-if="containersRunning(pod.status.containerStatuses) > 0 && ('pods/attach' | canI : 'get')">
Copy link
Member

Choose a reason for hiding this comment

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

this should be pods/exec

@jhadvig jhadvig force-pushed the can_i branch 3 times, most recently from cf3e23c to 155e7ef Compare July 11, 2016 14:38
@jhadvig
Copy link
Member Author

jhadvig commented Jul 11, 2016

@jwforres @benjaminapetersen @liggitt I've update the PR based on your comments, expect the one that suggests to return the rules together with the project and context, since we have canI, canIDoAny, canIScale, canIAddToProject filters that take care of any users actions they have authority to perform

@benjaminapetersen
Copy link
Contributor

Cool, I'm good with that.

}
});
if (canAddToProject) {
return false;
Copy link
Member

Choose a reason for hiding this comment

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

why is this not returning true?

Copy link
Member

Choose a reason for hiding this comment

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

@jwforres
Copy link
Member

[merge]

@jwforres
Copy link
Member

looks like it might have just been a flake [merge]

@jwforres
Copy link
Member

failed on the same test, @jhadvig can you run grunt test-integration locally and see if its passing

@jwforres
Copy link
Member

[merge] will let it go one more time, but i suspect this may be related to additional delay before the delete action is being shown

@openshift-bot
Copy link

openshift-bot commented Jul 11, 2016

Origin Web Console Merge Results: SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pull_requests_origin_web_console/104/)

@jwforres
Copy link
Member

[merge]

@openshift-bot
Copy link

Evaluated for origin web console merge up to 332bffe

@openshift-bot openshift-bot merged commit 563e73a into openshift:master Jul 11, 2016
f0x11 pushed a commit to f0x11/origin-web-console that referenced this pull request Jan 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants