Skip to content
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

Dev: Add BIT user attributes to MS User #1074

Merged
merged 1 commit into from
May 2, 2021

Conversation

mtreacy002
Copy link
Member

Description

Adding BIT user attributes to MS User as the first step for full BIT-MS integration

Fixes #1073

Type of Change:

  • Code

Code/Quality Assurance Only

  • New feature (non-breaking change which adds functionality pre-approved by mentors)

How Has This Been Tested?

The local_data.db has successfully added BIT User specific attributes after running migration script.

Screen Shot 2021-04-18 at 1 49 33 pm

Checklist:

  • My PR follows the style guidelines of this project
  • I have performed a self-review of my own code or materials
  • I have commented my code or provided relevant documentation, particularly in hard-to-understand areas

Code/Quality Assurance Only

  • My changes generate no new warnings
  • New and existing unit tests pass locally with my changes

@mtreacy002 mtreacy002 added BIT This labels issues that need to be completed to help BIT Category: Coding Changes to code base or refactored code that doesn't fix a bug. Type: Enhancement New feature or request. labels Apr 18, 2021


@unique
class Timezone(Enum):
Copy link
Member

Choose a reason for hiding this comment

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

Is this required? There should be something inbuilt to do the same thing. I know there is in java.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm open to refactoring this Timezone enum to a more efficient way if someone can pointed out an inbuilt package that is available out there. We can try to refactor the Timezone in the BIT repo first instead of here to see if it works coz BIT schema already the tests written for the endpoints that are using this Timezone enum.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

@epicadk epicadk Apr 18, 2021

Choose a reason for hiding this comment

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

Instead of this enum we could do this it's an inbuilt package. But implementing this means that the tz package would have to be the same for all the application.

Copy link
Member Author

@mtreacy002 mtreacy002 Apr 22, 2021

Choose a reason for hiding this comment

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

@epicadk , unfortunately, this zoneinfo module only available for Python >= 3.9.
Screen Shot 2021-04-22 at 10 38 41 am

MS backend is still using Python 3.6 for gh-action, so the gh action build/test will fail unless we change this.
Screen Shot 2021-04-22 at 10 41 35 am

Also, this enum is currently used in BIT frontend in timezones.js as a constant so that we can provide the dropdown options to user to prevent them inserting timezone that doesn't fall within the accepted value of backend timezone enum (which is according to the pytz list). Do you have any suggestions how we do this if we refactor backend to zoneinfo? What should we use as constant at the frontend?

Copy link
Member

@epicadk epicadk Apr 22, 2021

Choose a reason for hiding this comment

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

We'll run a matrix build. I'll create an issue. Mentorship system runs fine on python version 3.9.

Copy link
Member

@isabelcosta isabelcosta May 1, 2021

Choose a reason for hiding this comment

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

@mtreacy002 can you now use python 3.9 and use zoneinfo?

}

def __repr__(self):
"""Returns the user's name and username. """
return f"User name {self.name} . Username is {self.username} ."
"""Returns the user's name, username, whether or not they are an organization representative and their timezone. """
Copy link
Member

Choose a reason for hiding this comment

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

Requires approval from @isabelcosta

Copy link
Member Author

@mtreacy002 mtreacy002 Apr 18, 2021

Choose a reason for hiding this comment

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

Yep..., I actually think it won't be too much of a problem if we don't include the is_organization_rep or Timezone in here since they can be abstracted later once we grab the user data using GET /user api call 🤔. I will just remove them for now 😁.

@mtreacy002
Copy link
Member Author

mtreacy002 commented Apr 18, 2021

My approached in this PR was from an angle of a new contributor who has succesfully completed the local setup.
The followings are the steps done on this PR:

  1. updated local develop branch by pulling the latest commit from upstream.

  2. created a new pr branch

  3. run python run.py comand => this created the local_data.db. Notice that the alembic version folder din't exist in the db.

