Skip to content

[NEW] Personal access tokens for users to create API tokens#11638

Merged
sampaiodiego merged 11 commits intodevelopfrom
feature/rest-personal-access-tokens
Aug 21, 2018
Merged

[NEW] Personal access tokens for users to create API tokens#11638
sampaiodiego merged 11 commits intodevelopfrom
feature/rest-personal-access-tokens

Conversation

@MarcosSpessatto
Copy link
Copy Markdown
Contributor

Closes #7289

Add possibility to user generate personal access tokens(without expiration) to use with REST API.
@MarcosSpessatto MarcosSpessatto added this to the 0.69.0 milestone Aug 1, 2018
@MarcosSpessatto MarcosSpessatto self-assigned this Aug 1, 2018
@engelgabriel engelgabriel temporarily deployed to rocket-chat-pr-11638 August 1, 2018 14:38 Inactive
fix tests in personal access tokens endpoints
@engelgabriel engelgabriel temporarily deployed to rocket-chat-pr-11638 August 1, 2018 21:31 Inactive
throw new Meteor.Error('not-authorized', 'Not Authorized', { method: 'personalAccessTokens:generateToken'});
}
if (!RocketChat.settings.get('API_Enable_Personal_Access_Tokens')) {
throw new Meteor.Error('not-authorized', 'Not Authorized', { method: 'personalAccessTokens:generateToken'});
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

the error description here could say Personal Access Tokens are currently disabled. what do do you think?

this.ready = new ReactiveVar(true);

this.autorun(() => {
const subscription = this.subscribe('personalAccessTokens');
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

the subcribe command should be done outside the autorun block.

meteor is smart on this case because it knows you're not subscribing to a different thing, but still having it outside the autorun is a better pattern

});

Template.personalAccessTokens.onCreated(function() {
this.tokens = new ReactiveVar();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

you don't need this reactive var. instead you should be using the collection on the helpers

</tr>
</thead>
<tbody>
{{#unless hasTokens}}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

you can replace this #unless block by a {{else}} block on {{#each}} command, like this:

{{#each tokens}}
   ... show tokens ...
{{else}}
   ... no tokens
{{/each}}

"API_Personal_Access_Tokens_To_REST_API": "Personal access tokens to REST API",
"API_Personal_Access_Tokens_Remove_Modal": "Are you sure you wish to remove this personal access token?",
"API_Personal_Access_Token_Generated": "Personal Access Token successfully generated",
"API_Personal_Access_Token_Generated_Text_Token_s_UserId_s": "Please save your token carefully as you will no longer be able to view it afterwards. <br/>Token: <strong>%s</strong><br/>Your user Id: <strong>%s</strong>",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

please use named variables instead of %s, in this case, something like (look at __token__ and __user_id__):
"API_Personal_Access_Token_Generated_Text_Token_s_UserId_s": "Please save your token carefully as you will no longer be able to view it afterwards. <br/>Token: <strong>__token__</strong><br/>Your user Id: <strong>__user_id__</strong>",

{{/if}}
{{/if}}
</form>
{{> personalAccessTokens }}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

instead of adding this at Security page, I think it should have its own sub-menu.
this would also allow not writing it as a package, but as a meteor module

Change personal access tokens from package to module, and create an individual section on sidebar
@engelgabriel engelgabriel temporarily deployed to rocket-chat-pr-11638 August 15, 2018 21:51 Inactive
add more tests cases, mainly when the personal access tokens setting is disabled.
@engelgabriel engelgabriel temporarily deployed to rocket-chat-pr-11638 August 15, 2018 22:11 Inactive
@sampaiodiego sampaiodiego temporarily deployed to rocket-chat-pr-11638 August 17, 2018 02:04 Inactive
@sampaiodiego sampaiodiego temporarily deployed to rocket-chat-pr-11638 August 17, 2018 02:18 Inactive
@sampaiodiego sampaiodiego temporarily deployed to rocket-chat-pr-11638 August 17, 2018 18:11 Inactive
@sampaiodiego sampaiodiego changed the title [NEW] Add possibility to user generate personal access tokens to use with REST API. [NEW] Personal access tokens for users to create API tokens Aug 17, 2018
@sampaiodiego sampaiodiego merged commit ed1d550 into develop Aug 21, 2018
@sampaiodiego sampaiodiego deleted the feature/rest-personal-access-tokens branch August 21, 2018 00:42
@sampaiodiego sampaiodiego mentioned this pull request Aug 28, 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.

4 participants