Screen Shot 2021-04-18 at 12 20 31 pm

  1. Registered a new user and confirm email (this is now what most contributors would have on their db where they have data but no alembic version folder as contributors have never run migration script before.

  2. run initial migration using command "flask db migrate -m "Initial migration" => this added alembic version folder into the local_data.db.

Screen Shot 2021-04-18 at 12 33 02 pm

  1. Added the render_as_batch condition in run.py so that running flask-db-upgrade won't return this error

Screen Shot 2021-04-18 at 2 10 59 pm

Screen Shot 2021-04-18 at 2 08 12 pm

  1. Made the schema changes in UserModel by adding BIT user specific attribute. Then run another migration command flask db migrate -m "<message>" where <message> is a clear message what the change was about. This was used as the alembic version title. This round running the script actually created the new alembic script version as it should.

Screen Shot 2021-04-18 at 3 06 17 pm

  1. Fixed migration script so running flask db upgrade won't return this error

Screen Shot 2021-04-18 at 3 14 16 pm

The culprit was shown below
Screen Shot 2021-04-18 at 12 51 42 pm

And here's the fix
Screen Shot 2021-04-18 at 1 12 10 pm

  1. Refreshed the local_data.db on the sqlite db viewer tool and saw the new attributes were added (screenshot given in pr descripction above)

@epicadk
Copy link
Member

epicadk commented Apr 18, 2021

A tip for @isabelcosta and other reviewers you can the changes @mtreacy002 has made here

@mtreacy002
Copy link
Member Author

mtreacy002 commented Apr 18, 2021

@epicadk, there were soooo many other commits there included in this PR 😱. Must be because the bit branch hasn't been synced to the develop branch from the admin/maintainers side. Is it possible for you to do this? I think once bit branch is updated, the irrelevant commits will disappear from the pr, right?

@epicadk
Copy link
Member

epicadk commented Apr 18, 2021

I think they will yes. Also can you please add BIT to github actions?

@mtreacy002
Copy link
Member Author

I think they will yes. Also can you please add BIT to github actions?

Done

@mtreacy002
Copy link
Member Author

@epicadk, should I also add bit to gh-action docs.yml, or wait till we have docs related issue to add bit to the docs workflow?

@codecov
Copy link

codecov bot commented Apr 18, 2021

Codecov Report

Merging #1074 (e2c16ae) into bit (ca4728a) will increase coverage by 1.48%.
The diff coverage is 99.84%.

❗ Current head e2c16ae differs from pull request most recent head 81f739c. Consider uploading reports for the commit 81f739c to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##              bit    #1074      +/-   ##
==========================================
+ Coverage   92.90%   94.39%   +1.48%     
==========================================
  Files          38       39       +1     
  Lines        2073     2623     +550     
==========================================
+ Hits         1926     2476     +550     
  Misses        147      147              
Impacted Files Coverage Δ
app/api/models/mentorship_relation.py 100.00% <ø> (ø)
app/api/models/task.py 100.00% <ø> (ø)
app/utils/bitschema_utils.py 99.83% <99.83%> (ø)
app/api/dao/mentorship_relation.py 96.11% <100.00%> (ø)
app/api/dao/task.py 98.48% <100.00%> (ø)
app/api/dao/task_comment.py 100.00% <100.00%> (ø)
app/api/dao/user.py 85.77% <100.00%> (-0.06%) ⬇️
app/api/resources/admin.py 88.13% <100.00%> (-0.58%) ⬇️
app/api/resources/task.py 100.00% <100.00%> (ø)
app/api/resources/user.py 89.75% <100.00%> (-0.66%) ⬇️
... and 22 more

@mtreacy002
Copy link
Member Author

mtreacy002 commented Apr 18, 2021

Codecov Report

❗ No coverage uploaded for pull request base (bit@479f1c7). Click here to learn what that means.
The diff coverage is 99.84%.

Impacted file tree graph

@@          Coverage Diff           @@
##             bit    #1074   +/-   ##
======================================
  Coverage       ?   94.39%           
======================================
  Files          ?       39           
  Lines          ?     2623           
  Branches       ?        0           
======================================
  Hits           ?     2476           
  Misses         ?      147           
  Partials       ?        0           

Impacted Files Coverage Δ
app/api/models/mentorship_relation.py 100.00% <ø> (ø)
app/api/models/task.py 100.00% <ø> (ø)
app/utils/bitschema_utils.py 99.83% <99.83%> (ø)
app/api/dao/mentorship_relation.py 96.11% <100.00%> (ø)
app/api/dao/task.py 98.48% <100.00%> (ø)
app/api/dao/task_comment.py 100.00% <100.00%> (ø)
app/api/dao/user.py 85.77% <100.00%> (ø)
app/api/resources/admin.py 88.13% <100.00%> (ø)
app/api/resources/task.py 100.00% <100.00%> (ø)
app/api/resources/user.py 89.75% <100.00%> (ø)
... and 6 more

@epicadk , can you suggest what went wrong here? 🤔
Is it just bcoz this is the first report so nothing to compare? That should be fine then, right?

@epicadk
Copy link
Member

epicadk commented Apr 18, 2021

@epicadk, should I also add bit to gh-action docs.yml, or wait till we have docs related issue to add bit to the docs workflow?

Yup I think you can wait for this.

@epicadk
Copy link
Member

epicadk commented Apr 18, 2021

@epicadk , can you suggest what went wrong here? 🤔
Is it just bcoz this is the first report so nothing to compare? That should be fine then, right?

Yup that's right. It's fine.

@mtreacy002
Copy link
Member Author

@isabelcosta , I have resolved the conflict, can you please review again 😉

@isabelcosta
Copy link
Member

auch @mtreacy002 can you squash all these commits into one? I see an issue here, and I bet it's because of the way that I did the sync 🙈

image

@epicadk
Copy link
Member

epicadk commented Apr 18, 2021

auch @mtreacy002 can you squash all these commits into one? I see an issue here, and I bet it's because of the way that I did the sync 🙈

image

Nope rebasing won't be possible. It would still show the error.

@mtreacy002
Copy link
Member Author

mtreacy002 commented Apr 19, 2021

@isabelcosta , do you still face the conflict on merging? Do you want me to try squash merge all the commits from my end?

@epicadk
Copy link
Member

epicadk commented Apr 20, 2021

@isabelcosta , do you still face the conflict on merging? Do you want me to try squash merge all the commits from my end?

You could try but I'm guessing it would still show merge conflicts after squashing. What you could do is. Rebase them into a single commit and then merge the upstream branch.

@mtreacy002
Copy link
Member Author

Done, @isabelcosta and @epicadk , I've squashed and force-pushed the commits. Can you please check again if this still causing conflicts at your end when merging?

@epicadk
Copy link
Member

epicadk commented Apr 22, 2021

Done, @isabelcosta and @epicadk , I've squashed and force-pushed the commits. Can you please check again if this still causing conflicts at your end when merging?

Yeps this might work.

@@ -14,7 +14,7 @@ def create_app(config_filename: str) -> Flask:

db.init_app(app)

migrate = Migrate(app, db)
migrate = Migrate(app, db, render_as_batch=True)
Copy link
Member

Choose a reason for hiding this comment

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

what does this do? 🤓



def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
Copy link
Member

Choose a reason for hiding this comment

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

These comments from alembic can be removed right?

Copy link
Member Author

Choose a reason for hiding this comment

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

@isabelcosta , done 😉

@epicadk
Copy link
Member

epicadk commented Apr 25, 2021

  1. Added the render_as_batch condition in run.py so that running flask-db-upgrade won't return this error

@isabelcosta

@mtreacy002
Copy link
Member Author

@vj-codes , I remember you asked last time whether we need to add Black to requirements.txt and my answered to that was that it's not needed. However, now that I encountered this issue with local Black version passing files but Black version in gh-action failing it, it seems fair to put Black to the `requirements.txt so that we can make sure all contributors running the same version locally that we'll match to the latest stable version on gh-action. What do you think of this? cc @epicadk

@epicadk
Copy link
Member

epicadk commented Apr 29, 2021

@vj-codes , I remember you asked last time whether we need to add Black to requirements.txt and my answered to that was that it's not needed. However, now that I encountered this issue with local Black version passing files but Black version in gh-action failing it, it seems fair to put Black to the `requirements.txt so that we can make sure all contributors running the same version locally that we'll match to the latest stable version on gh-action. What do you think of this? cc @epicadk

Yup seems like a nice idea. But maybe add it to dev-requirements.txt? Also sorry for the delay I have some other commitments so I can't really attend the ms open session. I'll try to attend the upcoming one so we can discuss and possibly merge this. I actually think we can merge this and handle the timezone case later.

@epicadk
Copy link
Member

epicadk commented May 1, 2021

@isabelcosta no other changes from my side, can this be merged?

@isabelcosta isabelcosta closed this May 1, 2021
@isabelcosta isabelcosta deleted the branch anitab-org:bit May 1, 2021 14:12
@isabelcosta isabelcosta reopened this May 1, 2021
@isabelcosta
Copy link
Member

@mtreacy002 can you try to solve the merge conflicts please? Me, @vj-codes and @epicadk did some merges and branch recreation, and now that we added the matrix python version thing to GH Actions, there are conflicts.

remove BIT attrributes from being returned in _repr_(self)

remove unnecessary brackets

Fix description

add bit branch to github action

fix black linting error

Remove alembic auto-generated comments
@mtreacy002 mtreacy002 force-pushed the add-bitschema-user branch from e2c16ae to 81f739c Compare May 2, 2021 00:43
@mtreacy002
Copy link
Member Author

I've solved the conflict @isabelcosta 😉

Copy link
Member

@isabelcosta isabelcosta left a comment

Choose a reason for hiding this comment

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

Will approve and merge once it has 2 approvals.

Points raised:

  • We discussed that, timezones will be refactored later, to come from zoneinfo module.
  • Instructions on how to run migrations should go to the README.

Copy link
Member

@epicadk epicadk left a comment

Choose a reason for hiding this comment

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

👍🏼

@isabelcosta isabelcosta merged commit f25a0b8 into anitab-org:bit May 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BIT This labels issues that need to be completed to help BIT Category: Coding Changes to code base or refactored code that doesn't fix a bug. Type: Enhancement New feature or request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants